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) LenzCommandStationmCommandStationReference to the command station in communication here.protected java.util.HashMap<XNetListener,java.lang.Integer>mListenerMasks(package private) XNetSystemConnectionMemomMemoReference to the system connection memo.(package private) static XNetTrafficControllerself-
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 voidaddXNetListener(int mask, XNetListener l)Request notification of things happening on the XNet.voidconnectPort(AbstractPortController p)Make connection to existing PortController object.protected booleanendOfMessage(AbstractMRReply msg)protected AbstractMRMessageenterNormalMode()Return the value of getExitProgModeMsg().protected AbstractMRMessageenterProgMode()This method has to be available, even though it doesn't do anything on Lenz.voidforwardMessage(AbstractMRListener reply, AbstractMRMessage m)Forward a preformatted XNetMessage to a specific listener interface.voidforwardReply(AbstractMRListener client, AbstractMRReply m)Forward a preformatted XNetMessage to the registered XNetListeners.LenzCommandStationgetCommandStation()Get access to communicating command station object.XNetFeedbackMessageCachegetFeedbackMessageCache()Return an XNetFeedbackMessageCache object associated with this traffic controller.XNetSystemConnectionMemogetSystemConnectionMemo()Get access to the system connection memo associated with this traffic controller.protected voidhandleTimeout(AbstractMRMessage msg, AbstractMRListener l)(package private) booleanhasTimeSlot()protected voidloadChars(AbstractMRReply msg, java.io.DataInputStream istream)Get characters from the input source, and file a message.protected AbstractMRReplynewReply()protected voidnotifyMessage(AbstractMRMessage m, AbstractMRListener notMe)Forward a Message to registered listeners.protected AbstractMRMessagepollMessage()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 AbstractMRListenerpollReplyHandler()protected booleanprogrammerIdle()Check to see if the programmer associated with this interface is idle or not.voidremoveXNetListener(int mask, XNetListener l)Stop notification of things happening on the XNet.voidsendHighPriorityXNetMessage(XNetMessage m, XNetListener reply)voidsetSystemConnectionMemo(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:
connectPortin classAbstractMRTrafficController- Parameters:
p- the PortController
-
forwardMessage
public void forwardMessage(AbstractMRListener reply, AbstractMRMessage m)
Forward a preformatted XNetMessage to a specific listener interface.- Specified by:
forwardMessagein 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:
forwardReplyin 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:AbstractMRTrafficControllerInvoked 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:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
addXNetListener
public void addXNetListener(int mask, XNetListener l)
Description copied from interface:XNetInterfaceRequest 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:
addXNetListenerin 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:XNetInterfaceStop notification of things happening on the XNet.Note that mask and XNetListener must match a previous request exactly.
- Specified by:
removeXNetListenerin 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:
enterProgModein 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:
enterNormalModein 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:
programmerIdlein classAbstractMRTrafficController- Returns:
- true if not busy programming
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReplyin 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:
loadCharsin 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:
handleTimeoutin classAbstractMRTrafficController
-
notifyMessage
protected void notifyMessage(AbstractMRMessage m, AbstractMRListener notMe)
Description copied from class:AbstractMRTrafficControllerForward a Message to registered listeners.- Overrides:
notifyMessagein 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.
-
-