org.psepr.jClient
Class LeaseHandler

java.lang.Object
  extended by org.psepr.jClient.LeaseHandler

public class LeaseHandler
extends java.lang.Object

Create a single lease and keep an eye on it and call back if it fails.

When one calls for a lease, it may take a while to aquire same and, later, the connectin could drop or the server could not be replying to the lease so the application must take some action.

Using this routine to create a lease also creates a watcher thread that keeps checking to make sure the lease is still alive. If the lease goes inactive, the PsEPR connection is forced to reconnect and the lease will get renegotiated.

If the lease cannot be restored, an optional routine that implements the LeaseWatcher interface is called with an error string.

Code using this routine looks like:

 // pConn == an aquired PsEPRConnection (see PsEPRConnection
 LeaseHandler inLease = null;
 try {
        // get some parser for the payloads
        PayloadParser xParser = new PayloadGeneric();
        // ask for the lease (notice no LeaseManager specified
        inLease = new LeaseHandler(pConn, "/", xParser, eQueue, null);
 // wait for the lease to be active
 inLease.waitForLease();
 }
 catch (PsEPRException e) {
        System.out.println("GetLease failed:"+e.toString());
        pConn.close();
        return;
 }
 catch (Exception e) {
        // who knows why this would ever happen
        System.out.println("GetLease exception:"+e.toString());
        pConn.close();
        return;
 }
 

Author:
Robert.Adams@intel.com

Constructor Summary
LeaseHandler()
           
LeaseHandler(PsEPRConnection con, java.lang.String chan, PayloadParser pp, EventReceiver eq, LeaseWatcher lw)
           
 
Method Summary
 void connect()
          Do a manual connect after setting all the correct parameters
 void disconnect()
          Disconnect the lease from the connection
 java.lang.String getChannel()
           
 PsEPRConnection getConnection()
           
 EventReceiver getEventReceiver()
           
 PsEPRLease getLease()
           
 LeaseWatcher getLeaseWatcher()
           
 PayloadParser getPayloadParser()
           
 void setChannel(java.lang.String xx)
           
 void setConnection(PsEPRConnection xx)
           
 void setEventReceiver(EventReceiver xx)
           
 void setLeaseWatcher(LeaseWatcher xx)
           
 void setPayloadParser(PayloadParser xx)
           
 void waitForLease()
          Wait until the lease is active.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeaseHandler

public LeaseHandler()

LeaseHandler

public LeaseHandler(PsEPRConnection con,
                    java.lang.String chan,
                    PayloadParser pp,
                    EventReceiver eq,
                    LeaseWatcher lw)
             throws PsEPRException
Throws:
PsEPRException
Method Detail

getConnection

public PsEPRConnection getConnection()

setConnection

public void setConnection(PsEPRConnection xx)

getChannel

public java.lang.String getChannel()

setChannel

public void setChannel(java.lang.String xx)

getPayloadParser

public PayloadParser getPayloadParser()

setPayloadParser

public void setPayloadParser(PayloadParser xx)

getEventReceiver

public EventReceiver getEventReceiver()

setEventReceiver

public void setEventReceiver(EventReceiver xx)

getLeaseWatcher

public LeaseWatcher getLeaseWatcher()

setLeaseWatcher

public void setLeaseWatcher(LeaseWatcher xx)

getLease

public PsEPRLease getLease()

connect

public void connect()
             throws PsEPRException
Do a manual connect after setting all the correct parameters

Throws:
PsEPRException

disconnect

public void disconnect()
Disconnect the lease from the connection


waitForLease

public void waitForLease()
Wait until the lease is active.