Class SimpleOperationsServer

    • 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
      • 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
    • 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:
        sendMessage in class AbstractOperationsServer
        Parameters:
        contents - is the ArrayList of Attributes to be sent. A linefeed ('\n") is appended to the String.
        Throws:
        java.io.IOException
      • 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:
        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:
        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
        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

        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:
        parseStatus in class AbstractOperationsServer
        Throws:
        JmriException
        java.io.IOException
      • sendFullStatus

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