org.glite.ce.monitorapij.sensor
Class AbstractSensor

java.lang.Object
  extended byorg.glite.ce.monitorapij.types.CEMonResourceBase
      extended byorg.glite.ce.monitorapij.types.CEMonResource
          extended byorg.glite.ce.monitorapij.sensor.AbstractSensor
All Implemented Interfaces:
MonitorListener, Resource, java.lang.Runnable, Sensor, java.io.Serializable

public abstract class AbstractSensor
extends CEMonResource
implements java.lang.Runnable, Resource, Sensor, MonitorListener

Base abstract class which must be extended by all sensor plugins. It extends CEMonResource and implements interfaces Runnable, Resource, Sensor and MonitorListener. It provides methods to control the sensor execution and to manage the SensorListeners and supported formats.

Author:
Luigi Zangrando (zangrando@pd.infn.it)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.glite.ce.monitorapij.types.CEMonResource
creationTime, newResource
 
Constructor Summary
AbstractSensor()
          Create a new AbstractSensor object named "CE Sensor" and of type "Sensor".
AbstractSensor(java.lang.String name, java.lang.String type)
          Create a new AbstractSensor object.
 
Method Summary
 void addFormat(SensorOutputDataFormat format)
          Add a format to the ArrayList of supported formats.
 void addSensorListener(SensorListener l)
          Add a SensorListener to the sensor.
 void destroySensor()
          Not yet implemented.
 void doOnMonitorEvent(MonitorEvent mEvt)
          Specify the things to do when a MonitorEvent occurs.
protected  void fireSensorEvent(SensorEvent event)
          Notify all listeners that have registered interest for notification on this event type.
 SensorOutputDataFormat getDefaultFormat()
          Get the default format if previously set or the first saved supported format.
 SensorOutputDataFormat getFormat(java.lang.String format)
          Get the SensorOutputDataFormat named as specified if it is supported.
 SensorOutputDataFormat[] getFormats()
          Get all the supported formats.
 SensorListener[] getSensorListeners()
          Get an array of all the SensorListeners added to this AbstractSensor with addSensorListener().
 void init()
          Initialize the Sensor.
 boolean isFormatSupported(SensorOutputDataFormat sensorOutputDataFormat)
          Check if the specified SensorOutputDataFormat is supported.
 boolean isFormatSupported(java.lang.String format)
          Check if the SensorOutputDataFormat named as specified is supported.
 void removeFormat(SensorOutputDataFormat format)
          Remove the specified format.
 void removeSensorListener(SensorListener l)
          Remove a SensorListener from the sensor.
 void resumeSensor()
          Resumes the execution of the Sensor.
 void run()
          Launch the execute() method of Sensor thread each executionDelay time interval.
 void setDefaultFormat(SensorOutputDataFormat format)
          Set the default format.
 void startSensor()
          Start the execution of the Sensor intended as a Thread if the Property executionDelay has been defined.
 void suspendSensor()
          Suspend the execution of the Sensor.
 
Methods inherited from class org.glite.ce.monitorapij.types.CEMonResource
exists, getCreationTime, getProperty, isNew, lastModified, removeHiddenProperties, setCreationTime, setId, setNew
 
Methods inherited from class org.glite.ce.monitorapij.types.CEMonResourceBase
equals, getDeserializer, getId, getJarPath, getName, getProperty, getProperty, getSerializer, getType, getTypeDesc, hashCode, setId, setJarPath, setName, setProperty, setProperty, setType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.glite.ce.monitorapij.resource.Resource
exists, getCreationTime, getId, getJarPath, getName, getProperty, getProperty, getProperty, getType, isNew, lastModified, setCreationTime, setId, setId, setJarPath, setName, setNew, setProperty, setProperty, setType
 
Methods inherited from interface org.glite.ce.monitorapij.sensor.Sensor
execute, getName, getType
 

Constructor Detail

AbstractSensor

public AbstractSensor()
Create a new AbstractSensor object named "CE Sensor" and of type "Sensor".


AbstractSensor

public AbstractSensor(java.lang.String name,
                      java.lang.String type)
Create a new AbstractSensor object.

Parameters:
name - The name of AbstractSensor
type - The type of AbstractSensor
Method Detail

getFormat

public SensorOutputDataFormat getFormat(java.lang.String format)
Get the SensorOutputDataFormat named as specified if it is supported.

Specified by:
getFormat in interface Sensor
Parameters:
format - The name of the searched format.
Returns:
The searched SensorOutputDataFormat if this is supported, null otherwise.
See Also:
Sensor.getFormat(java.lang.String)

getFormats

public SensorOutputDataFormat[] getFormats()
Get all the supported formats.

Specified by:
getFormats in interface Sensor
Returns:
An array of SensorOutputDataFormat representing the all supported formats.
See Also:
Sensor.getFormats()

setDefaultFormat

public void setDefaultFormat(SensorOutputDataFormat format)
Set the default format.

Specified by:
setDefaultFormat in interface Sensor
Parameters:
format - The SensorOutputDataFormat to be set as default. This must be not null and supported.
See Also:
Sensor.setDefaultFormat(org.glite.ce.monitorapij.sensor.SensorOutputDataFormat)

getDefaultFormat

public SensorOutputDataFormat getDefaultFormat()
Get the default format if previously set or the first saved supported format.

Specified by:
getDefaultFormat in interface Sensor
Returns:
The SensorOutputDataFormat which is the default format

addFormat

public void addFormat(SensorOutputDataFormat format)
Add a format to the ArrayList of supported formats. Do nothing if the format has already been added.

Specified by:
addFormat in interface Sensor
Parameters:
format - The SensorOutputDataFormat to add

removeFormat

public void removeFormat(SensorOutputDataFormat format)
Remove the specified format. If this is the default format, the first saved format will be set as new default format.

Specified by:
removeFormat in interface Sensor
Parameters:
format - the SensorOutputDataFormat to be removed
See Also:
Sensor.removeFormat(org.glite.ce.monitorapij.sensor.SensorOutputDataFormat)

isFormatSupported

public boolean isFormatSupported(SensorOutputDataFormat sensorOutputDataFormat)
Check if the specified SensorOutputDataFormat is supported.

Specified by:
isFormatSupported in interface Sensor
Parameters:
sensorOutputDataFormat - The SensorOutputDataFormat to check.
Returns:
A boolean: true if the specified format is supported, false otherwise.
See Also:
isFormatSupported(java.lang.String), Sensor.isFormatSupported(org.glite.ce.monitorapij.sensor.SensorOutputDataFormat)

isFormatSupported

public boolean isFormatSupported(java.lang.String format)
Check if the SensorOutputDataFormat named as specified is supported.

Specified by:
isFormatSupported in interface Sensor
Parameters:
format - The name of the SensorOutputDataFormat to be checked.
Returns:
A boolean representing the response.
See Also:
Sensor.isFormatSupported(java.lang.String)

getSensorListeners

public SensorListener[] getSensorListeners()
Get an array of all the SensorListeners added to this AbstractSensor with addSensorListener().

Specified by:
getSensorListeners in interface Sensor
Returns:
All of the SensorListeners added or an empty array if no listeners have been added.

addSensorListener

public void addSensorListener(SensorListener l)
Add a SensorListener to the sensor.

Specified by:
addSensorListener in interface Sensor
Parameters:
l - The SensorListener to be added.

removeSensorListener

public void removeSensorListener(SensorListener l)
Remove a SensorListener from the sensor.

Specified by:
removeSensorListener in interface Sensor
Parameters:
l - The listener to be removed.

fireSensorEvent

protected void fireSensorEvent(SensorEvent event)
Notify all listeners that have registered interest for notification on this event type. The event instance is created using the event parameter.

Parameters:
event - The SensorEvent object.

init

public void init()
          throws SensorException
Initialize the Sensor.

Specified by:
init in interface Sensor
Throws:
SensorException - thrown if something gone wrong during initialization.

startSensor

public void startSensor()
Start the execution of the Sensor intended as a Thread if the Property executionDelay has been defined. Otherwise log a warning "executionDelay property not found!".

Specified by:
startSensor in interface Sensor
See Also:
Sensor.startSensor()

suspendSensor

public void suspendSensor()
Suspend the execution of the Sensor.

Specified by:
suspendSensor in interface Sensor
See Also:
Sensor.suspendSensor()

resumeSensor

public void resumeSensor()
Resumes the execution of the Sensor.

Specified by:
resumeSensor in interface Sensor
See Also:
Sensor.resumeSensor()

destroySensor

public void destroySensor()
Not yet implemented. By now this method just suspends the Sensor without destroying it

Specified by:
destroySensor in interface Sensor
See Also:
Sensor.destroySensor()

run

public void run()
Launch the execute() method of Sensor thread each executionDelay time interval.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

doOnMonitorEvent

public void doOnMonitorEvent(MonitorEvent mEvt)
Specify the things to do when a MonitorEvent occurs.

Specified by:
doOnMonitorEvent in interface MonitorListener
Parameters:
mEvt - The MonitorEvent events the listener is interested in.
See Also:
MonitorListener.doOnMonitorEvent(org.glite.ce.monitorapij.sensor.MonitorEvent)