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 classLocoNetThrottledTransmitter.Memo(package private) classLocoNetThrottledTransmitter.ServiceThread
-
Field Summary
Fields Modifier and Type Field Description (package private) LocoNetInterfacecontroller(package private) booleandisposed(package private) longlastSendTimeMSec(package private) LocoNetSystemConnectionMemomemoReference to the system connection memo.(package private) longminInterval(package private) booleanmTurnoutExtraSpace(package private) java.util.concurrent.DelayQueue<LocoNetThrottledTransmitter.Memo>queue(package private) booleanrunningstatic java.lang.StringSERVICE_THREAD_NAMEConstant for the name of the Service Thread.(package private) LocoNetThrottledTransmitter.ServiceThreadtheServiceThread-
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 voidaddLocoNetListener(int mask, LocoNetListener listener)Request notification of things happening on the LocoNet.(package private) longcalcSendTimeMSec()voiddispose()Request that server thread cease operation, no more messages can be sent.LocoNetSystemConnectionMemogetSystemConnectionMemo()Get the system connection memo associated with this traffic controller.(package private) static longnowMSec()voidremoveLocoNetListener(int mask, LocoNetListener listener)voidsendLocoNetMessage(LocoNetMessage msg)Accept a message to be sent after suitable delay.voidsetSystemConnectionMemo(LocoNetSystemConnectionMemo m)Set the system connection memo associated with this traffic controller.booleanstatus()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:
setSystemConnectionMemoin interfaceLocoNetInterface- Parameters:
m- associated systemConnectionMemo object
-
getSystemConnectionMemo
public LocoNetSystemConnectionMemo getSystemConnectionMemo()
Get the system connection memo associated with this traffic controller.- Specified by:
getSystemConnectionMemoin 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:LocoNetInterfaceRequest 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:
addLocoNetListenerin 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:
removeLocoNetListenerin interfaceLocoNetInterface
-
status
public boolean status()
Description copied from interface:LocoNetInterfaceCheck whether an implementation is operational. Returns true if operational.- Specified by:
statusin interfaceLocoNetInterface- Returns:
- true if implementation is operational.
-
sendLocoNetMessage
public void sendLocoNetMessage(LocoNetMessage msg)
Accept a message to be sent after suitable delay.- Specified by:
sendLocoNetMessagein interfaceLocoNetInterface
-
calcSendTimeMSec
long calcSendTimeMSec()
-
nowMSec
static long nowMSec()
-
-