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
  • Field Details

    • OPERATIONS

      public static final 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:
    • TRAIN

      public static final String TRAIN
      the tag identifying the train's identity
      See Also:
    • TRAINS

      public static final String TRAINS
      Returns a list of trains. One line for each train in the list.
      See Also:
    • LOCATIONS

      public static final String LOCATIONS
      Returns a list of locations that the trains visit. One line for each location in the list.
      See Also:
    • TRAINLENGTH

      public static final 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:
    • TRAINWEIGHT

      public static final String TRAINWEIGHT
      Requests/returns the train's weight. The train's name is required.
      See Also:
    • TRAINCARS

      public static final String TRAINCARS
      Requests/returns the number of cars in the train. The train's name is required.
      See Also:
    • TRAINLEADLOCO

      public static final String TRAINLEADLOCO
      Requests/returns the road and number of the lead loco for this train. The train's name is required.
      See Also:
    • TRAINCABOOSE

      public static final 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:
    • TRAINSTATUS

      public static final String TRAINSTATUS
      Requests/returns the train's status. The train's name is required.
      See Also:
    • TERMINATE

      public static final String TERMINATE
      Terminates the train and returns the train's status. The train's name is required.
      See Also:
    • TRAINLOCATION

      public static final 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:
    • FIELDSEPARATOR

      public static final String FIELDSEPARATOR
      the character that separates the field tag from its value.
      See Also:
  • Constructor Details

  • Method Details

    • sendMessage

      public void sendMessage(ArrayList<Attribute> contents) throws IOException
      send a String to the other end of the telnet connection. The String is composed of a set of attributes.
      Specified by:
      sendMessage in class AbstractOperationsServer
      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

      public void sendErrorStatus(String errorStatus) throws IOException
      constructs an error message and sends it to the client. The error message will be
      • OPERATIONS:
      • the error string
      • "\n"
      Specified by:
      sendErrorStatus in class AbstractOperationsServer
      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

      public static String constructOperationsMessage(List<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
      The meaning of request/response is context sensitive. If the SimpleOperationsServer client is sending the message, then it is a request. If the SimpleOperationsServer is sending the message, then it is a response.
      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

      public void parseStatus(String statusString) throws JmriException, 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:
      parseStatus in class AbstractOperationsServer
      Parameters:
      statusString - the string to parse.
      Throws:
      JmriException - if unable to parse status.
      IOException - if unable to send response.
    • sendTrainList

      public void sendTrainList()
      send a list of trains known by Operations to the client
      Specified by:
      sendTrainList in class AbstractOperationsServer
    • sendLocationList

      public void sendLocationList()
      send a list of locations known by Operations to the client
      Specified by:
      sendLocationList in class AbstractOperationsServer
    • sendFullStatus

      public void sendFullStatus(Train train) throws IOException
      sends the full status for a train to a client
      Specified by:
      sendFullStatus in class AbstractOperationsServer
      Parameters:
      train - The desired train.
      Throws:
      IOException - on failure to send an error message
    • propertyChange

      Specified by:
      propertyChange in interface PropertyChangeListener
      Specified by:
      propertyChange in class AbstractOperationsServer