Class LnTrafficController
- java.lang.Object
-
- jmri.jmrix.loconet.LnTrafficController
-
- All Implemented Interfaces:
LocoNetInterface
- Direct Known Subclasses:
LnPacketizer
,LnTrafficRouter
public abstract class LnTrafficController extends java.lang.Object implements LocoNetInterface
Abstract base class for implementations of LocoNetInterface.This provides just the basic interface and some statistics support.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Vector<LocoNetListener>
listeners
(package private) LocoNetSystemConnectionMemo
memo
Reference to the system connection memo.protected int
receivedByteCount
protected int
receivedMsgCount
protected int
transmittedMsgCount
-
Fields inherited from interface jmri.jmrix.loconet.LocoNetInterface
ALL, POWER, PROGRAMMING, SENSORS, SLOTINFO, TURNOUTS
-
-
Constructor Summary
Constructors Constructor Description LnTrafficController()
Constructor without reference to a LocoNetSystemConnectionMemo.LnTrafficController(LocoNetSystemConnectionMemo memo)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addLocoNetListener(int mask, LocoNetListener l)
Request notification of things happening on the LocoNet.void
dispose()
Clean up any resources, particularly threads.int
getReceivedByteCount()
Monitor the number of bytes in LocoNet messages received across the interface.int
getReceivedMsgCount()
Monitor the number of LocoNet messages received across the interface.LocoNetSystemConnectionMemo
getSystemConnectionMemo()
Get the system connection memo associated with this connection.int
getTransmittedMsgCount()
Monitor the number of LocoNet messages transmitted across the interface.abstract boolean
isXmtBusy()
Is there a backlog of information for the outbound link?void
notify(LocoNetMessage m)
Forward a LocoNetMessage to all registered listeners.void
removeLocoNetListener(int mask, LocoNetListener l)
void
resetStatistics()
Reset statistics (received message count, transmitted message count, received byte count).abstract void
sendLocoNetMessage(LocoNetMessage m)
Forward a preformatted LocoNetMessage to the actual interface.void
setSystemConnectionMemo(LocoNetSystemConnectionMemo m)
Set the system connection memo associated with this connection.abstract boolean
status()
Check whether an implementation is operational.
-
-
-
Field Detail
-
memo
LocoNetSystemConnectionMemo memo
Reference to the system connection memo.
-
listeners
protected java.util.Vector<LocoNetListener> listeners
-
receivedMsgCount
protected int receivedMsgCount
-
receivedByteCount
protected int receivedByteCount
-
transmittedMsgCount
protected int transmittedMsgCount
-
-
Constructor Detail
-
LnTrafficController
public LnTrafficController()
Constructor without reference to a LocoNetSystemConnectionMemo.
-
LnTrafficController
public LnTrafficController(LocoNetSystemConnectionMemo memo)
Constructor. Gets a reference to the LocoNetSystemConnectionMemo.- Parameters:
memo
- connection's memo
-
-
Method Detail
-
setSystemConnectionMemo
public void setSystemConnectionMemo(LocoNetSystemConnectionMemo m)
Set the system connection memo associated with this connection.- Specified by:
setSystemConnectionMemo
in interfaceLocoNetInterface
- Parameters:
m
- associated systemConnectionMemo object
-
getSystemConnectionMemo
public LocoNetSystemConnectionMemo getSystemConnectionMemo()
Get the system connection memo associated with this connection.- Specified by:
getSystemConnectionMemo
in interfaceLocoNetInterface
- Returns:
- the associated systemConnectionMemo object
-
status
public abstract boolean status()
Check whether an implementation is operational. Returns true if operational.- Specified by:
status
in interfaceLocoNetInterface
- Returns:
- true if implementation is operational.
-
sendLocoNetMessage
public abstract void sendLocoNetMessage(LocoNetMessage m)
Forward a preformatted LocoNetMessage to the actual interface.Implementations should update the transmit count statistic.
- Specified by:
sendLocoNetMessage
in interfaceLocoNetInterface
- Parameters:
m
- message to send; will be updated with CRC
-
addLocoNetListener
public void addLocoNetListener(int mask, @Nonnull LocoNetListener l)
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)l
- Object to be notified of new messages as they arrive.
-
removeLocoNetListener
public void removeLocoNetListener(int mask, @Nonnull LocoNetListener l)
- Specified by:
removeLocoNetListener
in interfaceLocoNetInterface
-
notify
public void notify(LocoNetMessage m)
Forward a LocoNetMessage to all registered listeners.Needs to have public access, as
LnOverTcpPacketizer
andIBLnPacketizer
invoke it, but don't inherit from it.- Parameters:
m
- message to forward. Listeners should not modify it!
-
isXmtBusy
public abstract boolean isXmtBusy()
Is there a backlog of information for the outbound link? This includes both in the program (e.g. the outbound queue) and in the Command Station interface (e.g. flow control from the port).- Returns:
- true if busy, false if nothing waiting to send
-
resetStatistics
public void resetStatistics()
Reset statistics (received message count, transmitted message count, received byte count).
-
dispose
public void dispose()
Clean up any resources, particularly threads.The object can't be used after this.
-
getReceivedMsgCount
public int getReceivedMsgCount()
Monitor the number of LocoNet messages received across the interface. This includes the messages this client has sent.- Returns:
- the number of messages received
-
getReceivedByteCount
public int getReceivedByteCount()
Monitor the number of bytes in LocoNet messages received across the interface. This includes the bytes in messages this client has sent.- Returns:
- the number of bytes received
-
getTransmittedMsgCount
public int getTransmittedMsgCount()
Monitor the number of LocoNet messages transmitted across the interface.- Returns:
- the number of messages transmitted
-
-