Hi Rupert,

As far as I know, you can use the default constructor for LeaseRenewalManager.

Then, every time you come across a lease that you want to renew, you
simply call;

myLeaseRenewalManager.renewUntil(newLease, expiry, null);

Or give it a LeaseListener in place of null if you have any special
conditions you want to handle.  From the API docs;

"[you] must create an instance of this class [the service's] own
virtual machine to locally manage the leases granted to [it]".

So your service implementation must renew it's own lease, this is not
the same as having a single LeaseRenewalManager on your network which
automatically updates all the leases for every service which is
discoverable.  I suppose it's possible that you could get the lease
for each service (say, by adding a method onto the service's
interface) which you could then use with the LRM, but I've never tried
that.

Hope that helps.

Tom


On Fri, Dec 17, 2010 at 12:22 PM, Rupert Smith
<rupertlssm...@googlemail.com> wrote:
> Hi,
>
> I have set up a ServiceDiscoveryManager, and used it to create a LookupCache
> of services it finds. All good, but a short while after a new service is
> found it is removed from the cache, presumably as the lease has expired. So
> I want to set up a LeaseRenewalManager to keep the lease going, but I can't
> figure out how this is supposed to work. Here's the code to set up the
> cache:
>
>    private void startListeningForJMXConnectors() throws IOException,
> ClassNotFoundException
>    {
>        // 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 = serviceDiscoveryManager.createLookupCache(template,
> null, this);
>    }
>
> I think the LeaseRenewalManager constructor I want is this one:
>
> *LeaseRenewalManager<../../../net/jini/lease/LeaseRenewalManager.html#LeaseRenewalManager(net.jini.core.lease.Lease,
> long, 
> net.jini.lease.LeaseListener)>*(Lease<../../../net/jini/core/lease/Lease.html>
> lease,
> long desiredExpiration,
> LeaseListener<../../../net/jini/lease/LeaseListener.html>
>  listener)
>
> I can't figure out where to get the Lease object from though. Or is it
> something that I implement myself?
>
> Rupert
>

Reply via email to