Class LocoNetThrottledTransmitter
- java.lang.Object
-
- jmri.jmrix.loconet.LocoNetThrottledTransmitter
-
- All Implemented Interfaces:
LocoNetInterface
public class LocoNetThrottledTransmitter extends java.lang.Object implements LocoNetInterface
Delay LocoNet messages that need to be throttled.A LocoNetThrottledTransmitter object sits in front of a LocoNetInterface (e.g. TrafficHandler) and meters out specific LocoNet messages.
The internal Memo class is used to hold the pending message and the time it's to be sent. Time computations are in units of milliseconds, as that's all the accuracy that's needed here.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
LocoNetThrottledTransmitter.Memo
(package private) class
LocoNetThrottledTransmitter.ServiceThread
-
Field Summary
Fields Modifier and Type Field Description (package private) LocoNetInterface
controller
(package private) boolean
disposed
(package private) long
lastSendTimeMSec
(package private) LocoNetSystemConnectionMemo
memo
Reference to the system connection memo.(package private) long
minInterval
(package private) boolean
mTurnoutExtraSpace
(package private) java.util.concurrent.DelayQueue<LocoNetThrottledTransmitter.Memo>
queue
(package private) boolean
running
static java.lang.String
SERVICE_THREAD_NAME
Constant for the name of the Service Thread.(package private) LocoNetThrottledTransmitter.ServiceThread
theServiceThread
-
Fields inherited from interface jmri.jmrix.loconet.LocoNetInterface
ALL, POWER, PROGRAMMING, SENSORS, SLOTINFO, TURNOUTS
-
-
Constructor Summary
Constructors Constructor Description LocoNetThrottledTransmitter(LocoNetInterface controller, boolean mTurnoutExtraSpace)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLocoNetListener(int mask, LocoNetListener listener)
Request notification of things happening on the LocoNet.(package private) long
calcSendTimeMSec()
void
dispose()
Request that server thread cease operation, no more messages can be sent.LocoNetSystemConnectionMemo
getSystemConnectionMemo()
Get the system connection memo associated with this traffic controller.(package private) static long
nowMSec()
void
removeLocoNetListener(int mask, LocoNetListener listener)
void
sendLocoNetMessage(LocoNetMessage msg)
Accept a message to be sent after suitable delay.void
setSystemConnectionMemo(LocoNetSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.boolean
status()
Check whether an implementation is operational.
-
-
-
Field Detail
-
memo
LocoNetSystemConnectionMemo memo
Reference to the system connection memo.
-
mTurnoutExtraSpace
boolean mTurnoutExtraSpace
-
disposed
volatile boolean disposed
-
running
volatile boolean running
-
controller
LocoNetInterface controller
-
minInterval
long minInterval
-
lastSendTimeMSec
long lastSendTimeMSec
-
queue
java.util.concurrent.DelayQueue<LocoNetThrottledTransmitter.Memo> queue
-
SERVICE_THREAD_NAME
public static final java.lang.String SERVICE_THREAD_NAME
Constant for the name of the Service Thread. Requires the connection UserName prepending.- See Also:
- Constant Field Values
-
theServiceThread
LocoNetThrottledTransmitter.ServiceThread theServiceThread
-
-
Constructor Detail
-
LocoNetThrottledTransmitter
public LocoNetThrottledTransmitter(@Nonnull LocoNetInterface controller, boolean mTurnoutExtraSpace)
-
-
Method Detail
-
setSystemConnectionMemo
public void setSystemConnectionMemo(LocoNetSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.- Specified by:
setSystemConnectionMemo
in interfaceLocoNetInterface
- Parameters:
m
- associated systemConnectionMemo object
-
getSystemConnectionMemo
public LocoNetSystemConnectionMemo getSystemConnectionMemo()
Get the system connection memo associated with this traffic controller.- Specified by:
getSystemConnectionMemo
in interfaceLocoNetInterface
- Returns:
- the associated systemConnectionMemo object
-
dispose
public void dispose()
Request that server thread cease operation, no more messages can be sent. Note that this returns before the thread is known to be done if it still has work pending. If you need to be sure it's done, check and wait on !running.
-
addLocoNetListener
public void addLocoNetListener(int mask, LocoNetListener listener)
Description copied from interface:LocoNetInterface
Request notification of things happening on the LocoNet.The same listener can register multiple times with different masks. (Multiple registrations with a single mask value are equivalent to a single registration) Mask values are defined as class constants. Note that these are bit masks, and should be OR'd, not added, if multiple values are desired.
The event notification contains the received message as source, not this object, so that we can notify of an incoming message to multiple places and then move on.
- Specified by:
addLocoNetListener
in interfaceLocoNetInterface
- Parameters:
mask
- The OR of the key values of messages to be reported (to reduce traffic, provide for listeners interested in different things)listener
- Object to be notified of new messages as they arrive.
-
removeLocoNetListener
public void removeLocoNetListener(int mask, LocoNetListener listener)
- Specified by:
removeLocoNetListener
in interfaceLocoNetInterface
-
status
public boolean status()
Description copied from interface:LocoNetInterface
Check whether an implementation is operational. Returns true if operational.- Specified by:
status
in interfaceLocoNetInterface
- Returns:
- true if implementation is operational.
-
sendLocoNetMessage
public void sendLocoNetMessage(LocoNetMessage msg)
Accept a message to be sent after suitable delay.- Specified by:
sendLocoNetMessage
in interfaceLocoNetInterface
-
calcSendTimeMSec
long calcSendTimeMSec()
-
nowMSec
static long nowMSec()
-
-