org.psepr.jClient
Class ConnectionHandler

java.lang.Object
  extended by org.psepr.jClient.ConnectionHandler
All Implemented Interfaces:
EventReceiver

public class ConnectionHandler
extends java.lang.Object
implements EventReceiver

This class makes a connection to the PsEPR system. It wraps up some of the stuff around retrying and identity defaulting to create a simple connection.

Usual use of this class is:

 ConnectionHandler connH = new ConnectionHandler();
       connH.setSendService("PsEPRServiceName");
       connH.setSendPassword("PsEPRServicePassword);
       ( or connH.setIdentity(new PsEPRServiceIdentity(params)); )
       connH.start();
       ( optionally connH.monitorConnection(); )
       ...
       LeaseHandler leaseH = new LeaseHandler(connh.getConnection(), ...);
       ...
       connH.stop();
 

On can directly set the PsEPRServiceIdentity or you can set the sendService and sendServicePassword and let this routine build the PsEPRServiceIdentity. If neither are specified, it tries to get the default service from the PsEPR config files.

It does not create a monitoring lease directly, although one can easily do it by calling monitorConnection. The monitorConnection routine can be passed an instance of LeaseWatcher which will be called if the connection is lost and cannot be restored. This monitoring is not needed if the program does any of it's own lease invocations.


Constructor Summary
ConnectionHandler()
           
ConnectionHandler(PsEPRServiceIdentity id)
           
ConnectionHandler(java.lang.String srv, java.lang.String srvPassword)
           
 
Method Summary
 PsEPRConnection getConnection()
           
 PsEPRServiceIdentity getIdentity()
           
 java.lang.String getService()
           
 java.lang.String getServicePassword()
           
 void init()
           
 boolean isConnected()
          return true if the PsEPR connectin is up and happy
 boolean isShouldMonitor()
           
 void monitorConnection()
           
 void monitorConnection(LeaseWatcher watcher)
           Called after starting the connection to cause a lease to be added to the connection.
 boolean receiveEvent(PsEPREvent pEvent)
          class for events on the monitoring channel.
 void setConnection(PsEPRConnection connection)
           
 void setIdentity(PsEPRServiceIdentity identity)
           
 void setService(java.lang.String sendService)
           
 void setServicePassword(java.lang.String sendServicePassword)
           
 void setShouldMonitor(boolean shouldMonitor)
           
 void start()
          Start the connectin to the PsEPR infrastrcuture
 void stop()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionHandler

public ConnectionHandler()

ConnectionHandler

public ConnectionHandler(java.lang.String srv,
                         java.lang.String srvPassword)

ConnectionHandler

public ConnectionHandler(PsEPRServiceIdentity id)
Method Detail

init

public void init()

getConnection

public PsEPRConnection getConnection()

setConnection

public void setConnection(PsEPRConnection connection)

getIdentity

public PsEPRServiceIdentity getIdentity()

setIdentity

public void setIdentity(PsEPRServiceIdentity identity)

getService

public java.lang.String getService()

setService

public void setService(java.lang.String sendService)

getServicePassword

public java.lang.String getServicePassword()

setServicePassword

public void setServicePassword(java.lang.String sendServicePassword)

isShouldMonitor

public boolean isShouldMonitor()

setShouldMonitor

public void setShouldMonitor(boolean shouldMonitor)

isConnected

public boolean isConnected()
return true if the PsEPR connectin is up and happy

Returns:

start

public void start()
           throws java.lang.Exception
Start the connectin to the PsEPR infrastrcuture

Throws:
java.lang.Exception

stop

public void stop()

monitorConnection

public void monitorConnection()

monitorConnection

public void monitorConnection(LeaseWatcher watcher)

Called after starting the connection to cause a lease to be added to the connection. This causes us to periodically talk to the PsEPR server and make sure it's still alive. If the lease cannot be renewed, the server must be down and we should reconnect to a different server.

A user can either call setShouldMonitor() before or after the connection is made or can call this function directory after the call to start().

This functionality not needed if the application make it's own leases since it will notice the connection going down.

Parameters:
watcher - called if no connections to the server can be made

receiveEvent

public boolean receiveEvent(PsEPREvent pEvent)
class for events on the monitoring channel. This doesn't do anything.

Specified by:
receiveEvent in interface EventReceiver
Parameters:
pEvent -
Returns: