Class Message


  • public class Message
    extends java.lang.Object
    This class represents the message chain used for constructing the messages sent to the server.
    • Constructor Summary

      Constructors 
      Constructor Description
      Message()
      Constructs a new Message object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(long insref, int mref)
      Adds a new message to the message chain.
      boolean add_date​(int tag, java.lang.String value)
      Adds a date field to the current message.
      boolean add_date2​(int tag, int year, int month, int day)
      Adds a date field to the current message without having to construct it as a string before.
      boolean add_list​(int tag, java.lang.String value)
      Adds a space separated list of unsigned integers to the current message.
      boolean add_long​(int tag, long value, int decimals)
      Adds a scaled integer field to the current message.
      boolean add_numeric​(int tag, java.lang.String value)
      Adds a numeric field to the current message.
      boolean add_string​(int tag, java.lang.String value)
      Adds a string field to the current message.
      boolean add_time​(int tag, java.lang.String value)
      Adds a time field to the current message.
      boolean add_time2​(int tag, int hour, int min, int sec, int msec)
      Adds a time field to the current message without having to construct it as a string before.
      boolean add_time3​(int tag, int hour, int min, int sec, int nsec)
      Adds a time field to the current message without having to construct it as a string before, with nanosecond support.
      boolean addWithDelayInfo​(long insref, int mref, int delay)
      Adds a new message to the message chain.
      boolean del()
      Removes the current message from the message chain, marking it to be reused.
      protected void finalize()  
      static Message fromString​(java.lang.String string)
      Creates a Message from the string returned from the toString() method.
      int get_num()
      Return the total number of messages in the chain.
      int get_num_active()
      Return the number of active messages in the chain.
      boolean move​(Message dst, long insrefFrom, long insrefTo)
      Moves all messages with an insref matching insrefFrom to the Message at dst and change it to insrefTo.
      void reset()
      Resets the message chain so it can be reused.
      boolean setCompressionLevel​(int level)
      Sets the compression level as used by add_string when compressing the strings with zlib.
      boolean setDelay​(int value)
      Sets the intended delay for the current and/or future messages.
      boolean setUTF8Validation​(int value)
      Enables (1) or Disables (0) UTF-8 validation of the string given to add_string, the default is Disabled (0).
      java.lang.String toString()
      Serialize the message chain and return it as a base64 encoded string
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Message

        public Message()
        Constructs a new Message object.
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • toString

        public java.lang.String toString()
        Serialize the message chain and return it as a base64 encoded string
        Overrides:
        toString in class java.lang.Object
        Returns:
        base64 encoded serialized representation of the message chain
      • fromString

        public static Message fromString​(java.lang.String string)
        Creates a Message from the string returned from the toString() method.
        Parameters:
        string - a string returned from the toString() method of a Message class
        Returns:
        a Message class populated with the message chain from the base64 encoded input string
      • setCompressionLevel

        public boolean setCompressionLevel​(int level)
        Sets the compression level as used by add_string when compressing the strings with zlib.
        Parameters:
        level - compression level between 0-9 where 0 is Z_NO_COMPRESSION and 9 is Z_BEST_COMPRESSION. Default value is 1 (Z_BEST_SPEED).
        Returns:
        true if the compression level was successfully changed or false if there was an error
      • setUTF8Validation

        public boolean setUTF8Validation​(int value)
        Enables (1) or Disables (0) UTF-8 validation of the string given to add_string, the default is Disabled (0).
        Parameters:
        value - 1 to Enable UTF-8 validation or 0 to Disable it.
        Returns:
        true if the setting was successfully changed or false if there was an error
      • setDelay

        public boolean setDelay​(int value)
        Sets the intended delay for the current and/or future messages. The setting will remain until changed (a call to reset will not reset the setting back to the default). The default value is DLY.BEST.
        Parameters:
        value - The intended delay
        Returns:
        true if the setting was successfully changed or false if there was an error
      • add

        public boolean add​(long insref,
                           int mref)
        Adds a new message to the message chain. If there is an empty message in the chain, that message will be reused and no memory will be allocated. Use message_reference to define which message to send.
        Parameters:
        insref - instrument reference
        mref - message reference
        Returns:
        true if a new message was added (or an old was reused) or false if there was an error
      • addWithDelayInfo

        public boolean addWithDelayInfo​(long insref,
                                        int mref,
                                        int delay)
        Adds a new message to the message chain. If there is an empty message in the chain, that message will be reused and no memory will be allocated. Use message_reference to define which message to send.
        Parameters:
        insref - instrument reference
        mref - message reference
        delay - message delay
        Returns:
        true if a new message was added (or an old was reused) or false if there was an error
      • del

        public boolean del()
        Removes the current message from the message chain, marking it to be reused. The current message pointer will change to the previous message in the chain if there is any, so repeated calls will reset the whole chain.
        Returns:
        true if there are more messages in the chain or false if the message chain is empty
      • reset

        public void reset()
        Resets the message chain so it can be reused. The same as calling del() until it returns false.
      • add_list

        public boolean add_list​(int tag,
                                java.lang.String value)
        Adds a space separated list of unsigned integers to the current message.
        Parameters:
        tag - field tag to add
        value - a list of unsigned integers separated by space
        Returns:
        true if add was successfull, false if not
      • add_numeric

        public boolean add_numeric​(int tag,
                                   java.lang.String value)
        Adds a numeric field to the current message.
        Parameters:
        tag - field tag to add
        value - the numeric value to add as a string
        Returns:
        true if add was successfull, false if not
      • add_long

        public boolean add_long​(int tag,
                                long value,
                                int decimals)
        Adds a scaled integer field to the current message.
        Parameters:
        tag - field tag to add
        value - the scaled integer value
        decimals - the number of fixed decimals in the scaled integer
        Returns:
        true if add was successfull, false if not
      • add_string

        public boolean add_string​(int tag,
                                  java.lang.String value)
        Adds a string field to the current message.
        Parameters:
        tag - field tag to add
        value - the string to add
        Returns:
        true if add was successfull, false if not
      • add_date

        public boolean add_date​(int tag,
                                java.lang.String value)
        Adds a date field to the current message.
        Parameters:
        tag - field tag to add
        value - the date as a string in "YYYY-MM-DD", "YYYY-MM", "YYYY-Hx", "YYYY-Tx", "YYYY-Qx" or "YYYY-Wxx" format
        Returns:
        true if add was successfull, false if not
      • add_date2

        public boolean add_date2​(int tag,
                                 int year,
                                 int month,
                                 int day)
        Adds a date field to the current message without having to construct it as a string before.
        Parameters:
        tag - field tag to add
        year - the Year part of the date to add
        month - the Month part of the date to add
        day - the Day part of the date to add
        Returns:
        true if add was successfull, false if not
      • add_time

        public boolean add_time​(int tag,
                                java.lang.String value)
        Adds a time field to the current message.
        Parameters:
        tag - field tag to add
        value - the time as a string in "HH:MM:SS" or "HH:MM:SS.mmm" format
        Returns:
        true if add was successfull, false if not
      • add_time2

        public boolean add_time2​(int tag,
                                 int hour,
                                 int min,
                                 int sec,
                                 int msec)
        Adds a time field to the current message without having to construct it as a string before.
        Parameters:
        tag - field tag to add
        hour - the Hour part of the timestamp
        min - the Minutes part of the timestamp
        sec - the Seconds part of the timestamp
        msec - the Milliseconds part of the timestamp
        Returns:
        true if add was successfull, false if not
      • add_time3

        public boolean add_time3​(int tag,
                                 int hour,
                                 int min,
                                 int sec,
                                 int nsec)
        Adds a time field to the current message without having to construct it as a string before, with nanosecond support.
        Parameters:
        tag - field tag to add
        hour - the Hour part of the timestamp
        min - the Minutes part of the timestamp
        sec - the Seconds part of the timestamp
        nsec - the Nanoseconds part of the timestamp
        Returns:
        true if add was successfull, false if not
      • get_num

        public int get_num()
        Return the total number of messages in the chain. The difference between this and the number returned by the get_num_active method is that the message chain only grows as you add new messages to it and it never shrinks even after a call to reset or del. So get_num() returns the current absolute size of the message chain, i.e the number of messages it can contain before it needs to (automatically) be resized.
        Returns:
        the total number of messages in the chain
      • get_num_active

        public int get_num_active()
        Return the number of active messages in the chain.
        Returns:
        the number of active messages in the chain
      • move

        public boolean move​(Message dst,
                            long insrefFrom,
                            long insrefTo)
        Moves all messages with an insref matching insrefFrom to the Message at dst and change it to insrefTo. If dst is set to the source object or null then the change from insrefFrom to insrefTo will be done in-place.
        Parameters:
        dst - the Message to move to or null if in-place renaming of insrefs are to be done.
        insrefFrom - the insref to change from
        insrefTo - the insref to change to
        Returns:
        true if add was successfull, false if not