Package com.millistream.www
Class Message
- java.lang.Object
-
- com.millistream.www.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 newMessage
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 thetoString()
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 matchinginsrefFrom
to the Message atdst
and change it toinsrefTo
.void
reset()
Resets the message chain so it can be reused.boolean
setCompressionLevel(int level)
Sets the compression level as used byadd_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 toadd_string
, the default is Disabled (0).java.lang.String
toString()
Serialize the message chain and return it as a base64 encoded string
-
-
-
Method Detail
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.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 classjava.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 thetoString()
method.- Parameters:
string
- a string returned from thetoString()
method of aMessage
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 byadd_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 toadd_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 toreset
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. Usemessage_reference
to define which message to send.- Parameters:
insref
- instrument referencemref
- 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. Usemessage_reference
to define which message to send.- Parameters:
insref
- instrument referencemref
- message referencedelay
- 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 callingdel()
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 addvalue
- 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 addvalue
- 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 addvalue
- the scaled integer valuedecimals
- 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 addvalue
- 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 addvalue
- 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 addyear
- the Year part of the date to addmonth
- the Month part of the date to addday
- 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 addvalue
- 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 addhour
- the Hour part of the timestampmin
- the Minutes part of the timestampsec
- the Seconds part of the timestampmsec
- 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 addhour
- the Hour part of the timestampmin
- the Minutes part of the timestampsec
- the Seconds part of the timestampnsec
- 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 theget_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 toreset
ordel
. Soget_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 matchinginsrefFrom
to the Message atdst
and change it toinsrefTo
. Ifdst
is set to the source object ornull
then the change frominsrefFrom
toinsrefTo
will be done in-place.- Parameters:
dst
- theMessage
to move to ornull
if in-place renaming of insrefs are to be done.insrefFrom
- the insref to change frominsrefTo
- the insref to change to- Returns:
- true if add was successfull, false if not
-
-