Package jmri.jmris.simpleserver
Class SimpleOperationsServer
java.lang.Object
jmri.jmris.AbstractOperationsServer
jmri.jmris.simpleserver.SimpleOperationsServer
- All Implemented Interfaces:
PropertyChangeListener,EventListener
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
FieldsModifier and TypeFieldDescriptionstatic final Stringthe character that separates the field tag from its value.static final StringReturns a list of locations that the trains visit.static final StringAll operation messages start with the key word "OPERATIONS" followed by a command like "TRAINS".static final StringTerminates the train and returns the train's status.static final Stringthe tag identifying the train's identitystatic final StringRequests/returns the road and number of the caboose for this train if there's one assigned.static final StringRequests/returns the number of cars in the train.static final StringRequests/returns the road and number of the lead loco for this train.static final StringRequests/returns the train's length.static final StringSets/requests/returns the train's location or gets the train's current location.static final StringReturns a list of trains.static final StringRequests/returns the train's status.static final StringRequests/returns the train's weight.Fields inherited from class jmri.jmris.AbstractOperationsServer
lm, tm, trains -
Constructor Summary
ConstructorsConstructorDescriptionSimpleOperationsServer(DataInputStream inStream, DataOutputStream outStream) SimpleOperationsServer(JmriConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconstructOperationsMessage(List<Attribute> contents) constructs a request in a format that parseOperationsMessage can handle.parseOperationsMessage(String message) parse a String presumably constructed by constructOperationsMessage.voidparseStatus(String statusString) Parse operation commands.voidvoidsendErrorStatus(String errorStatus) constructs an error message and sends it to the client.voidsendFullStatus(Train train) sends the full status for a train to a clientvoidsend a list of locations known by Operations to the clientvoidsendMessage(ArrayList<Attribute> contents) send a String to the other end of the telnet connection.voidsend a list of trains known by Operations to the clientMethods inherited from class jmri.jmris.AbstractOperationsServer
addTrainToList, constructTrainCaboose, constructTrainLeadLoco, constructTrainLength, constructTrainLocation, constructTrainNumberOfCars, constructTrainStatus, constructTrainWeight, dispose, getListener, isExactLoationNameEnabled, removeTrainFromList, setExactLocationName, setTrainLocation, terminateTrain
-
Field Details
-
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:
-
TRAIN
the tag identifying the train's identity- See Also:
-
TRAINS
Returns a list of trains. One line for each train in the list.- See Also:
-
LOCATIONS
Returns a list of locations that the trains visit. One line for each location in the list.- See Also:
-
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:
-
TRAINWEIGHT
Requests/returns the train's weight. The train's name is required.- See Also:
-
TRAINCARS
Requests/returns the number of cars in the train. The train's name is required.- See Also:
-
TRAINLEADLOCO
Requests/returns the road and number of the lead loco for this train. The train's name is required.- See Also:
-
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:
-
TRAINSTATUS
Requests/returns the train's status. The train's name is required.- See Also:
-
TERMINATE
Terminates the train and returns the train's status. The train's name is required.- See Also:
-
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:
-
FIELDSEPARATOR
the character that separates the field tag from its value.- See Also:
-
-
Constructor Details
-
SimpleOperationsServer
-
SimpleOperationsServer
-
-
Method Details
-
sendMessage
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:
IOException- if unable to send.
-
sendErrorStatus
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:
IOException- if there is a problem sending the error message
-
constructOperationsMessage
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
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
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.IOException- if unable to send response.
-
sendTrainList
send a list of trains known by Operations to the client- Specified by:
sendTrainListin classAbstractOperationsServer
-
sendLocationList
send a list of locations known by Operations to the client- Specified by:
sendLocationListin classAbstractOperationsServer
-
sendFullStatus
sends the full status for a train to a client- Specified by:
sendFullStatusin classAbstractOperationsServer- Parameters:
train- The desired train.- Throws:
IOException- on failure to send an error message
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener- Specified by:
propertyChangein classAbstractOperationsServer
-