Hi,

I got it working. The problem was that I am using a security manager, and a
permission was missing:

   permission com.sun.jini.thread.ThreadPoolPermission "getUserThreadPool";

Which I presume the LookupCache needed. It resulted in an uncaught
exception, which was logged, and I wouldn't have spotted it, if I hadn't set
of Log4J and Chainsaw. Seems to be logged but swallowed. I usually add a
top-level error handler to all threads in my code, that logs and calls
System.exit(-1), on any uncaught exceptions. Drastic, but at least you find
out quickly about the problem.

Thanks again Tom and Dennis for the replies. Got this all ready to fly to
now!

Rupert

On 3 December 2010 13:06, Rupert Smith <[email protected]> wrote:

> I am now using a LookupCache to attempt to receive notification on the
> availability of services. Here is the code I use to create the cache:
>
>         // Locate the Jini registry.
>         LookupLocator lookup = new LookupLocator(jiniRegistryURL);
>         LookupLocatorDiscovery discovery = new LookupLocatorDiscovery(new
> LookupLocator[] { lookup });
>         discovery.addDiscoveryListener(this);
>
>         // Create a service discovery manager for the JMX Connector
> services.
>         ServiceDiscoveryManager serviceDiscoveryManager =
>             new ServiceDiscoveryManager(discovery, new
> LeaseRenewalManager());
>
>         Class[] classes = new Class[] { JMXConnector.class };
>         Entry[] serviceAttrs =
>                 new Entry[] { new
> com.sun.jini.lookup.entry.BasicServiceType(JMX_CONNECTOR_SERVICE_NAME) };
>         ServiceTemplate template = new ServiceTemplate(null, classes,
> serviceAttrs);
>
>         // Register to be notified of changes to the available JMX
> Connector services.
>         LookupCache cache =
> serviceDiscoveryManager.createLookupCache(template, null, this);
>
> It works, but... Only if the requested service has already been registered
> (by a seperate app) _before+ this code is run. Also when a service lease is
> cancelled, the 'serviceRemoved' listener method is not invoked. I must be
> doing something wrong.
>
> I was expecting that after the above is run, the cache is now running, and
> new service registrations/expiries will continue to result in calls to the
> local listener methods. Have I misconfiguration things? Also I just used
> 'new LeaseRenewalManager()' with no-args, to fill in one parameter without
> really understanding what I am doing there. Could that be the problem?
>
> Thanks for the help so far, I feel like I am almost there now.
>
> Rupert
>
> =================
>
> Here is the code the apps use, on being shutdown to deregister their
> services (the lease is cancelled), I presume thats the right way to do it?
>
> private void unregisterRMIConnector()
>     {
>         if (rmiConnectorRegistration != null)
>         {
>             log.fine("Unregistering ServiceID: " +
> rmiConnectorRegistration.getServiceID().toString());
>
>             try
>             {
>                 rmiConnectorRegistration.getLease().cancel();
>             }
>             catch (UnknownLeaseException e)
>             {
>                 // Best effort has been made to cancel the registration,
> compensating action, registration is nulled.
>                 e = null;
>             }
>             catch (RemoteException e)
>             {
>                 // Best effort has been made to cancel the registration,
> compensating action, registration is nulled.
>                 e = null;
>             }
>
>             rmiConnectorRegistration = null;
>         }
>     }
>
>
>

Reply via email to