Package jmri.jmrix.lenz
Class XNetTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.lenz.XNetTrafficController
-
- All Implemented Interfaces:
XNetInterface
- Direct Known Subclasses:
XNetPacketizer
,XNetTrafficRouter
public abstract class XNetTrafficController extends AbstractMRTrafficController implements XNetInterface
Abstract base class for implementations of XNetInterface.This provides just the basic interface.
- See Also:
AbstractMRTrafficController
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.LinkedBlockingQueue<XNetListener>
highPriorityListeners
(package private) java.util.concurrent.LinkedBlockingQueue<XNetMessage>
highPriorityQueue
(package private) LenzCommandStation
mCommandStation
Reference to the command station in communication here.protected java.util.HashMap<XNetListener,java.lang.Integer>
mListenerMasks
(package private) XNetSystemConnectionMemo
mMemo
Reference to the system connection memo.(package private) static XNetTrafficController
self
-
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, AUTORETRYSTATE, cmdListeners, connectionError, controller, flushReceiveChars, IDLESTATE, istream, listenerQueue, maxRcvExceptionCount, mCurrentMode, mCurrentState, mLastSender, msgQueue, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, POLLSTATE, PROGRAMINGMODE, rcvException, rcvThread, replyInDispatch, threadStopRequest, timeoutFlag, timeouts, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable, xmtThread
-
Fields inherited from interface jmri.jmrix.lenz.XNetInterface
ALL, COMMINFO, CONSIST, CS_INFO, FEEDBACK, INTERFACE, PROGRAMMING, THROTTLE
-
-
Constructor Summary
Constructors Constructor Description XNetTrafficController(LenzCommandStation pCommandStation)
Create a new XNetTrafficController.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addXNetListener(int mask, XNetListener l)
Request notification of things happening on the XNet.void
connectPort(AbstractPortController p)
Make connection to existing PortController object.protected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
Return the value of getExitProgModeMsg().protected AbstractMRMessage
enterProgMode()
This method has to be available, even though it doesn't do anything on Lenz.void
forwardMessage(AbstractMRListener reply, AbstractMRMessage m)
Forward a preformatted XNetMessage to a specific listener interface.void
forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward a preformatted XNetMessage to the registered XNetListeners.LenzCommandStation
getCommandStation()
Get access to communicating command station object.XNetFeedbackMessageCache
getFeedbackMessageCache()
Return an XNetFeedbackMessageCache object associated with this traffic controller.XNetSystemConnectionMemo
getSystemConnectionMemo()
Get access to the system connection memo associated with this traffic controller.protected void
handleTimeout(AbstractMRMessage msg, AbstractMRListener l)
(package private) boolean
hasTimeSlot()
protected void
loadChars(AbstractMRReply msg, java.io.DataInputStream istream)
Get characters from the input source, and file a message.protected AbstractMRReply
newReply()
protected void
notifyMessage(AbstractMRMessage m, AbstractMRListener notMe)
Forward a Message to registered listeners.protected AbstractMRMessage
pollMessage()
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TrafficController should just sleep.protected AbstractMRListener
pollReplyHandler()
protected boolean
programmerIdle()
Check to see if the programmer associated with this interface is idle or not.void
removeXNetListener(int mask, XNetListener l)
Stop notification of things happening on the XNet.void
sendHighPriorityXNetMessage(XNetMessage m, XNetListener reply)
void
setSystemConnectionMemo(XNetSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, disconnectPort, distributeReply, enterProgModeDelayTime, forwardToPort, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, hasTimeouts, lengthOfByteStream, newRcvNotifier, notifyReply, portReadyToSend, portWarn, portWarnTCP, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.lenz.XNetInterface
sendXNetMessage, status
-
-
-
-
Field Detail
-
mListenerMasks
protected final java.util.HashMap<XNetListener,java.lang.Integer> mListenerMasks
-
self
static XNetTrafficController self
-
highPriorityQueue
final java.util.concurrent.LinkedBlockingQueue<XNetMessage> highPriorityQueue
-
highPriorityListeners
final java.util.concurrent.LinkedBlockingQueue<XNetListener> highPriorityListeners
-
mCommandStation
final LenzCommandStation mCommandStation
Reference to the command station in communication here.
-
mMemo
XNetSystemConnectionMemo mMemo
Reference to the system connection memo.
-
-
Constructor Detail
-
XNetTrafficController
XNetTrafficController(LenzCommandStation pCommandStation)
Create a new XNetTrafficController. Must provide a LenzCommandStation reference at creation time.- Parameters:
pCommandStation
- reference to associated command station object, preserved for later.
-
-
Method Detail
-
connectPort
public void connectPort(AbstractPortController p)
Make connection to existing PortController object.- Overrides:
connectPort
in classAbstractMRTrafficController
- Parameters:
p
- the PortController
-
forwardMessage
public void forwardMessage(AbstractMRListener reply, AbstractMRMessage m)
Forward a preformatted XNetMessage to a specific listener interface.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
m
- Message to sendreply
- abstract listener.
-
forwardReply
public void forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward a preformatted XNetMessage to the registered XNetListeners.NOTE: this drops the packet if the checksum is bad.
- Specified by:
forwardReply
in classAbstractMRTrafficController
- Parameters:
client
- is the client getting the messagem
- Message to send
-
sendHighPriorityXNetMessage
public void sendHighPriorityXNetMessage(XNetMessage m, XNetListener reply)
-
pollMessage
protected AbstractMRMessage pollMessage()
Description copied from class:AbstractMRTrafficController
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TrafficController should just sleep.- Specified by:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
addXNetListener
public void addXNetListener(int mask, XNetListener l)
Description copied from interface:XNetInterface
Request notification of things happening on the XNet.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:
addXNetListener
in interfaceXNetInterface
- 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.
-
removeXNetListener
public void removeXNetListener(int mask, XNetListener l)
Description copied from interface:XNetInterface
Stop notification of things happening on the XNet.Note that mask and XNetListener must match a previous request exactly.
- Specified by:
removeXNetListener
in interfaceXNetInterface
- Parameters:
mask
- listening mask.l
- listener to remove notifications for.
-
enterProgMode
protected AbstractMRMessage enterProgMode()
This method has to be available, even though it doesn't do anything on Lenz.- Specified by:
enterProgMode
in classAbstractMRTrafficController
- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage enterNormalMode()
Return the value of getExitProgModeMsg().- Specified by:
enterNormalMode
in classAbstractMRTrafficController
- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
AbstractMRTrafficController.enterProgMode()
-
programmerIdle
protected boolean programmerIdle()
Check to see if the programmer associated with this interface is idle or not.- Overrides:
programmerIdle
in classAbstractMRTrafficController
- Returns:
- true if not busy programming
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
loadChars
protected void loadChars(AbstractMRReply msg, java.io.DataInputStream istream) throws java.io.IOException
Get characters from the input source, and file a message.Returns only when the message is complete.
Only used in the Receive thread.
- Overrides:
loadChars
in classAbstractMRTrafficController
- Parameters:
msg
- message to fillistream
- character source.- Throws:
java.io.IOException
- when presented by the input source.
-
handleTimeout
protected void handleTimeout(AbstractMRMessage msg, AbstractMRListener l)
- Overrides:
handleTimeout
in classAbstractMRTrafficController
-
notifyMessage
protected void notifyMessage(AbstractMRMessage m, AbstractMRListener notMe)
Description copied from class:AbstractMRTrafficController
Forward a Message to registered listeners.- Overrides:
notifyMessage
in classAbstractMRTrafficController
- Parameters:
m
- Message to be forwarded intactnotMe
- One (optional) listener to be skipped, usually because it's the originating object.
-
getCommandStation
public LenzCommandStation getCommandStation()
Get access to communicating command station object.- Returns:
- associated Command Station object
-
getSystemConnectionMemo
public XNetSystemConnectionMemo getSystemConnectionMemo()
Get access to the system connection memo associated with this traffic controller.- Returns:
- associated systemConnectionMemo object
-
setSystemConnectionMemo
public void setSystemConnectionMemo(XNetSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.- Parameters:
m
- associated systemConnectionMemo object
-
getFeedbackMessageCache
public XNetFeedbackMessageCache getFeedbackMessageCache()
Return an XNetFeedbackMessageCache object associated with this traffic controller.- Returns:
- the feedback message cache. One is provided if null.
-
hasTimeSlot
boolean hasTimeSlot()
- Returns:
- whether or not this connection currently has a timeslot from the Command station.
-
-