public class SensorDataFeeder extends java.lang.Thread implements StopableObject
Modifier and Type | Field and Description |
---|---|
static boolean |
FEEDER_HEARTBEAT
The default instruction to send the actual simulation time each simulation minute as time sensor event.
|
static boolean |
FEEDER_SILENT
The default instruction to write informations to console/logfile.
|
static int |
FEEDER_SPEED
The default simulation speed in simulation minutes per real-time minute.
|
static int |
FEEDER_WAIT
The default waiting time before simulation starts in milliseconds.
|
private java.lang.String |
file
The actual name of the file that contains the story which shall be simulated.
|
private boolean |
heartbeat
The actual instruction to send the actual simulation time each simulation minute as time sensor event.
|
private java.util.SortedMap<SensorDataFeederItem,java.lang.String> |
log
The actual list of sent
SensorDataFeederItem . |
private java.util.List<SensorDataFeederNotifiable> |
notifiable
The list of threads, which shall be notified at change and simulation end.
|
private java.util.Map<java.lang.String,de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher> |
outTopics
The actual opened output topics on the ActiveMQ as
Map of sensor name to LPPublisher . |
private java.lang.String |
path
The actual path to the directory of the simulation files.
|
private boolean |
shutDown
Determines if the method
shutDown() has been called. |
private boolean |
silent
Determines if this service shall print out debug output or not.
|
private int |
speed
The actual simulation speed in simulation minutes per real-time minute.
|
private java.util.Map<java.lang.Integer,SensorDataFeederItem> |
story
|
static java.lang.String |
TEST_FILE
The default name of the file that contains the story which shall be simulated.
|
static java.lang.String |
TEST_PATH
The default path to the directory of the simulation files.
|
static java.lang.String |
TOPIC_ROOT
The default prefix for simulated sensor result topics on the ActiveMQ.
|
private java.lang.String |
topicRoot
The actual prefix for simulated sensor result topics on the ActiveMQ.
|
private int |
wait
The actual delay time in milliseconds before the simulation shall start.
|
Constructor and Description |
---|
SensorDataFeeder(java.lang.String[] args)
Initializes a new
SensorDataFeeder object with supplied command line arguments. |
SensorDataFeeder(java.lang.String basepath,
java.lang.String topicRootIn,
int speedIn,
int waitIn,
boolean sendHeartbeat,
boolean beQuite)
Initializes a new
SensorDataFeeder object. |
Modifier and Type | Method and Description |
---|---|
void |
addNotifiable(SensorDataFeederNotifiable object)
Adds a new thread which shall be notified if this simulation feeder stops.
|
private void |
end()
Gracefully end the thread by disconnecting all open
LPPublisher and notifying all registered
SensorDataFeederNotifiable objects. |
java.lang.String |
getFile()
Return the actual simulation files name.
|
java.util.SortedMap<SensorDataFeederItem,java.lang.String> |
getLog()
Returns the log of sent simulation events as list of
SensorDataFeederItem . |
java.lang.String |
getPath()
Returns the path where the simulation file is located.
|
int |
getSpeed()
Returns the actual simulation speed in simulation minutes per real-time minute.
|
java.util.Map<java.lang.Integer,SensorDataFeederItem> |
getStory()
Returns the whole actual simulation story as list of
SensorDataFeederItem . |
private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher |
getTopic(java.lang.String type)
Creates and returns a new
LPPublisher object which holds an open ActiveMQ topic connection named as
"topicRoot +[SENSOR_TYPE_NAME]". |
java.lang.String |
getTopicRoot()
Returns the actual ActiveMQ topic prefix.
|
boolean |
isActive()
Determines whether the method
StopableObject.shutDown() has been called on this object or not. |
boolean |
isSilent()
Determines whether the simulation runs in silent mode or not.
|
private java.util.Map<java.lang.Integer,SensorDataFeederItem> |
loadStory(java.lang.String storyFilePath)
Loads and returns a story from a defined story file by using
SensorDataFeederItem.fromFile(String) . |
static void |
main(java.lang.String[] args)
Main method to start the sensor data feeder as stand-alone thread.
|
void |
run()
Starts the simulation.
|
private void |
sendData(SensorDataFeederItem item)
Sends a new
SensorDataFeederItem as JSON-object via the ActiveMQ. |
boolean |
sendsHeartbeats()
Determines whether the simulation sends the actual simulation time as simulated time sensor each minute or not.
|
void |
shutDown()
Shuts the object down.
|
private void |
simulateTime(int last,
int next,
int speedIn)
Let the thread sleep, until the next sensor event shall be published onto the ActiveMQ.
|
void |
unregisterNotifiable(SensorDataFeederNotifiable object)
Unregisters a thread form the list of threats that shall be notified if the simulation feeder stops.
|
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
public static final java.lang.String TOPIC_ROOT
public static final java.lang.String TEST_PATH
public static final java.lang.String TEST_FILE
public static final int FEEDER_SPEED
public static final int FEEDER_WAIT
public static final boolean FEEDER_HEARTBEAT
public static final boolean FEEDER_SILENT
private java.lang.String topicRoot
private java.lang.String path
private java.lang.String file
private int speed
private int wait
private boolean heartbeat
private boolean silent
private java.util.Map<java.lang.String,de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher> outTopics
Map
of sensor name to LPPublisher
.private boolean shutDown
shutDown()
has been called.private java.util.List<SensorDataFeederNotifiable> notifiable
private java.util.SortedMap<SensorDataFeederItem,java.lang.String> log
SensorDataFeederItem
.private java.util.Map<java.lang.Integer,SensorDataFeederItem> story
public SensorDataFeeder(java.lang.String[] args)
SensorDataFeeder
object with supplied command line arguments.--storyfile | Name of the used story file |
(Defaults to TEST_FILE ) |
|
--storypath | Path to the used story file |
(Defaults to TEST_PATH ) |
|
--feederwait | Delay time before start in milliseconds |
--feederchannelroot | Default AMQ topic prefix |
(Defaults to TOPIC_ROOT ) |
|
--feederspeed | Speed of simulation in simulation minutes per real minute |
(Defaults to FEEDER_SPEED ) |
|
--feederheartbeat | Instruction to send the actual simulation time each simulation minute as time sensor event. |
(Defaults to FEEDER_HEARTBEAT ) |
|
--feedersilent | Determines if this service shall print out debug output or not. |
(Defaults to FEEDER_SILENT ) |
|
--wrapped | Informs the systems it wasn't started as stand-alone service and forces it to be silent. |
args
- The command line arguments (see method description for usage).public SensorDataFeeder(java.lang.String basepath, java.lang.String topicRootIn, int speedIn, int waitIn, boolean sendHeartbeat, boolean beQuite)
SensorDataFeeder
object.basepath
- The path to the simulation story file as String
.topicRootIn
- The prefix of ActiveMQ topics for simulated sensor event output as
String
.speedIn
- The in simulation minutes per real-time minute as int
.waitIn
- The delay in milliseconds before the simulation starts as
int
.sendHeartbeat
- The instruction to send a frequently heartbeat including the
simulation time or not as boolean
.beQuite
- Indicates if this simulation shall run in silent mode or not.private java.util.Map<java.lang.Integer,SensorDataFeederItem> loadStory(java.lang.String storyFilePath)
SensorDataFeederItem.fromFile(String)
.storyFilePath
- The path to the file that contains the story which shall be loaded.Map
of simulation time minute (Integer
) to
SensorDataFeederItem
object.public final void addNotifiable(SensorDataFeederNotifiable object)
object
- The thread which shall be notified as SensorDataFeederNotifiable
.public final void unregisterNotifiable(SensorDataFeederNotifiable object)
object
- The thread which shall be unregistered of the list of notifiables.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 void shutDown()
StopableObject
shutDown
in interface StopableObject
StopableObject.shutDown()
public final void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
private void end()
LPPublisher
and notifying all registered
SensorDataFeederNotifiable
objects.private void sendData(SensorDataFeederItem item)
SensorDataFeederItem
as JSON-object via the ActiveMQ.item
- The new sensor event as SensorDataFeederItem
.private de.hawhamburg.livingplace.messaging.activemq.wrapper.LPPublisher getTopic(java.lang.String type)
LPPublisher
object which holds an open ActiveMQ topic connection named as
"topicRoot
+[SENSOR_TYPE_NAME]".type
- The name of the sensor type as String
.LPPublisher
as open topic on the ActiveMQ to publish the simulated sensor
event.public final java.lang.String getPath()
String
.public final java.lang.String getFile()
String
.public final java.lang.String getTopicRoot()
String
.public final int getSpeed()
public final java.util.Map<java.lang.Integer,SensorDataFeederItem> getStory()
SensorDataFeederItem
.SensorDataFeederItem
.public final java.util.SortedMap<SensorDataFeederItem,java.lang.String> getLog()
SensorDataFeederItem
.SensorDataFeederItem
.public final boolean sendsHeartbeats()
true
if this simulation sends its actual simulation time as simulated time
sensor, otherwise false
.public final boolean isSilent()
true
if the simulation runs in silent mode, otherwise false
.private void simulateTime(int last, int next, int speedIn)
last
- The simulation time in minutes where the last event took place.next
- The simulation time in minutes where the next event shall start.speedIn
- The current simulation time in simulation minutes per real-time minute.public static void main(java.lang.String[] args)
--storyfile | Name of the used story file |
(Defaults to TEST_FILE ) |
|
--storypath | Path to the used story file |
(Defaults to TEST_PATH ) |
|
--feederwait | Delay time before start in milliseconds |
--feederchannelroot | Default AMQ topic prefix |
(Defaults to TOPIC_ROOT ) |
|
--feederspeed | Speed of simulation in simulation minutes per real minute |
(Defaults to FEEDER_SPEED ) |
|
--feederheartbeat | Instruction to send the actual simulation time each simulation minute as time sensor event. |
(Defaults to FEEDER_HEARTBEAT ) |
|
--feedersilent | Determines if this service shall print out debug output or not. |
(Defaults to FEEDER_SILENT ) |
|
--wrapped | Informs the systems it wasn't started as stand-alone service and forces it to be silent. |
args
- The command line arguments (see method description for usage).