Package jmri.jmrix.xpa
Class XpaTrafficController
- java.lang.Object
-
- jmri.jmrix.xpa.XpaTrafficController
-
- All Implemented Interfaces:
java.lang.Runnable
,XpaInterface
public class XpaTrafficController extends java.lang.Object implements XpaInterface, java.lang.Runnable
Converts Stream-based I/O to/from Xpa messages. The "XpaInterface" side sends/receives message objects. The connection to an XpaPortController is via a pair of *Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
XpaTrafficController.XmtHandler
Captive class to handle transmission.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<XpaListener>
cmdListeners
(package private) java.io.DataInputStream
istream
(package private) XpaListener
lastSender
(package private) java.io.OutputStream
ostream
(package private) XpaTrafficController.XmtHandler
xmtHandler
(local class) object to implement the transmit thread(package private) java.util.LinkedList<byte[]>
xmtList
(package private) java.lang.Thread
xmtThread
-
Constructor Summary
Constructors Constructor Description XpaTrafficController()
Create a new XpaTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addXpaListener(XpaListener l)
void
connectPort(XpaPortController p)
Make connection to existing PortController object.void
disconnectPort(XpaPortController p)
Break connection to existing XpaPortController object.(package private) void
handleOneIncomingReply()
protected void
notifyMessage(XpaMessage m, XpaListener notMe)
Forward a XpaMessage to all registered XpaInterface listeners.protected void
notifyReply(XpaMessage r)
void
removeXpaListener(XpaListener l)
void
run()
Handle incoming characters.void
sendXpaMessage(XpaMessage m, XpaListener reply)
Forward a pre-formatted message to the actual interface.void
startTransmitThread()
Start the Transmit thread.boolean
status()
Test operational status of interface.
-
-
-
Field Detail
-
xmtList
final java.util.LinkedList<byte[]> xmtList
-
xmtHandler
final XpaTrafficController.XmtHandler xmtHandler
(local class) object to implement the transmit thread
-
xmtThread
java.lang.Thread xmtThread
-
cmdListeners
protected final java.util.ArrayList<XpaListener> cmdListeners
-
lastSender
XpaListener lastSender
-
istream
java.io.DataInputStream istream
-
ostream
java.io.OutputStream ostream
-
-
Constructor Detail
-
XpaTrafficController
public XpaTrafficController()
Create a new XpaTrafficController instance.
-
-
Method Detail
-
startTransmitThread
public void startTransmitThread()
Start the Transmit thread.
-
status
public boolean status()
Description copied from interface:XpaInterface
Test operational status of interface.- Specified by:
status
in interfaceXpaInterface
- Returns:
- true if the interface implementation is operational.
-
addXpaListener
public void addXpaListener(XpaListener l)
- Specified by:
addXpaListener
in interfaceXpaInterface
-
removeXpaListener
public void removeXpaListener(XpaListener l)
- Specified by:
removeXpaListener
in interfaceXpaInterface
-
notifyMessage
protected void notifyMessage(XpaMessage m, XpaListener notMe)
Forward a XpaMessage to all registered XpaInterface listeners.- Parameters:
m
- the message to forwardnotMe
- registered listener not to forward the message to
-
notifyReply
protected void notifyReply(XpaMessage r)
-
sendXpaMessage
public void sendXpaMessage(XpaMessage m, XpaListener reply)
Forward a pre-formatted message to the actual interface.- Specified by:
sendXpaMessage
in interfaceXpaInterface
- Parameters:
m
- the message to forwardreply
- the listener to receive the reply
-
connectPort
public void connectPort(XpaPortController p)
Make connection to existing PortController object.- Parameters:
p
- controller for the port associated with this controller
-
disconnectPort
public void disconnectPort(XpaPortController p)
Break connection to existing XpaPortController object. Once broken, attempts to send via "message" member will fail.- Parameters:
p
- controller for the port associated with this controller
-
run
public void run()
Handle incoming characters. This is a permanent loop, looking for input messages in character form on the stream connected to the PortController viaconnectPort
. Terminates with the input stream breaking out of the try block.- Specified by:
run
in interfacejava.lang.Runnable
-
handleOneIncomingReply
void handleOneIncomingReply() throws java.io.IOException
- Throws:
java.io.IOException
-
-