org.mbari.siam.core
Class CommsLeaseListener

java.lang.Object
  extended by org.mbari.siam.core.CommsLeaseListener
All Implemented Interfaces:
LeaseListener
Direct Known Subclasses:
AuxComms.Listener

public class CommsLeaseListener
extends java.lang.Object
implements LeaseListener

CommsLeaseListener responds to the Node's LeaseManager leasing events, and in response carries out several tasks to manage the relationship with the node's "parent" node. E.g. in the case of the primary surface node, CommsLeaseListener applies power to the radio that enables the communications link to its parent, which in this case is the shore portal. The class assumes there may be a device whose power is turned on/off by invoking scripts (specified in the node properties). CommsLeaseListener has delays built in to account for the time it takes to establish the communication link, and to allow the application protocol to get to the other side before tearing down the link. When it gets establishCallback() and power is not already on, it turns on RF power, delays for CommsManager.radioAcquireTime, and then notifies the parent via Node.notifyParentLinkConnected(). Conversely, when it gets terminateCallback() or expiredCallback() and the remaining connections == 0 and power is already on, it calls Node.notifyParentLinkDisconnecting(), delays for CommsManager.protocolWaitTime and then turns off RF power. 2/7/2006 k headley When a subnode is configured with a secondary wireless link to shore, it should only bring up the ppp link, and not notify its parent (or the portal) that the link is up. To that end, a new property (CommsManager.notifyParent) has been added to siamPort.cfg to indicate that the CommsLeaseListener should not contact its parent node as part of establishing and releasing communications. If CommsManager.notifyParent is set to false, the ppp link will be established at the specified interval, but no telemetry will take place.

Author:
Bob Herlien - derived from CommsManager.java

Field Summary
protected  boolean _commsManagerEnabled
           
protected  java.lang.String _commsOffCommand
           
protected  java.lang.String _commsOnCommand
           
protected  java.lang.String _commsStatusCommand
           
protected  boolean _establishingLease
           
protected  org.mbari.siam.core.CommsLeaseListener.CommsSleepRollCallListener _listener
           
protected  java.lang.Object _lock
           
protected  long _nextEstablishTime
           
protected  NodeProperties _nodeProperties
           
protected  NodeService _nodeService
           
protected  SyncProcessRunner _processRunner
           
protected  long _processWaitTime
           
protected  long _protocolWaitTime
           
protected static int COMMS_CONNECTED
           
protected static int COMMS_DISCONNECTED
          By convention, "connection status" command should return 0 if link IS connected, else return 1 if link is NOT connected.
protected static java.lang.String DFLT_COMMS_STATUS_COMMAND
           
protected  long onTime
           
protected static int PORT_IN_USE
          By convention, connection and disconnection commands should return value of 0 if successful, and non-zero in case of error.
protected static long PROTOCOL_WAIT_TIME
           
 
Method Summary
 boolean commLinkConnected()
          Return true if comms link is connected.
protected  void disconnectingCallback(long nextConnectMsec)
          Invoked before link is disconnected.
 void initialize()
          This method must be called by creator (not constructor) to initialize parameters.
 void leaseEstablishCallback(int leaseID, long leasePeriod, long nextEstablishTime, int numConnections)
          Called when a lease is being established.
 void leaseExpiredCallback(int leaseID, long nextEstablishTime, int numConnections)
          Called when lease expires.
 void leaseRenewalCallback(int leaseID, long leasePeriod, int numConnections)
          Called when lease is being renewed.
 void leaseTerminatedCallback(int leaseID, long nextEstablishTime, int numConnections)
          Called when lease is being terminated.
 void switchCommsOff()
          Shut down comms link, turn off power.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_WAIT_TIME

protected static final long PROTOCOL_WAIT_TIME
See Also:
Constant Field Values

_nodeProperties

protected NodeProperties _nodeProperties

_nodeService

protected NodeService _nodeService

_lock

protected java.lang.Object _lock

_listener

protected org.mbari.siam.core.CommsLeaseListener.CommsSleepRollCallListener _listener

_nextEstablishTime

protected long _nextEstablishTime

_commsManagerEnabled

protected boolean _commsManagerEnabled

_protocolWaitTime

protected long _protocolWaitTime

_processWaitTime

protected long _processWaitTime

_commsOnCommand

protected java.lang.String _commsOnCommand

_commsOffCommand

protected java.lang.String _commsOffCommand

_commsStatusCommand

protected java.lang.String _commsStatusCommand

_processRunner

protected SyncProcessRunner _processRunner

onTime

protected long onTime

PORT_IN_USE

protected static final int PORT_IN_USE
By convention, connection and disconnection commands should return value of 0 if successful, and non-zero in case of error. The scripts should return PORT_IN_USE (255) if the port is in use by another process.

See Also:
Constant Field Values

COMMS_DISCONNECTED

protected static final int COMMS_DISCONNECTED
By convention, "connection status" command should return 0 if link IS connected, else return 1 if link is NOT connected.

See Also:
Constant Field Values

COMMS_CONNECTED

protected static final int COMMS_CONNECTED
See Also:
Constant Field Values

_establishingLease

protected boolean _establishingLease

DFLT_COMMS_STATUS_COMMAND

protected static final java.lang.String DFLT_COMMS_STATUS_COMMAND
See Also:
Constant Field Values
Method Detail

initialize

public void initialize()
This method must be called by creator (not constructor) to initialize parameters.


leaseEstablishCallback

public void leaseEstablishCallback(int leaseID,
                                   long leasePeriod,
                                   long nextEstablishTime,
                                   int numConnections)
                            throws LeaseRefused
Called when a lease is being established. If this is the first lease, inform the parent of the connection. If link to parent is not connected, turn on comms power and inform parent.

Specified by:
leaseEstablishCallback in interface LeaseListener
Parameters:
leaseID - lease ID of session being established
leasePeriod - lease period in milliseconds
nextEstablishTime - next estimated lease establishment time
numConnections - Total number of connections on the comms media, including this one.
Throws:
LeaseRefused

leaseTerminatedCallback

public void leaseTerminatedCallback(int leaseID,
                                    long nextEstablishTime,
                                    int numConnections)
Called when lease is being terminated. If RF power is on, inform Parent that power is about to be turned off. This callback implementation must execute in a timely manner.

Specified by:
leaseTerminatedCallback in interface LeaseListener
Parameters:
leaseID - lease ID of session being terminated
nextEstablishTime - next estimated lease establishment time
numConnections - Total number of connections on the comms media, after this one has been terminated

leaseExpiredCallback

public void leaseExpiredCallback(int leaseID,
                                 long nextEstablishTime,
                                 int numConnections)
Called when lease expires. This callback implementation must execute in a timely manner.

Specified by:
leaseExpiredCallback in interface LeaseListener
Parameters:
leaseID - lease ID of session being established
nextEstablishTime - next estimated lease establishment time
numConnections - Total number of connections on the comms media, after this one has expired

leaseRenewalCallback

public void leaseRenewalCallback(int leaseID,
                                 long leasePeriod,
                                 int numConnections)
                          throws LeaseRefused
Called when lease is being renewed. Not used by this implementation

Specified by:
leaseRenewalCallback in interface LeaseListener
Parameters:
leaseID - lease ID of session being renewed
leasePeriod - lease period in milliseconds
numConnections - Total number of connections on the comms media, including this one.
Throws:
LeaseRefused

disconnectingCallback

protected void disconnectingCallback(long nextConnectMsec)
                              throws java.lang.Exception
Invoked before link is disconnected.

Throws:
java.lang.Exception

switchCommsOff

public void switchCommsOff()
                    throws java.lang.Exception
Shut down comms link, turn off power.

Throws:
java.lang.Exception

commLinkConnected

public boolean commLinkConnected()
Return true if comms link is connected.



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.