org.jgroups.service.lease
Class LeaseFactoryClient

java.lang.Object
  extended byorg.jgroups.service.lease.LeaseFactoryClient
All Implemented Interfaces:
LeaseFactory

public class LeaseFactoryClient
extends java.lang.Object
implements LeaseFactory

LeaseFactoryClient is an implementation of LeaseFactory interface that delegates lease granting to group containing one or more LeaseFactoryService instances.

This service tries to implement semi-synchronous communication pattern: each call blocks until reply from service received or timeout occurs.

Also this implementation assumes that pending new lease request conflicts with renewal request and request that came last is aborted.

Author:
Roman Rokytskyy (rrokytskyy@acm.org)

Field Summary
protected  int cancelTimeout
           
protected  PullPushAdapter clientAdapter
           
protected  Channel clientChannel
           
static int DEFAULT_CANCEL_TIMEOUT
           
static int DEFAULT_LEASE_TIMEOUT
           
protected  int leaseTimeout
           
protected  Log log
           
protected  java.util.HashMap pendingCancels
           
protected  java.util.HashMap pendingLeases
           
protected  java.util.HashMap pendingRenewals
           
 
Fields inherited from interface org.jgroups.service.lease.LeaseFactory
DURATION_ANY, DURATION_FOREVER
 
Constructor Summary
LeaseFactoryClient(Channel clientChannel)
          Create instance of this class for specified client channel with default timeouts.
LeaseFactoryClient(Channel clientChannel, int leaseTimeout, int cancelTimeout)
          Create instance of this class for the specified channel with specified timeouts.
 
Method Summary
 void cancelLease(Lease existingLease)
          Cancel existing lease.
 Address getAddress()
          Get address of this client in group.
 Lease newLease(java.lang.Object leaseTarget, java.lang.Object tenant, long requestedDuration, boolean isAbsolute)
          Get new lease.
 Lease renewLease(Lease existingLease, long requestedDuration, boolean isAbsolute)
          Renew existing lease.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LEASE_TIMEOUT

public static final int DEFAULT_LEASE_TIMEOUT
See Also:
Constant Field Values

DEFAULT_CANCEL_TIMEOUT

public static final int DEFAULT_CANCEL_TIMEOUT
See Also:
Constant Field Values

clientChannel

protected Channel clientChannel

clientAdapter

protected PullPushAdapter clientAdapter

leaseTimeout

protected int leaseTimeout

cancelTimeout

protected int cancelTimeout

pendingLeases

protected java.util.HashMap pendingLeases

pendingRenewals

protected java.util.HashMap pendingRenewals

pendingCancels

protected java.util.HashMap pendingCancels

log

protected Log log
Constructor Detail

LeaseFactoryClient

public LeaseFactoryClient(Channel clientChannel)
Create instance of this class for specified client channel with default timeouts.


LeaseFactoryClient

public LeaseFactoryClient(Channel clientChannel,
                          int leaseTimeout,
                          int cancelTimeout)
Create instance of this class for the specified channel with specified timeouts.

Parameters:
clientChannel - channel that will be used for client-service communication.
leaseTimeout - timeout for "new lease" and "renew lease" requests.
cancelTimeout - timeout for "cancel lease" timeout.
Method Detail

cancelLease

public void cancelLease(Lease existingLease)
                 throws UnknownLeaseException
Cancel existing lease.

Specified by:
cancelLease in interface LeaseFactory
Parameters:
existingLease - lease to cancel.
Throws:
UnknownLeaseException - if existingLease is unknown for this lease factory. Usually means that lease was granted by another factory.

newLease

public Lease newLease(java.lang.Object leaseTarget,
                      java.lang.Object tenant,
                      long requestedDuration,
                      boolean isAbsolute)
               throws LeaseDeniedException
Get new lease.

Specified by:
newLease in interface LeaseFactory
Parameters:
leaseTarget - unique identifier of resource to be leased.
tenant - unique identifier of entity that requests lease.
isAbsolute - specified if lease duration is absolute or relative.
Returns:
instance of Lease representing granted lease. Note, granted lease might have different duration than requested.
Throws:
LeaseDeniedException - if lease cannot be granted.

renewLease

public Lease renewLease(Lease existingLease,
                        long requestedDuration,
                        boolean isAbsolute)
                 throws LeaseDeniedException
Renew existing lease. This method is used to extend lease time, therefore existingLease must be valid.

Specified by:
renewLease in interface LeaseFactory
Parameters:
isAbsolute - specified if lease duration is absolute or relative.
Returns:
instance of Lease representing granted lease. Note, granted lease might have different duration than requested.
Throws:
LeaseDeniedException - if lease cannot be granted.

getAddress

public Address getAddress()
Get address of this client in group.



Copyright ? 2001,2002 www.jgroups.com . All Rights Reserved.