public abstract class Sensor extends java.lang.Thread implements StopableObject
SensorAdapter
.SensorAdapter
to be used in common with the reachability
project. It provides some ActiveMQ connection relevant methods, to extremely simplify the sensor adapter design.Modifier and Type | Field and Description |
---|---|
private long |
delay
Default delay time.
|
private ReasonerDimension |
internalDimension
The context dimension as
ReasonerDimension for which this sensor supplies data inputs. |
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher |
internalSensorDataTopic
The
LPPublisher , which publishes the generalized result set on the internal result topic
internalSensorDataTopicName . |
private java.lang.String |
internalSensorDataTopicName
The ActiveMQ topic name on which the
Sensor publishes its generalized data set for the reasoner. |
private java.util.Map<java.lang.String,java.lang.String> |
localConf
Local adapter configuration.
|
private java.util.Random |
rand
Local random number generator.
|
private java.lang.String |
registryRequestTopicName
The ActiveMQ topic name on which reachability systems registry service will send its registry invitations.
|
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher |
registryTopic
The
LPPublisher , which publishes register messages onto the systems registry register topic
registryTopicName . |
private java.lang.String |
registryTopicName
The ActiveMQ topic name on which clients send their registration messages to the systems registry service.
|
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPSubscriber |
requestRegistryTopic
The
LPSubscriber , which listens for register requests on the systems registry request topic
registryRequestTopicName . |
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher |
requestTopic
The
LPPublisher , which publishes requests to the sensors data source request topic
requestTopicName . |
private java.lang.String |
requestTopicName
The ActiveMQ topic name on which a request shall be send to the sensors data source.
|
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPSubscriber |
resultTopic
The
LPSubscriber , which receives results from the sensors data source result topic
resultTopicName . |
private java.lang.String |
resultTopicName
The ActiveMQ topic name on which the sensors data source provides its measured results.
|
private boolean |
shutDown
Determines if the method
shutDown() has been called. |
private boolean |
silent
Holds the activity state of this object.
|
private boolean |
stopped
Determines if the
Sensor has stopped. |
Modifier | Constructor and Description |
---|---|
protected |
Sensor(ReasonerDimension dimension)
Protected constructor ensures, that there will be no direct instance of this class.
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Connects the
Sensor to the topics via ActiveMQ, using the utility class ConnectionUtil . |
private void |
end()
Unregisters from systems registry service, disconnects all ActiveMQ topic connections and sets
stopped
to true . |
ReasonerDimension |
getDataDimension()
Provides the context dimension of the
Sensor s data as ReasonerDimension . |
private JsonReachabilitySensorData |
getDataMessage(SensorData so)
Creates a new
JsonReachabilitySensorData message based on a supplied SensorData . |
java.lang.String |
getID()
Returns the ID of this
Sensor . |
protected java.lang.String |
getLocalConf(java.lang.String key)
Returns the value of the supplied local adapter parameter key if exiting, otherwise
null . |
protected de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher |
getRequestTopic()
Returns the current
LPPublisher object, which is connected to the internally defined request topic of
this Sensor s data source. |
java.lang.String |
getRequestTopicName()
Provides the name of the request topic for ActiveMQ communication, if this
Sensor is connect to its data
source via ActiveMQ. |
protected de.hawhamburg.livingplace.messaging.activemq.wrapper.LPSubscriber |
getResultTopic()
Returns the current
LPSubscriber object, which is connected to the internally defined result topic of
this Sensor s data source. |
java.lang.String |
getResultTopicName()
Provides the name of the result topic for ActiveMQ communication, if this
Sensor is connect to its data
source via ActiveMQ. |
abstract SensorData |
getSensorOutput()
Provides the current
SensorData and null if none exists. |
protected java.lang.String |
getVersion()
Returns the version of this
Sensor . |
private void |
handleRegisterRequestMessage()
Checks for new registry invitations from the systems registry service and sends register message if there's
some by using
sendRegistryMessage(RegistryMessageType) with RegistryMessageType.REGISTER . |
boolean |
isActive()
Determines whether the method
StopableObject.shutDown() has been called on this object or not. |
protected boolean |
isSilent()
Determines if the
Sensor s running mode is silent. |
protected void |
loadDefaultsFromXMLResource()
Loads the sensors local configuration from its XML configuration file.
|
void |
run()
Main run method.
|
private void |
sendInitialRegisterMessage()
Sends an initial register message by using
sendRegistryMessage(RegistryMessageType) with
RegistryMessageType.REGISTER . |
private void |
sendInternalSensorData(SensorData so)
Sends the measured
SensorData as common internal representation onto the internal data exchange topic
internalSensorDataTopicName , if this Sensor dosn't run in silent mode (isSilent() ). |
private void |
sendRegistryMessage(RegistryMessageType type)
Creates and sends a new
JsonRARegistryMessage onto the registryTopic . |
protected void |
setDelay(long newDelay)
Updates or sets the internal delay time to a new value.
|
protected void |
setLocalConf(java.lang.String key,
java.lang.String value)
Set a local adapter configuration parameter key to value.
|
protected void |
setRequestTopicName(java.lang.String newTopicName)
Updates or sets the internal request topic name to a new value.
|
protected void |
setResultTopicName(java.lang.String newTopicName)
Updates or sets the internal result topic name to a new value.
|
void |
setSilent(boolean state)
Sets the silent state.
|
void |
shutDown()
Shuts the object down.
|
boolean |
stopped()
Determines if the
Sensor has stopped. |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
private boolean silent
true
, the worker won't publish its results on
the result topic.private java.lang.String requestTopicName
private java.lang.String resultTopicName
private java.lang.String internalSensorDataTopicName
Sensor
publishes its generalized data set for the reasoner.private java.lang.String registryRequestTopicName
private java.lang.String registryTopicName
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher requestTopic
LPPublisher
, which publishes requests to the sensors data source request topic
requestTopicName
.private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPSubscriber resultTopic
LPSubscriber
, which receives results from the sensors data source result topic
resultTopicName
.private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher internalSensorDataTopic
LPPublisher
, which publishes the generalized result set on the internal result topic
internalSensorDataTopicName
.private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPSubscriber requestRegistryTopic
LPSubscriber
, which listens for register requests on the systems registry request topic
registryRequestTopicName
.private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher registryTopic
LPPublisher
, which publishes register messages onto the systems registry register topic
registryTopicName
.private ReasonerDimension internalDimension
ReasonerDimension
for which this sensor supplies data inputs.private boolean shutDown
shutDown()
has been called.private long delay
private java.util.Random rand
private java.util.Map<java.lang.String,java.lang.String> localConf
private boolean stopped
Sensor
has stopped.protected Sensor(ReasonerDimension dimension)
dimension
- The ReasonerDimension
for which this sensor is configured.public final void connect()
Sensor
to the topics via ActiveMQ, using the utility class ConnectionUtil
.public final void setSilent(boolean state)
true
, the Sensor
won't publish his informations
onto the internal result topic for the reasoner.state
- The current state of silence as Boolean
.protected final boolean isSilent()
Sensor
s running mode is silent.Boolean
.public final boolean isActive()
StopableObject
StopableObject.shutDown()
has been called on this object or not.isActive
in interface StopableObject
true
if shutDown()
wasn't called, otherwise false
.StopableObject.isActive()
public final boolean stopped()
Sensor
has stopped.true
if Sensor
has stopped, otherwise false
.public final void shutDown()
StopableObject
shutDown
in interface StopableObject
StopableObject.shutDown()
public final java.lang.String getRequestTopicName()
Sensor
is connect to its data
source via ActiveMQ.Sensor
s data source if its connected via ActiveMQ,
otherwise null
.public final java.lang.String getResultTopicName()
Sensor
is connect to its data
source via ActiveMQ.Sensor
s data source if its connected via ActiveMQ,
otherwise null
.public final ReasonerDimension getDataDimension()
Sensor
s data as ReasonerDimension
.ReasonerDimension
of the Sensor
.public abstract SensorData getSensorOutput()
SensorData
and null
if none exists.SensorData
object on success, otherwise null
.public final void run()
sendInitialRegisterMessage()
and frequently does:
handleRegisterRequestMessage()
Sensor
s data source by using getSensorOutput()
sendInternalSensorData(SensorData)
isActive()
. Afterwards cleaning up all resources by using end()
.run
in interface java.lang.Runnable
run
in class java.lang.Thread
private void end()
stopped
to true
.private void sendInitialRegisterMessage()
sendRegistryMessage(RegistryMessageType)
with
RegistryMessageType.REGISTER
.private void handleRegisterRequestMessage()
sendRegistryMessage(RegistryMessageType)
with RegistryMessageType.REGISTER
.private void sendRegistryMessage(RegistryMessageType type)
JsonRARegistryMessage
onto the registryTopic
. This may register or
unregister this Sensor
due to the supplied RegistryMessageType
.type
- The RegistryMessageType
which indicates if the Sensor
shall be registered or
unregistered from the systems registry service.protected final void setRequestTopicName(java.lang.String newTopicName)
newTopicName
- The new name of the request topic as String
.protected final void setResultTopicName(java.lang.String newTopicName)
newTopicName
- The new name of the result topic as String
.protected final void setDelay(long newDelay)
newDelay
- The new delay time as long
representing milliseconds.protected final void setLocalConf(java.lang.String key, java.lang.String value)
key
- The key of the local adapter parameter as String
.value
- The (new) value of the local adapter parameter as String
.protected final java.lang.String getLocalConf(java.lang.String key)
null
.key
- The local adapter parameter key as String
.String
if existing, otherwise
null
.protected final de.hawhamburg.livingplace.messaging.activemq.wrapper.LPSubscriber getResultTopic()
LPSubscriber
object, which is connected to the internally defined result topic of
this Sensor
s data source.LPSubscriber
object which is connected to the result topic.protected final de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher getRequestTopic()
LPPublisher
object, which is connected to the internally defined request topic of
this Sensor
s data source.LPPublisher
object which is connected to the request topic.protected final void loadDefaultsFromXMLResource()
Settings.SENSOR_CONFIGURATION_PATH
and be named like the adapters simple class name.
Settings.SENSOR_RESULT_TOPIC_XPATH
Settings.SENSOR_RESULT_TOPIC_XPATH
Settings.SENSOR_RESULT_TOPIC_XPATH
Settings.SENSOR_LOCAL_CONF_XPATH
.private void sendInternalSensorData(SensorData so)
SensorData
as common internal representation onto the internal data exchange topic
internalSensorDataTopicName
, if this Sensor
dosn't run in silent mode (isSilent()
).so
- The measured data as SensorData
object.private JsonReachabilitySensorData getDataMessage(SensorData so)
JsonReachabilitySensorData
message based on a supplied SensorData
.so
- The measured data as SensorData
.JsonReachabilitySensorData
message based on the supplied SensorData
.public final java.lang.String getID()
Sensor
.Sensor
as String
.