Package net.jini.lookup

Examples of net.jini.lookup.DiscoveryAdmin


    {
        if( (proxy == null) || (groups == null) ) return false;
        /* First, test that the lookup service implements both of the
         * appropriate administration interfaces
         */
        DiscoveryAdmin discoveryAdmin = null;
        if( !(proxy instanceof Administrable) ) return false;
        Object admin = ((Administrable)proxy).getAdmin();
//  try {
            admin = getConfig().prepare("test.reggieAdminPreparer", admin);
//  } catch (TestException e) {
//      throw new RemoteException("Preparation error", e);
//  }
        if( !(admin instanceof DiscoveryAdmin) ) return false;
        discoveryAdmin = (DiscoveryAdmin)admin;
        /* Set the member groups for the lookup service */
        discoveryAdmin.setMemberGroups(groups);
        return true;
    }//end setLookupMemberGroups
View Full Code Here


        synchronized(eventLock) {
            eventReceived = false;
            srvcReg = manager.startLookupService(); // already prepared
            lookupList.add( srvcReg );
        }
        DiscoveryAdmin admin = DiscoveryAdminUtil.getDiscoveryAdmin(srvcReg);
        memberGroups = admin.getMemberGroups();
        LocatorsUtil.displayLocator(QAConfig.getConstrainedLocator(srvcReg.getLocator()),
                                    "  lookup locator",Level.FINE);
        logger.log(Level.FINE,
       "  lookup MemberGroup(s) = "
       +GroupsUtil.toCommaSeparatedStr(memberGroups));
View Full Code Here

            eventReceived = false;
      srvcReg = manager.startLookupService(); // prepared
            lookupList.add( srvcReg );
        }//end synchronized
        // prepared by DiscoveryAdminUtil
        DiscoveryAdmin admin1 = DiscoveryAdminUtil.getDiscoveryAdmin
                                                                (srvcReg);
        String[] memberGroups1 = admin1.getMemberGroups();
        LocatorsUtil.displayLocator(
                QAConfig.getConstrainedLocator(srvcReg.getLocator()),
                "  lookup locator",Level.FINE);
        logger.log(Level.FINE,
                          "  lookup MemberGroup(s) = "
                          +GroupsUtil.toCommaSeparatedStr(memberGroups1));
        /* Give the event time to arrive */
        i = 0;
        if(!eventReceived) {
        for(i=1;i<nSecsWait;i++) {
                DiscoveryServiceUtil.delayMS(1000);
                if(eventReceived) break;
            }
        }//endif
        if(eventReceived) {
            logger.log(Level.FINE,
               "second discovery event received after "+i+" second(s)");
        } else {
            throw new TestException(
                             " -- waited "+i+" seconds, but no discovery "
                             +"event received for the second lookup "
                             +"service started");
        }//endif
        /* Remove the lease from the renewal manager so it can expire */
        try {
            lrm.remove(lease);
            logger.log(Level.FINE,
                              "removed the lease from the renewal "
                              +"manager");
        } catch(UnknownLeaseException e) {
            logger.log(Level.FINE,
                            "UnknownLeaseException -- failed to "
                            +"removed the lease from the renewal manager");
        }
        /* Wait long enough to allow the registration lease to expire */
        logger.log(Level.FINE,
                              "waiting for lease expiration ...");
        boolean leaseExpired = false;
        for(i=0;i<N_CYCLES_WAIT_EXPIRATION;i++) {
            DiscoveryServiceUtil.delayMS(2*actualDur);
            /* Verify the lease has expired by trying to renew the lease */
            try {
                lease.renew(duration);
            } catch (UnknownLeaseException e) { //expected exception
                leaseExpired = true;
                logger.log(Level.FINE,
                              "lease on the registration has expired");
                break;
            }
        }//end loop
        if(!leaseExpired) {
            logger.log(Level.FINE,
                              "failure -- lease still exists");
            throw new TestException(
                             " -- lease did not expire after "
                             +(N_CYCLES_WAIT_EXPIRATION*2*(actualDur/1000))
                             + "seconds");
        }//endif
        /* Start another lookup belonging to same group(s) as first */
        logger.log(Level.FINE,
                          "starting a new lookup service");
        synchronized(eventLock) {
            eventReceived = false;
      srvcReg = manager.startLookupService(); // prepared
            lookupList.add( srvcReg );
        }//end synchronized

        // prepared by DiscoveryAdminUtil
        DiscoveryAdmin admin2 = DiscoveryAdminUtil.getDiscoveryAdmin
                                                                (srvcReg);
        String[] memberGroups2 = admin2.getMemberGroups();
        LocatorsUtil.displayLocator(
                QAConfig.getConstrainedLocator(srvcReg.getLocator()),
                "  lookup locator",Level.FINE);
        logger.log(Level.FINE,
                          "  lookup MemberGroup(s) = "
View Full Code Here

            regProxy
                    = ((DiscoveryProtocolSimulator)generator).getLookupProxy();
            ((DiscoveryProtocolSimulator)generator).setMemberGroups(newGroups);
        } else {
            regProxy = (ServiceRegistrar)generator;
            DiscoveryAdmin admin
                    = (DiscoveryAdmin)( ((Administrable)regProxy).getAdmin() );
      try {
                admin = (DiscoveryAdmin)
            getConfig().prepare("test.reggieAdminPreparer", admin);
      } catch (TestException e) {
    throw new RemoteException("Problem preparing admin", e);
      }
            admin.setMemberGroups(newGroups);
        }//endif
        LookupLocator loc = QAConfig.getConstrainedLocator(regProxy.getLocator());
        return new LocatorGroupsPair(loc,newGroups);
    }//end replaceMemberGroups
View Full Code Here

    protected LocatorGroupsPair replaceMemberGroups(Object generator,
                                                    boolean alternate)
                                                        throws RemoteException
    {
        ServiceRegistrar regProxy = null;
  DiscoveryAdmin admin = null;
  // only prepare the real proxy (until simulators are secure)
        if(generator instanceof DiscoveryProtocolSimulator) {
            regProxy
                   = ((DiscoveryProtocolSimulator)generator).getLookupProxy();
      admin = (DiscoveryAdmin)( ((Administrable)regProxy).getAdmin() );
        } else {
            regProxy = (ServiceRegistrar)generator;
      admin = (DiscoveryAdmin)( ((Administrable)regProxy).getAdmin() );
      try {
                admin = (DiscoveryAdmin)
            getConfig().prepare("test.reggieAdminPreparer", admin);
      } catch (TestException e) {
    throw new RemoteException("Problem preparing admin", e);
      }
        }//endif
        String[] groups    = admin.getMemberGroups();
        String[] newGroups =  ( (groups.length > 0) ?
                          (new String[groups.length]) :
                          (new String[] {"Group_"+regProxy.getServiceID()}) );
        if(newGroups.length == 0) {
            logger.log(Level.FINE, "   NO_GROUPS");
View Full Code Here

    {
        if( (proxy == null) || (groups == null) ) return false;
        /* First, test that the lookup service implements both of the
         * appropriate administration interfaces
         */
        DiscoveryAdmin discoveryAdmin = null;
        if( !(proxy instanceof Administrable) ) return false;
        Object admin = ((Administrable)proxy).getAdmin();
//  try {
            admin = getConfig().prepare("test.reggieAdminPreparer", admin);
//  } catch (TestException e) {
//      throw new RemoteException("Preparation error", e);
//  }
        if( !(admin instanceof DiscoveryAdmin) ) return false;
        discoveryAdmin = (DiscoveryAdmin)admin;
        /* Set the member groups for the lookup service */
        discoveryAdmin.setMemberGroups(groups);
        return true;
    }//end setLookupMemberGroups
View Full Code Here

        testLocator("hostname", 40, "jini://hostname:40/", true);
        testLocator("hostname", 70000, "jini://hostname:70000/", false);
        testLocator("hostname", -300, "jini://hostname:-300/", false);

        // Ensure that the locator actually works.
        DiscoveryAdmin admin = null;

  ServiceRegistrar reg = createLookup();
  admin = getAdmin(reg);
  String[] actualGroups = new String[] {
      "disc_test" };
  admin.setMemberGroups(actualGroups);
  LookupLocator locator =
      QAConfig.getConstrainedLocator(reg.getLocator());
  ServiceRegistrar reg1 = locator.getRegistrar();
 
  if (reg1.equals(reg) == false) {
View Full Code Here

        }
    }

    public void run() throws Exception {
        LookupDiscovery disc = null;
        DiscoveryAdmin admin = null;

  // Create a LookupDiscovery object.
  disc = new LookupDiscovery(Util.makeGroups("start", 700),
           getConfig().getConfiguration());
  logger.log(Level.INFO,
       "constructed with " + disc.getGroups().length + " elements");
  Thread.sleep(10000);
  disc.addDiscoveryListener(new Ignorer());
  ServiceRegistrar reg = createLookup();
  admin = getAdmin(reg);
  String[] actualGroups = new String[] {
      reg.getServiceID().toString() };
  admin.setMemberGroups(actualGroups);
  disc.addGroups(Util.makeGroups("added", 200));
  logger.log(Level.INFO, "increased to " + disc.getGroups().length
       + " elements");
  Thread.sleep(10000);
  disc.removeGroups(Util.makeGroups("start", 300));
View Full Code Here

            throw new IOException(String.format("Service %s has been declared for ALL_GROUPS", serviceElement.getName()));
        }
        for(ServiceRegistrar registrar : discoveryManagement.getRegistrars()) {
            try {
                List<String> toAdd = new ArrayList<String>();
                DiscoveryAdmin admin = (DiscoveryAdmin) ((Administrable)registrar).getAdmin();
                String[] knownGroups = admin.getMemberGroups();
                for(String serviceGroup : serviceElement.getServiceBeanConfig().getGroups()) {
                    boolean found = false;
                    for(String known : knownGroups) {
                        if(serviceGroup.equals(known)) {
                            found = true;
                            break;
                        }
                    }
                    if(!found) {
                        toAdd.add(serviceGroup);
                    }
                }
                if(!toAdd.isEmpty()) {
                    admin.addMemberGroups(toAdd.toArray(new String[toAdd.size()]));
                    if(logger.isDebugEnabled()) {
                        logger.debug("Added {} to ServiceRegistrar at {}:{}",
                                     toAdd, registrar.getLocator().getHost(), registrar.getLocator().getPort());
                    }
                }
View Full Code Here

TOP

Related Classes of net.jini.lookup.DiscoveryAdmin

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.