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) LocoNetSystemConnectionMemomemoReference to the system connection memo.protected intreceivedByteCountprotected intreceivedMsgCountprotected inttransmittedMsgCount-
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 voidaddLocoNetListener(int mask, LocoNetListener l)Request notification of things happening on the LocoNet.voiddispose()Clean up any resources, particularly threads.intgetReceivedByteCount()Monitor the number of bytes in LocoNet messages received across the interface.intgetReceivedMsgCount()Monitor the number of LocoNet messages received across the interface.LocoNetSystemConnectionMemogetSystemConnectionMemo()Get the system connection memo associated with this connection.intgetTransmittedMsgCount()Monitor the number of LocoNet messages transmitted across the interface.abstract booleanisXmtBusy()Is there a backlog of information for the outbound link?voidnotify(LocoNetMessage m)Forward a LocoNetMessage to all registered listeners.voidremoveLocoNetListener(int mask, LocoNetListener l)voidresetStatistics()Reset statistics (received message count, transmitted message count, received byte count).abstract voidsendLocoNetMessage(LocoNetMessage m)Forward a preformatted LocoNetMessage to the actual interface.voidsetSystemConnectionMemo(LocoNetSystemConnectionMemo m)Set the system connection memo associated with this connection.abstract booleanstatus()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:
setSystemConnectionMemoin interfaceLocoNetInterface- Parameters:
m- associated systemConnectionMemo object
-
getSystemConnectionMemo
public LocoNetSystemConnectionMemo getSystemConnectionMemo()
Get the system connection memo associated with this connection.- Specified by:
getSystemConnectionMemoin interfaceLocoNetInterface- Returns:
- the associated systemConnectionMemo object
-
status
public abstract boolean status()
Check whether an implementation is operational. Returns true if operational.- Specified by:
statusin 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:
sendLocoNetMessagein interfaceLocoNetInterface- Parameters:
m- message to send; will be updated with CRC
-
addLocoNetListener
public void addLocoNetListener(int mask, @Nonnull LocoNetListener l)
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)l- Object to be notified of new messages as they arrive.
-
removeLocoNetListener
public void removeLocoNetListener(int mask, @Nonnull LocoNetListener l)
- Specified by:
removeLocoNetListenerin interfaceLocoNetInterface
-
notify
public void notify(LocoNetMessage m)
Forward a LocoNetMessage to all registered listeners.Needs to have public access, as
LnOverTcpPacketizerandIBLnPacketizerinvoke 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
-
-