Package jmri.jmris.simpleserver
Class SimpleOperationsServer
- java.lang.Object
-
- jmri.jmris.AbstractOperationsServer
-
- jmri.jmris.simpleserver.SimpleOperationsServer
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener
public class SimpleOperationsServer extends AbstractOperationsServer
Simple interface between the JMRI operations and a network connection
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmris.AbstractOperationsServer
AbstractOperationsServer.TrainListener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFIELDSEPARATORthe character that separates the field tag from its value.static java.lang.StringLOCATIONSReturns a list of locations that the trains visit.static java.lang.StringOPERATIONSAll operation messages start with the key word "OPERATIONS" followed by a command like "TRAINS".static java.lang.StringTERMINATETerminates the train and returns the train's status.static java.lang.StringTRAINthe tag identifying the train's identitystatic java.lang.StringTRAINCABOOSERequests/returns the road and number of the caboose for this train if there's one assigned.static java.lang.StringTRAINCARSRequests/returns the number of cars in the train.static java.lang.StringTRAINLEADLOCORequests/returns the road and number of the lead loco for this train.static java.lang.StringTRAINLENGTHRequests/returns the train's length.static java.lang.StringTRAINLOCATIONSets/requests/returns the train's location or gets the train's current location.static java.lang.StringTRAINSReturns a list of trains.static java.lang.StringTRAINSTATUSRequests/returns the train's status.static java.lang.StringTRAINWEIGHTRequests/returns the train's weight.-
Fields inherited from class jmri.jmris.AbstractOperationsServer
lm, tm, trains
-
-
Constructor Summary
Constructors Constructor Description SimpleOperationsServer(java.io.DataInputStream inStream, java.io.DataOutputStream outStream)SimpleOperationsServer(JmriConnection connection)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringconstructOperationsMessage(java.util.List<javax.management.Attribute> contents)constructs a request in a format that parseOperationsMessage can handle.static java.util.ArrayList<javax.management.Attribute>parseOperationsMessage(java.lang.String message)parse a String presumably constructed by constructOperationsMessage.voidparseStatus(java.lang.String statusString)Parse operation commands.voidpropertyChange(java.beans.PropertyChangeEvent e)voidsendErrorStatus(java.lang.String errorStatus)constructs an error message and sends it to the client.voidsendFullStatus(Train train)sends the full status for a train to a clientvoidsendLocationList()send a list of locations known by Operations to the clientvoidsendMessage(java.util.ArrayList<javax.management.Attribute> contents)send a String to the other end of the telnet connection.voidsendTrainList()send a list of trains known by Operations to the client-
Methods inherited from class jmri.jmris.AbstractOperationsServer
addTrainToList, constructTrainCaboose, constructTrainLeadLoco, constructTrainLength, constructTrainLocation, constructTrainNumberOfCars, constructTrainStatus, constructTrainWeight, dispose, getListener, isExactLoationNameEnabled, removeTrainFromList, setExactLocationName, setTrainLocation, terminateTrain
-
-
-
-
Field Detail
-
OPERATIONS
public static final java.lang.String OPERATIONS
All operation messages start with the key word "OPERATIONS" followed by a command like "TRAINS". The reply message also starts with the key word "OPERATIONS" followed by the original command followed by the desired results.- See Also:
- Constant Field Values
-
TRAIN
public static final java.lang.String TRAIN
the tag identifying the train's identity- See Also:
- Constant Field Values
-
TRAINS
public static final java.lang.String TRAINS
Returns a list of trains. One line for each train in the list.- See Also:
- Constant Field Values
-
LOCATIONS
public static final java.lang.String LOCATIONS
Returns a list of locations that the trains visit. One line for each location in the list.- See Also:
- Constant Field Values
-
TRAINLENGTH
public static final java.lang.String TRAINLENGTH
Requests/returns the train's length. The train's name is required. Proper message format: "OPERATIONS TRAIN=train_name , TRAINLENGTH" Returns train length if train exists, otherwise an error message.Request: "Operations , TRAIN=train"
Reply: "OPERATIONS , TRAIN=train , TRAINLENGTH=train_length"
- See Also:
- Constant Field Values
-
TRAINWEIGHT
public static final java.lang.String TRAINWEIGHT
Requests/returns the train's weight. The train's name is required.- See Also:
- Constant Field Values
-
TRAINCARS
public static final java.lang.String TRAINCARS
Requests/returns the number of cars in the train. The train's name is required.- See Also:
- Constant Field Values
-
TRAINLEADLOCO
public static final java.lang.String TRAINLEADLOCO
Requests/returns the road and number of the lead loco for this train. The train's name is required.- See Also:
- Constant Field Values
-
TRAINCABOOSE
public static final java.lang.String TRAINCABOOSE
Requests/returns the road and number of the caboose for this train if there's one assigned. The train's name is required.- See Also:
- Constant Field Values
-
TRAINSTATUS
public static final java.lang.String TRAINSTATUS
Requests/returns the train's status. The train's name is required.- See Also:
- Constant Field Values
-
TERMINATE
public static final java.lang.String TERMINATE
Terminates the train and returns the train's status. The train's name is required.- See Also:
- Constant Field Values
-
TRAINLOCATION
public static final java.lang.String TRAINLOCATION
Sets/requests/returns the train's location or gets the train's current location.Sets the train's location: "Operations , TRAIN=train_name , TRAINLOCATION=location"
Requests the train's location: "OPERATIONS , TRAIN=train_name"
Returns the train's location: "OPERATIONS , TRAIN=train_name , TRAINLOCATION=location"
- See Also:
- Constant Field Values
-
FIELDSEPARATOR
public static final java.lang.String FIELDSEPARATOR
the character that separates the field tag from its value.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SimpleOperationsServer
public SimpleOperationsServer(JmriConnection connection)
-
SimpleOperationsServer
public SimpleOperationsServer(java.io.DataInputStream inStream, java.io.DataOutputStream outStream)
-
-
Method Detail
-
sendMessage
public void sendMessage(java.util.ArrayList<javax.management.Attribute> contents) throws java.io.IOException
send a String to the other end of the telnet connection. The String is composed of a set of attributes.- Specified by:
sendMessagein classAbstractOperationsServer- Parameters:
contents- is the ArrayList of Attributes to be sent. A linefeed ('\n") is appended to the String.- Throws:
java.io.IOException- if unable to send.
-
sendErrorStatus
public void sendErrorStatus(java.lang.String errorStatus) throws java.io.IOException
constructs an error message and sends it to the client. The error message will be- OPERATIONS:
- the error string
- "\n"
- Specified by:
sendErrorStatusin classAbstractOperationsServer- Parameters:
errorStatus- is the error message. It need not include any padding - this method will add it. It should be plain text.- Throws:
java.io.IOException- if there is a problem sending the error message
-
constructOperationsMessage
public static java.lang.String constructOperationsMessage(java.util.List<javax.management.Attribute> contents)
constructs a request in a format that parseOperationsMessage can handle. An OperationsMessage has the format:- OPERATIONS
- " , " (delimiter)
- request/reponse
- any number of " , " , followed by additional request/response pairs
- Parameters:
contents- is an array of Attributes. An Attribute is a String (tag) and a value. For this use, the value will always be a String or null. Thus, "=" and REQUEST_DELIMITER are illegal in a tag and REQUEST_DELIMITER is illegal in a value.- Returns:
- a String which is a serialized version of the attribute array, which can be sent to an SimpleOperationsServer or received from a SimpleOperationsServer
-
parseOperationsMessage
public static java.util.ArrayList<javax.management.Attribute> parseOperationsMessage(java.lang.String message)
parse a String presumably constructed by constructOperationsMessage. It breaks the String down into tag or tag=value pairs, using a REQUEST_DELIMITER as the separator. Each pair is further broken down into the tag and value and stuffed into an Attribute. The Attribute is then added to the resulting ArrayList.The leading OPERATIONS String is NOT included. If the first String is not OPERATIONS, an empty ArrayList is returned.
- Parameters:
message- is the String received- Returns:
- an ArrayList of Attributes of the constituent pieces of the message
-
parseStatus
public void parseStatus(java.lang.String statusString) throws JmriException, java.io.IOException
Parse operation commands. They all start with "OPERATIONS" followed by a command like "LOCATIONS". A command like "TRAINLENGTH" requires a train name. The delimiter is the tab character.- Specified by:
parseStatusin classAbstractOperationsServer- Parameters:
statusString- the string to parse.- Throws:
JmriException- if unable to parse status.java.io.IOException- if unable to send response.
-
sendTrainList
public void sendTrainList()
send a list of trains known by Operations to the client- Specified by:
sendTrainListin classAbstractOperationsServer
-
sendLocationList
public void sendLocationList()
send a list of locations known by Operations to the client- Specified by:
sendLocationListin classAbstractOperationsServer
-
sendFullStatus
public void sendFullStatus(Train train) throws java.io.IOException
sends the full status for a train to a client- Specified by:
sendFullStatusin classAbstractOperationsServer- Parameters:
train- The desired train.- Throws:
java.io.IOException- on failure to send an error message
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener- Specified by:
propertyChangein classAbstractOperationsServer
-
-