org.mbari.siam.core
Class DevicePacketAggregator

java.lang.Object
  extended by org.mbari.siam.core.DevicePacketAggregator
All Implemented Interfaces:
java.util.EventListener, ServiceListener

public class DevicePacketAggregator
extends java.lang.Object
implements ServiceListener

DevicePacketAggregator implements two new method signatures of getDevicePackets() on behalf of the Node interface. These method signatures add the following capabilities to getDevicePackets

  1. It aggregates DevicePacketSets returned from Instrument or NodeManager._log, creating larger DevicePacketSets that can be transferred more efficiently over the telemetry system. The amount of aggregation is specified by the numBytes parameter to the two new methods.
  2. It provides a timeout parameter to these methods. This allows the calling object (e.g. Portal) to limit the amount of time waiting for non-responsive Instruments, and thus allows it (the Portal) to move on to collecting data from the other Instruments and subnodes.
The first capability is implemented by repeatedly calling the data source (as specified by the isiId) until we get at least numBytes bytes. Note that the data source (e.g. Instrument or NodeManager log) returns DevicePacketSets aggregated using its own native DevicePacketSet size. Thus the DevicePacketAggregator can return a DevicePacketSet containing a number of bytes that exceeds the request by one "native" DevicePacketSet from the isiId.

The second capability is implemented using threads. The calling method simply passes the request to a worker thread, and waits for the worker thread to signal that it's done. It uses Object.wait(timeout) to accomplish this, thus implementing the timeout function. To guard against the possibility that a "stuck" Instrument can block the entire system, we use a worker thread for each ISI ID. Thus a "stuck" Instrument can block later requests on that same Instrument, but will not block requests for a different Instrument.

This class implements ServiceListener. The reason is that we need to be notified when a user does a shutdownPort. In that case, we destroy the associated DevicePacketWorker. If the user then does a scanPort and later calls getDevicePackets() for that isiId, we'll generate a new worker with the new Device reference that resulted from the scanPort.


Nested Class Summary
protected  class DevicePacketAggregator.DeviceInstrumentSource
          Implementation of DevicePacketSource that uses an Instrument as its packet source.
protected  class DevicePacketAggregator.DeviceLogSource
          Implementation of DevicePacketSource that uses a FilteredDeviceLog as its packet source.
 class DevicePacketAggregator.DeviceLogTestSource
          Implementation of DevicePacketSource used for testing with tests.Aggregator.
protected  class DevicePacketAggregator.DevicePacketRequest
          Class representing one getDevicePackets() request and response
static interface DevicePacketAggregator.DevicePacketSource
          Interface class that defines a source of DevicePackets.
protected  class DevicePacketAggregator.DevicePacketWorker
          Worker thread that actually fetches the DevicePacketSet data.
 
Field Summary
protected  java.lang.String _directory
           
protected static org.apache.log4j.Logger _log4j
          Log4j logger
protected  NodeService _node
           
protected  long _testDelay
           
protected  boolean _testing
           
protected  java.util.Vector _workers
           
 
Constructor Summary
DevicePacketAggregator(NodeService node)
          Normal constructor when operating in SIAM
DevicePacketAggregator(java.lang.String directory, long delay)
          Test constructor, used by tests.Aggregator
 
Method Summary
 void exitWorkers()
          Tell all DevicePacketWorkers to exit
 DevicePacketSet getDevicePackets(long isiId, long startKey, long endKey, int numBytes, int timeout)
          Get a DevicePacketSet.
 DevicePacketSet getDevicePackets(long isiId, long startKey, long endKey, int numBytes, int typeMask, int timeout)
          Get a DevicePacketSet.
protected  DevicePacketAggregator.DevicePacketSource getDevicePacketSource(long deviceID)
          Creates a DevicePacketSource for this deviceID
protected  DevicePacketAggregator.DevicePacketWorker getWorker(long isiId)
          Find the DevicePacketWorker that is servicing this isiId.
 void serviceInstalled(ServiceEvent e)
          serviceInstalled method for the ServiceListener interface.
 void serviceRemoved(ServiceEvent e)
          serviceRemoved method for the ServiceListener interface.
 void serviceRequestComplete(ServiceEvent e)
          serviceRequestComplete method for the ServiceListener interface.
 void serviceSampleLogged(LogSampleServiceEvent e)
          serviceSampleLogged method for the ServiceListener interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log4j

protected static org.apache.log4j.Logger _log4j
Log4j logger


_workers

protected java.util.Vector _workers

_node

protected NodeService _node

_testing

protected boolean _testing

_directory

protected java.lang.String _directory

_testDelay

protected long _testDelay
Constructor Detail

DevicePacketAggregator

public DevicePacketAggregator(NodeService node)
Normal constructor when operating in SIAM


DevicePacketAggregator

public DevicePacketAggregator(java.lang.String directory,
                              long delay)
Test constructor, used by tests.Aggregator

Method Detail

getDevicePackets

public DevicePacketSet getDevicePackets(long isiId,
                                        long startKey,
                                        long endKey,
                                        int numBytes,
                                        int typeMask,
                                        int timeout)
                                 throws TimeoutException,
                                        java.lang.IllegalArgumentException,
                                        DeviceNotFound,
                                        NoDataException
Get a DevicePacketSet.

Parameters:
isiId - = Device id
startKey - = Earliest time (key) to request
endKey - = End time of request
numBytes - = Requested size of DevicePacketSet, in bytes
typeMask - = Mask to filter requested packets. See DevicePacket.
timeout - = timeout in milliseconds
Throws:
TimeoutException
java.lang.IllegalArgumentException
DeviceNotFound
NoDataException

getDevicePackets

public DevicePacketSet getDevicePackets(long isiId,
                                        long startKey,
                                        long endKey,
                                        int numBytes,
                                        int timeout)
                                 throws TimeoutException,
                                        java.lang.IllegalArgumentException,
                                        DeviceNotFound,
                                        NoDataException
Get a DevicePacketSet.

Parameters:
isiId - = Device id
startKey - = Earliest time (key) to request
endKey - = End time of request
numBytes - = Requested size of DevicePacketSet, in bytes
timeout - = timeout in milliseconds
Throws:
TimeoutException
java.lang.IllegalArgumentException
DeviceNotFound
NoDataException

getDevicePacketSource

protected DevicePacketAggregator.DevicePacketSource getDevicePacketSource(long deviceID)
                                                                   throws DeviceNotFound,
                                                                          NoDataException
Creates a DevicePacketSource for this deviceID

Throws:
DeviceNotFound
NoDataException

getWorker

protected DevicePacketAggregator.DevicePacketWorker getWorker(long isiId)
                                                       throws DeviceNotFound,
                                                              NoDataException
Find the DevicePacketWorker that is servicing this isiId. If none exists, create a new one.

Throws:
DeviceNotFound
NoDataException

exitWorkers

public void exitWorkers()
Tell all DevicePacketWorkers to exit


serviceInstalled

public void serviceInstalled(ServiceEvent e)
serviceInstalled method for the ServiceListener interface. Action performed when service installed. We ignore this event.

Specified by:
serviceInstalled in interface ServiceListener

serviceRemoved

public void serviceRemoved(ServiceEvent e)
serviceRemoved method for the ServiceListener interface. Action performed when service removed. We look for a DevicePacketWorker for the corresponding ISI ID, and shut it down if it exists.

Specified by:
serviceRemoved in interface ServiceListener

serviceRequestComplete

public void serviceRequestComplete(ServiceEvent e)
serviceRequestComplete method for the ServiceListener interface. Action performed when service installed. We ignore this event.

Specified by:
serviceRequestComplete in interface ServiceListener

serviceSampleLogged

public void serviceSampleLogged(LogSampleServiceEvent e)
serviceSampleLogged method for the ServiceListener interface. Action performed when service logs a device sample. We ignore this event.



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.