org.mbari.siam.core
Class DeviceService

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by org.mbari.siam.core.DeviceService
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, Device, DeviceServiceIF
Direct Known Subclasses:
BaseInstrumentService, InstrumentService

public abstract class DeviceService
extends java.rmi.server.UnicastRemoteObject
implements Device, DeviceServiceIF

DeviceService implements the Device interface.

Author:
Tom O'Reilly
See Also:
Serialized Form

Field Summary
protected  SiamBufferedInputStream _fromDevice
          InputStream from instrument
protected  InstrumentPort _instrumentPort
          Device instrument port (power and comms)
protected static org.apache.log4j.Logger _log4j
          Log4j logger
protected  NodeProperties _nodeProperties
          Reference to host node properties.
protected  Parent _parentNode
          Reference to parent node
protected  RegistryEntry _regEntry
          Our RegistryEntry for InstrumentRegistry
protected  ServiceSandBox _sandBox
          Service 'sandbox' on node file system
protected  java.lang.String _serviceCachePath
          Path to service state cache metadata
protected  java.lang.String _serviceName
          String representation of service name; use this for debugging purposes, to avoid excessive string construction
protected  java.lang.String _servicePropertiesPath
          Path to service properties file
protected  java.lang.String _serviceXMLPath
          Path to service XML metadata
protected  InstrumentPortOutputStream _toDevice
          OutputStream to instrument
static java.lang.String CACHED_PROPERTIES_FILENAME
           
static java.lang.String PROPERTIES_FILENAME
           
static java.lang.String XML_FILENAME
           
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface org.mbari.siam.distributed.Device
ERROR, INITIAL, INSTRUMENT_STATE, MDATA_ALL, OK, SAFE, SAMPLING, SERVICE_ATTRIBUTES, SERVICE_CACHE, SERVICE_PROPERTIES, SERVICE_XML, SHUTDOWN, SLEEPING, SUSPEND, UNKNOWN
 
Constructor Summary
DeviceService()
          Constructor.
 
Method Summary
 void addDataListener(InstrumentDataListener listener)
          Add an InstrumentDataListener
protected  void advertiseService()
          Advertise service on network
protected  void createRegistryEntry()
          Create a RegistryEntry for the InstrumentRegistry
 ServiceAttributes getAttributes()
          Return service's attributes object.
 byte[] getCommPortName()
          Returns name of host port.
 byte[] getFrameworkVersion()
          Return byte-string that specifies the SIAM framework version.
 long getId()
          Unique identifier for device instance
 InstrumentPort getInstrumentPort()
          Returns a reference to the instrument port.
 Location getLocation()
          Return Location of device.
abstract  MetadataPacket getMetadata(byte[] cause, int components, boolean logPacket)
          Get device metadata packet.
 byte[] getName()
          Returns name of driver class.
 RemoteSerialPort getRemoteSerialPort()
          Return remote serial port to client.
 RemoteSerialPort getRemoteSerialPort(int timeout)
          Return remote serial port to client.
 int getSamplingCount()
          return sample count
 int getSamplingErrorCount()
          return sampling error count
 int getSamplingRetryCount()
           
 SerialPortParameters getSerialPortParameters()
          Subclass should return serial port parameters to use on port.
 int getStatus()
          Return instrument service status.
 java.net.InetAddress host()
          Return InetAddress of device service host.
protected  void incRetryCount()
           
 void initialize(NodeProperties nodeProperties, Parent parent, InstrumentPort port, ServiceSandBox sandBox, java.lang.String serviceXMLPath, java.lang.String servicePropertiesPath, java.lang.String cachedServicePath)
          Initialize the service.
 void initializePropertyDefaults()
          Set (hard coded) property defaults ()
protected  void managePowerSleep()
          Put device power into quiescent state
protected  void managePowerWake()
          Put device power into active state
 void prepareToRun()
          Initialize driver and instrument.
 RegistryEntry registryEntry()
          Return service's RegistryEntry
 java.lang.String registryName()
          Return service's registry name
 void removeDataListener(InstrumentDataListener listener)
          Remove an InstrumentDataListener
 void resume()
          Put service in OK state.
 void setAttributes(ServiceAttributes attributes)
          Set the ServiceAttributes object for this service.
 void setInstrumentPort(InstrumentPort port)
          Set the instrument port.
 void setNodeProperties(NodeProperties nodeProperties)
          Set reference to host node properties.
 void setParent(Parent parent)
          Set parent node
 void setSerialPort()
          Set serial parameters if the InsrumentPort is a SerialInsrumentPort
protected  void setStatusError()
          Set service status to Device.ERROR.
protected  void setStatusInitial()
          Set service status to Device.INITIALIZING.
protected  void setStatusOk()
          Set service status to Device.OK.
 void setStatusSafe()
          Set service status to Device.SAFE.
protected  void setStatusSampling()
          Set service status to Device.SAMPLING.
protected  void setStatusShutdown()
          Set service status to Device.SHUTDOWN
protected  void setStatusSuspend()
          Set service status to Device.SUSPEND.
 byte[] shutdown()
          Stop the service.
 void suspend()
          Put service in SUSPEND state.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mbari.siam.distributed.Device
getChildren, getParent, powerOff, powerOn, test
 

Field Detail

_log4j

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


XML_FILENAME

public static final java.lang.String XML_FILENAME
See Also:
Constant Field Values

PROPERTIES_FILENAME

public static final java.lang.String PROPERTIES_FILENAME
See Also:
Constant Field Values

CACHED_PROPERTIES_FILENAME

public static final java.lang.String CACHED_PROPERTIES_FILENAME
See Also:
Constant Field Values

_parentNode

protected Parent _parentNode
Reference to parent node


_nodeProperties

protected NodeProperties _nodeProperties
Reference to host node properties.


_instrumentPort

protected InstrumentPort _instrumentPort
Device instrument port (power and comms)


_fromDevice

protected SiamBufferedInputStream _fromDevice
InputStream from instrument


_toDevice

protected InstrumentPortOutputStream _toDevice
OutputStream to instrument


_serviceXMLPath

protected java.lang.String _serviceXMLPath
Path to service XML metadata


_serviceCachePath

protected java.lang.String _serviceCachePath
Path to service state cache metadata


_servicePropertiesPath

protected java.lang.String _servicePropertiesPath
Path to service properties file


_sandBox

protected ServiceSandBox _sandBox
Service 'sandbox' on node file system


_regEntry

protected RegistryEntry _regEntry
Our RegistryEntry for InstrumentRegistry


_serviceName

protected java.lang.String _serviceName
String representation of service name; use this for debugging purposes, to avoid excessive string construction

Constructor Detail

DeviceService

public DeviceService()
              throws java.rmi.RemoteException
Constructor. Need no-argument constructor so class can be instantiated via loader.

Throws:
java.rmi.RemoteException
Method Detail

getId

public long getId()
Unique identifier for device instance

Specified by:
getId in interface Device

setParent

public void setParent(Parent parent)
Set parent node


getName

public final byte[] getName()
Returns name of driver class.

Specified by:
getName in interface Device
Specified by:
getName in interface DeviceServiceIF

getCommPortName

public byte[] getCommPortName()
Returns name of host port.

Specified by:
getCommPortName in interface Device

getRemoteSerialPort

public RemoteSerialPort getRemoteSerialPort()
                                     throws java.io.IOException,
                                            java.net.UnknownHostException
Return remote serial port to client.

Throws:
java.io.IOException
java.net.UnknownHostException

getRemoteSerialPort

public RemoteSerialPort getRemoteSerialPort(int timeout)
                                     throws java.io.IOException,
                                            RangeException,
                                            java.net.UnknownHostException
Return remote serial port to client.

Throws:
java.io.IOException
RangeException
java.net.UnknownHostException

getInstrumentPort

public InstrumentPort getInstrumentPort()
Returns a reference to the instrument port.


host

public java.net.InetAddress host()
                          throws java.net.UnknownHostException
Return InetAddress of device service host.

Specified by:
host in interface Device
Throws:
java.net.UnknownHostException

initialize

public void initialize(NodeProperties nodeProperties,
                       Parent parent,
                       InstrumentPort port,
                       ServiceSandBox sandBox,
                       java.lang.String serviceXMLPath,
                       java.lang.String servicePropertiesPath,
                       java.lang.String cachedServicePath)
                throws MissingPropertyException,
                       InvalidPropertyException,
                       PropertyException,
                       InitializeException,
                       java.io.IOException,
                       gnu.io.UnsupportedCommOperationException
Initialize the service.

Throws:
MissingPropertyException
InvalidPropertyException
PropertyException
InitializeException
java.io.IOException
gnu.io.UnsupportedCommOperationException

shutdown

public byte[] shutdown()
Stop the service.

Specified by:
shutdown in interface Device

setSerialPort

public void setSerialPort()
                   throws java.io.IOException,
                          gnu.io.UnsupportedCommOperationException
Set serial parameters if the InsrumentPort is a SerialInsrumentPort

Throws:
java.io.IOException
gnu.io.UnsupportedCommOperationException

setInstrumentPort

public void setInstrumentPort(InstrumentPort port)
Set the instrument port. (Called at startup.)

Parameters:
port - instrument port to be assigned to driver

suspend

public void suspend()
Put service in SUSPEND state. Release resources (e.g. serial port) for use by other applications. Note that this method should NOT be be synchronized, so that a sampling thread can be interrupted.

Specified by:
suspend in interface Device

resume

public void resume()
Put service in OK state. Re-acquire resources (e.g. serial port).

Specified by:
resume in interface Device

getStatus

public int getStatus()
Return instrument service status.

Specified by:
getStatus in interface Device

getSamplingErrorCount

public int getSamplingErrorCount()
return sampling error count

Specified by:
getSamplingErrorCount in interface Device

getSamplingCount

public int getSamplingCount()
return sample count

Specified by:
getSamplingCount in interface Device

getSamplingRetryCount

public int getSamplingRetryCount()
Specified by:
getSamplingRetryCount in interface Device

setStatusError

protected final void setStatusError()
Set service status to Device.ERROR.


incRetryCount

protected final void incRetryCount()

setStatusShutdown

protected final void setStatusShutdown()
Set service status to Device.SHUTDOWN


setStatusInitial

protected final void setStatusInitial()
Set service status to Device.INITIALIZING.


setStatusOk

protected final void setStatusOk()
Set service status to Device.OK.


setStatusSampling

protected final void setStatusSampling()
Set service status to Device.SAMPLING.


setStatusSuspend

protected final void setStatusSuspend()
Set service status to Device.SUSPEND.


setStatusSafe

public final void setStatusSafe()
Set service status to Device.SAFE.


managePowerWake

protected void managePowerWake()
Put device power into active state


managePowerSleep

protected void managePowerSleep()
Put device power into quiescent state


getSerialPortParameters

public SerialPortParameters getSerialPortParameters()
                                             throws gnu.io.UnsupportedCommOperationException
Subclass should return serial port parameters to use on port.

Throws:
gnu.io.UnsupportedCommOperationException

getMetadata

public abstract MetadataPacket getMetadata(byte[] cause,
                                           int components,
                                           boolean logPacket)
                                    throws java.rmi.RemoteException
Get device metadata packet.

Specified by:
getMetadata in interface Device
Throws:
java.rmi.RemoteException

initializePropertyDefaults

public void initializePropertyDefaults()
                                throws InitializeException
Set (hard coded) property defaults ()

Throws:
InitializeException

setNodeProperties

public void setNodeProperties(NodeProperties nodeProperties)
                       throws MissingPropertyException,
                              InvalidPropertyException
Set reference to host node properties.

Throws:
MissingPropertyException
InvalidPropertyException

prepareToRun

public void prepareToRun()
                  throws InitializeException,
                         java.lang.InterruptedException
Initialize driver and instrument. This method must be invoked by outside entity before data acquisition starts.

Specified by:
prepareToRun in interface Device
Throws:
InitializeException
java.lang.InterruptedException

setAttributes

public void setAttributes(ServiceAttributes attributes)
Set the ServiceAttributes object for this service.

Specified by:
setAttributes in interface DeviceServiceIF

createRegistryEntry

protected void createRegistryEntry()
Create a RegistryEntry for the InstrumentRegistry


getFrameworkVersion

public byte[] getFrameworkVersion()
Return byte-string that specifies the SIAM framework version.

Specified by:
getFrameworkVersion in interface Device

registryName

public java.lang.String registryName()
Return service's registry name


registryEntry

public RegistryEntry registryEntry()
Return service's RegistryEntry


addDataListener

public void addDataListener(InstrumentDataListener listener)
Add an InstrumentDataListener


removeDataListener

public void removeDataListener(InstrumentDataListener listener)
Remove an InstrumentDataListener


getAttributes

public ServiceAttributes getAttributes()
Return service's attributes object.


getLocation

public Location getLocation()
                     throws UnknownLocationException
Return Location of device. NOT YET IMPLEMENTED.

Specified by:
getLocation in interface Device
Throws:
UnknownLocationException

advertiseService

protected void advertiseService()
Advertise service on network



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.