org.jgroups.service.lease
Class LeaseFactoryService

java.lang.Object
  extended byorg.jgroups.service.AbstractService
      extended byorg.jgroups.service.lease.LeaseFactoryService
All Implemented Interfaces:
MembershipListener

public class LeaseFactoryService
extends AbstractService

LeaseFactoryService is service that is able to lease resources to clients. Lease request is sent using client-service communication channel and is identified by presence of LeaseRequestHeader header in message headers. There might be only one lease request header per message. It contains information about lease term and entity requesting lease, message payload contains unique identifier of resource to lease.

There is only one lease factory service talking to the client, coordinator of service group. Group of lease factory services is able to tolerate failures detectable by failure detector of inter-service communication channel.

This service is able to grant only one lease per resource, it is not able to determine correctly best-fit lease duration and uses fixed duration of 10 seconds, maximum duration is 60 seconds. Note, these durations apply only cases when lease term was not explicitly specified (LeaseFactory.DURATION_ANY or LeaseFactory.DURATION_FOREVER used as lease term). Subclasses might use more intelligent algorithm to determine lease duration and lease request conflicts using semantics of underlying resource.

Author:
Roman Rokytskyy (rrokytskyy@acm.org)

Nested Class Summary
static class LeaseFactoryService.LeaseInfo
          This class represents granted lease that is replicated between services.
 
Field Summary
protected  PullPushAdapter clientAdapter
           
static int DEFAULT_BEST_FIT_DURATION
           
static java.lang.String LEASE_SERVICE_NAME
           
protected  java.util.Map leases
           
static int MAXIMUM_DURATION
           
 
Fields inherited from class org.jgroups.service.AbstractService
blocked, blockMonitor, clientChannel, log, members, runThread, serviceAdapter, serviceChannel, threadMonitor
 
Constructor Summary
LeaseFactoryService(Channel serviceChannel, Channel clientChannel)
          Create instance of this class.
 
Method Summary
protected  void denyLeaseRequest(int denialType, Address requester, java.lang.String reason, java.lang.Object leaseTarget, java.lang.Object tenant)
          Deny lease request.
protected  long getBestFitDuration()
          Get best-fit duration leases with duration LeaseFactory.DURATION_ANY.
protected  long getMaximumDuration()
          Get best-fit duration leases with duration LeaseFactory.DURATION_FOREVER.
 java.lang.String getName()
          Get name of this service.
protected  void incorrectStateReceived(java.lang.Object incorrectState)
          This method is called when service queries new state but received state contains incorrect entries.
protected  void processCancelLeaseRequest(LeaseRequestHeader header, java.lang.Object leaseTarget, Address requester)
          Process request to cancel lease.
protected  void processNewLeaseRequest(LeaseRequestHeader header, java.lang.Object leaseTarget, Address requester)
          Process new lease request.
protected  void processRenewLeaseRequest(LeaseRequestHeader header, java.lang.Object leaseTarget, Address requester)
          Process request to renew a lease.
protected  void propagateStateChange(int type, LeaseFactoryService.LeaseInfo leaseInfo, java.lang.Object leaseTarget)
          Propagate state change to other members.
 
Methods inherited from class org.jgroups.service.AbstractService
block, getAddress, isBlocked, isCoordinator, setMessageListener, start, stop, suspect, viewAccepted, waitOnBlocked
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEASE_SERVICE_NAME

public static final java.lang.String LEASE_SERVICE_NAME
See Also:
Constant Field Values

DEFAULT_BEST_FIT_DURATION

public static final int DEFAULT_BEST_FIT_DURATION
See Also:
Constant Field Values

MAXIMUM_DURATION

public static final int MAXIMUM_DURATION
See Also:
Constant Field Values

clientAdapter

protected PullPushAdapter clientAdapter

leases

protected java.util.Map leases
Constructor Detail

LeaseFactoryService

public LeaseFactoryService(Channel serviceChannel,
                           Channel clientChannel)
Create instance of this class. This constructor constructs registers message listeners on client-service and inter-service communication channel.

Parameters:
serviceChannel - channel that will be used for inter-service communication.
clientChannel - channel that will be used for client-service communication.
Method Detail

getName

public java.lang.String getName()
Get name of this service.

Specified by:
getName in class AbstractService
Returns:
value of LEASE_SERVICE_NAME constant.

getBestFitDuration

protected long getBestFitDuration()
Get best-fit duration leases with duration LeaseFactory.DURATION_ANY. Value returned by this method is absolute expiration time.

Returns:
System.currentTimeMillis() + DEFAULT_BEST_FIT_DURATION;

getMaximumDuration

protected long getMaximumDuration()
Get best-fit duration leases with duration LeaseFactory.DURATION_FOREVER. Value returned by this method is absolute expiration time.

Returns:
System.currentTimeMillis() + MAXIMUM_DURATION;

incorrectStateReceived

protected void incorrectStateReceived(java.lang.Object incorrectState)
This method is called when service queries new state but received state contains incorrect entries. Subclasses should implement this method according to their needs.


propagateStateChange

protected void propagateStateChange(int type,
                                    LeaseFactoryService.LeaseInfo leaseInfo,
                                    java.lang.Object leaseTarget)
Propagate state change to other members.


denyLeaseRequest

protected void denyLeaseRequest(int denialType,
                                Address requester,
                                java.lang.String reason,
                                java.lang.Object leaseTarget,
                                java.lang.Object tenant)
Deny lease request.


processNewLeaseRequest

protected void processNewLeaseRequest(LeaseRequestHeader header,
                                      java.lang.Object leaseTarget,
                                      Address requester)
Process new lease request. This method checks if there is already lease on the specified resource, and if no lease found grants it. Otherwise lease request is denied and appropriate message is sent to client.


processRenewLeaseRequest

protected void processRenewLeaseRequest(LeaseRequestHeader header,
                                        java.lang.Object leaseTarget,
                                        Address requester)
Process request to renew a lease. This method checks if lease was granted and extends lease duration if


processCancelLeaseRequest

protected void processCancelLeaseRequest(LeaseRequestHeader header,
                                         java.lang.Object leaseTarget,
                                         Address requester)
Process request to cancel lease. This method checks if lease was granted, and cancels it if there is a match between party that was granted a lease and a party that cancels a lease.



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