You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@river.apache.org by Rupert Smith <ru...@googlemail.com> on 2010/12/17 13:22:32 UTC

How do I auto renew lease on a ServiceDiscoveryManager?

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

Re: How do I auto renew lease on a ServiceDiscoveryManager?

Posted by Rupert Smith <ru...@googlemail.com>.
No, but I will take a look at JoinManager now, thanks for the tip.

For some reason, I had thought it was the consumers of services that were
responsible for taking leases on them, and renewing the leases. I guess I
had that the wrong way around, which must explain why I am not winning by
looking for the right methods to call on that side.

On 17 December 2010 15:29, Greg Trasuk <tr...@stratuscom.com> wrote:

>
>
> Rupert:
>
> Registration in the lookup service is subject to leasing.  Whoever
> registers the service has to manage and renew the lease with each lookup
> registrar.  JoinManager will look after this for you, so you don't have
> to bother with leases manually.  Additionally, it makes sure you have
> registered with all the lookup services that are discovered.  Are you
> using JoinManager on the side that registers the JMX connector?
>
> Cheers,
>
> Greg.
>
> > >
> > > 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
> > >
>
>

Re: How do I auto renew lease on a ServiceDiscoveryManager?

Posted by Greg Trasuk <tr...@stratuscom.com>.

Rupert:

Registration in the lookup service is subject to leasing.  Whoever
registers the service has to manage and renew the lease with each lookup
registrar.  JoinManager will look after this for you, so you don't have
to bother with leases manually.  Additionally, it makes sure you have
registered with all the lookup services that are discovered.  Are you
using JoinManager on the side that registers the JMX connector?

Cheers,

Greg.

> >
> > 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
> >


Re: How do I auto renew lease on a ServiceDiscoveryManager?

Posted by Tom Hobbs <tv...@googlemail.com>.
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
<ru...@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
>