Package net.jini.core.lookup

Examples of net.jini.core.lookup.ServiceRegistrar


    public static ServiceRegistrar findTestLookupService(int retryTimeoutSecs)
            throws IOException, ClassNotFoundException, InterruptedException {

        // find/wait for lookup _service
        final long startTime = System.currentTimeMillis();
        ServiceRegistrar serviceRegistrar = null;
        final LookupLocator lookup = new LookupLocator(JINI_URL_LOCALHOST);
        while (serviceRegistrar == null
                && (System.currentTimeMillis() - startTime < (retryTimeoutSecs * 1000))) {

            try {
View Full Code Here


        // restore original system properties
        System.setProperties(origSysProps);
    }

    private static void verifyNoLocalLookupService() throws IOException, ClassNotFoundException, InterruptedException {
        ServiceRegistrar serviceRegistrar = findTestLookupService(1);
        assertNull("Found local lookup service, but it should be dead. Is an orphaned java process still running?",
                serviceRegistrar);
    }
View Full Code Here

    }

    public static void main (String[] args) {
        RoomLight myServer;
        LookupLocator lookup;
        ServiceRegistrar registrar;
        ServiceItem serviceItem;

        try {
/*        Set the security manager to allow the RMI class loader
          to go to the codebase for classes that are not available
          locally.  */

        System.setSecurityManager (new RMISecurityManager ());

/*      Create the attributes (an array of entry objects) that describe this
        server and use it to register this server with the lookup service.
        JoinManager finds and registers with the lookup service */

        Entry[] attr = new Entry[2];
        attr[0] = new Name("Neon Light");
        attr[1] = new ServiceInfo("Name", "Manufactor", "vendor","version","model","serial");
        myServer = new RoomLightNeon ();
        serviceItem = new ServiceItem(null, myServer, attr);

        lookup = new LookupLocator ("jini://localhost");
        registrar  = lookup.getRegistrar();
        registrar.register(serviceItem, Lease.FOREVER);

        System.out.println("Serrrrrrrrrrvice Ready ...");

        } catch (Exception e)
          {
View Full Code Here

public class RoomLightTest {
     public static void main (String[] args) {
          Entry[] aeAttributes;
          LookupLocator lookup;
          ServiceRegistrar registrar;
          ServiceTemplate template;
          RoomLight myRoomLight;

          try {
  /*          Set the security manager to allow the RMI class loader to access
              the codebase for classes that are not available locally */

              System.setSecurityManager (new RMISecurityManager ());

  /*          Find the Jini lookup service (reggie) and print its location */

              lookup = new LookupLocator ("jini://localhost");

  /*          Get the lookup service's ServiceRegistrar and perform a search to find
              the service that has the name attribute name of "HelloWorldServer".
              The lookup service returns an Proxy object to the service */

              registrar  = lookup.getRegistrar();
              aeAttributes = new Entry[2];

              aeAttributes[0] = new Name("Neon Light");
              aeAttributes[1] = new ServiceInfo("Name", "Manufactor", "vendor","version","model","serial");
             
              template = new ServiceTemplate (null, null, aeAttributes);

              myRoomLight = (RoomLight) registrar.lookup (template);

              System.out.println (" ist das Licht an? ->" + myRoomLight.isOn() + "<-");
          } catch (Exception e) {
              System.out.println ("client: MyClient.main() exception: " + e);
          }
View Full Code Here

    new DataOutputStream(sock.getOutputStream());
      dstr.writeInt(protoVersion);
      dstr.flush();
      ObjectInputStream istr =
    new ObjectInputStream(sock.getInputStream());
      ServiceRegistrar registrar =
    (ServiceRegistrar)((MarshalledObject)istr.readObject()).get();
      for (int grpCount = istr.readInt(); --grpCount >= 0; ) {
    istr.readUTF(); // ensure proper format, then discard
      }
      return registrar;
View Full Code Here

            public LookupTask(ProxyReg reg, long seqN) {
                super(reg, seqN);
      }
            public void run() {
                logger.finest("ServiceDiscoveryManager - LookupTask started");
    ServiceRegistrar proxy = reg.proxy;
    ServiceMatches matches;
                /* For the given lookup, get all services matching the tmpl */
    try {
        matches = proxy.lookup(tmpl, Integer.MAX_VALUE);
    } catch (Exception e) {
                    boolean cacheTerminated;
                    synchronized(serviceIdMap) {
                        cacheTerminated = bCacheTerminated;
                    }//end sync
View Full Code Here

  }
  int len = proxys.length;
  if(len == 0 ) return null;
  int rand = Math.abs(random.nextInt()) % len;
  for(int i=0; i<len; i++) {
      ServiceRegistrar proxy = proxys[(i + rand) % len];
      ServiceItem sItem = null;
      try {
                int maxMatches = ( (filter != null) ? Integer.MAX_VALUE : 1 );
    ServiceMatches sm = proxy.lookup(tmpl, maxMatches);
    sItem = getMatchedServiceItem(sm, filter);
      } catch(Exception e) {
                logger.log(Level.INFO,
                           "Exception occurred during query, discarding proxy",
                           e);
View Full Code Here

  if(len > 0) {
            /* loop thru the set of lookups, randomly selecting each lookup */
      int rand = (Math.abs(random.nextInt())) % len;
      for(int i=0; i<len; i++) {
                int max = maxMatches;
    ServiceRegistrar proxy = proxys[(i + rand) % len];
    try {
                    /* If a filter is to be applied (filter != null), then
                     * the value of the maxMatches parameter will not
                     * suffice when querying the current lookup service.
                     * This is because although services returned from a
                     * query of the lookup service will match the template,
                     * some of those services may get filtered out. Thus,
                     * asking for exactly maxMatches may result in fewer
                     * matching services than actually are contained in
                     * the lookup. Thus, all matching services are
                     * requested by passing in "infinity" for the maximum
                     * number of matches (Integer.MAX_VALUE).
                     */
                    if(filter != null) max = Integer.MAX_VALUE;
                    /* Query the current lookup for matching service(s). */
        ServiceMatches sm = proxy.lookup(tmpl, max);
        int nItems = sm.items.length;
        if(nItems == 0) continue;//no matches, query next lookup
                    /* Loop thru the matching services, randomly selecting
                     * each service, applying the filter if appropriate,
                     * and making sure the service has not already been
View Full Code Here

         * unicast response here because, prior to modification and storage
         * in the managed set of registrars in this method, it is assumed that
         * that object is not accessed by any other thread.
         */
        try {
      final ServiceRegistrar srcReg = resp.getRegistrar();
            ServiceRegistrar prepReg
    = (ServiceRegistrar)AccessController.doPrivileged
        ( securityContext.wrap( new PrivilegedExceptionAction() {
                        public Object run() throws RemoteException {
                            Object proxy = registrarPreparer.prepareProxy
                                                            (srcReg);
View Full Code Here

     *                  member groups of the registrar corresponding to the
     *                  <code>response</code> parameter (just after a
     *                  possible change)
     */
    private void maybeSendEvent(UnicastResponse response, String[] newGroups) {
        ServiceRegistrar reg = response.getRegistrar();
        boolean getActual    = true;
        if(newGroups == null) { // newGroups null means get actual groups now
            newGroups = getActualGroups(reg);
            if(newGroups == null) return; // if null, then it was discarded
            getActual = false;
        }//endif

        if(groupSetsEqual(response.getGroups(),newGroups)) return;

        String[] actualGroups = newGroups;
        if( getActual && (newGroups.length > 0) ) {
            actualGroups = getActualGroups(reg);
            if(actualGroups == null) return; // null ==> was already discarded
        }//endif
 
  synchronized (registrars) {
      // Other events may have occured to registrars while we were
      // making our remote call.
      UnicastResponse resp =
    (UnicastResponse) registrars.get(reg.getServiceID());
      if (resp == null) {
    // The registrar was discarded in the meantime. Oh well.
    return;
      }
      notifyOnGroupChange(reg, resp.getGroups(), actualGroups);
View Full Code Here

TOP

Related Classes of net.jini.core.lookup.ServiceRegistrar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.