org.psepr.jClient
Class SimpleLeaseManager

java.lang.Object
  extended by org.psepr.jClient.LeaseManager
      extended by org.psepr.jClient.SimpleLeaseManager
All Implemented Interfaces:
EventReceiver, PayloadParser

public class SimpleLeaseManager
extends LeaseManager

The simple lease manager tries to manage a lease of a fixed duration and, when the end of the lease nears, to request a new lease of that duration again. The effect is to keep the lease active until this.release() is called.

The use of this class is:

 LeaseManager myLM = new SimpleLeaseManager(channelName, leaseDurationInSeconds);
 PsEPRLease myLease = pConn.getLease(channelName, payloadParser, eventReceiver, myLM);
 ....
 pConn.releaseLease(myLease);
 
There are also calls in PsEPRConnection.getLease that hide the use of SimpleLeaseManager with a call that just specifies a duration:
 PsEPRLease myLease = pConn.getLease(channelName, payloadParser, eventReceiver, leaseDurationInSeconds);
 ...
 pConn.releaseLease(myLease);
 

This lease manager has several states:

A timeout routine is set while a lease is pending, active or renegotiating. If LEASE_ACTIVE, the timeout is LongTimeoutPercent/100 th of the granted time period and it causes this to renegotiate for a longer lease. If LEASE_PENDING or LEASE_RENEGOTIATING, the retry counter is counted down (starts at MaxRetries and counts down to zero) and the lease request is retried. In this case, the timeout period is ShortTimeoutPercent/100 th of the requested lease length.

Author:
Robert.Adams@intel.com

Constructor Summary
SimpleLeaseManager()
           
SimpleLeaseManager(PsEPRConnection pConn, java.lang.String chan, java.lang.String type)
           
SimpleLeaseManager(PsEPRConnection pConn, java.lang.String chan, java.lang.String type, long interval)
           
 
Method Summary
 void forceRenegotiation()
          Called to make the lease ask for permission again.
 java.lang.String getChannel()
           
 boolean getLeaseActive()
           
 long getLeaseGranted()
           
 java.lang.String getLeaseID()
          Return the unique identifier for the lease
 int getLeaseState()
           
 java.lang.String getLeaseStateName()
           
 long getLeaseWindow()
           
 int getLongTimeoutPercent()
           
 long getLongTimeoutPeriod()
           
 int getMaxRetries()
           
 int getRetriesRemaining()
           
 int getShortTimeoutPeriod()
           
 java.lang.String getType()
           
 boolean receiveEvent(PsEPREvent pE)
          Called to see if I want to process this event.
 void release()
          Release our lease.
 void setChannel(java.lang.String chan)
           
 void setLeaseGranted(long lg)
           
 void setLeaseID(java.lang.String xx)
           
 void setLeaseWindow(long lw)
          Set the duration of the lease.
 void setLongTimeoutPercent(int xx)
           
 void setMaxRetries(int mr)
           
 void setRetriesRemaining(int mr)
           
 void setShortTimeoutPeriod(int xx)
           
 void setType(java.lang.String tp)
           
 void start()
          Start the lease.
 
Methods inherited from class org.psepr.jClient.LeaseManager
getConnection, getNamespace, parsePayload, setConnection, setNamespace
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleLeaseManager

public SimpleLeaseManager()

SimpleLeaseManager

public SimpleLeaseManager(PsEPRConnection pConn,
                          java.lang.String chan,
                          java.lang.String type)

SimpleLeaseManager

public SimpleLeaseManager(PsEPRConnection pConn,
                          java.lang.String chan,
                          java.lang.String type,
                          long interval)
Method Detail

getLeaseActive

public boolean getLeaseActive()
Specified by:
getLeaseActive in class LeaseManager

getLeaseWindow

public long getLeaseWindow()

setLeaseWindow

public void setLeaseWindow(long lw)
Description copied from class: LeaseManager
Set the duration of the lease.

Specified by:
setLeaseWindow in class LeaseManager

getLeaseGranted

public long getLeaseGranted()

setLeaseGranted

public void setLeaseGranted(long lg)

getChannel

public java.lang.String getChannel()

setChannel

public void setChannel(java.lang.String chan)

getType

public java.lang.String getType()
Overrides:
getType in class LeaseManager

setType

public void setType(java.lang.String tp)
Overrides:
setType in class LeaseManager

getMaxRetries

public int getMaxRetries()

setMaxRetries

public void setMaxRetries(int mr)

getRetriesRemaining

public int getRetriesRemaining()

setRetriesRemaining

public void setRetriesRemaining(int mr)

getShortTimeoutPeriod

public int getShortTimeoutPeriod()

setShortTimeoutPeriod

public void setShortTimeoutPeriod(int xx)

getLeaseID

public java.lang.String getLeaseID()
Description copied from class: LeaseManager
Return the unique identifier for the lease

Specified by:
getLeaseID in class LeaseManager
Returns:

setLeaseID

public void setLeaseID(java.lang.String xx)

getLongTimeoutPercent

public int getLongTimeoutPercent()

setLongTimeoutPercent

public void setLongTimeoutPercent(int xx)

getLongTimeoutPeriod

public long getLongTimeoutPeriod()

getLeaseState

public int getLeaseState()

getLeaseStateName

public java.lang.String getLeaseStateName()

start

public void start()
Description copied from class: LeaseManager
Start the lease.

Specified by:
start in class LeaseManager

release

public void release()
Release our lease. This can throw a PsEPRException if the connection is gone.

Specified by:
release in class LeaseManager

forceRenegotiation

public void forceRenegotiation()
Called to make the lease ask for permission again. This usually happens when the XMPP connection is re-established.

Specified by:
forceRenegotiation in class LeaseManager

receiveEvent

public boolean receiveEvent(PsEPREvent pE)
Called to see if I want to process this event. If it's not a lease, it's not for me.

Specified by:
receiveEvent in interface EventReceiver
Overrides:
receiveEvent in class LeaseManager
Parameters:
pE - the event structure
Returns:
false if I didn't process the element