Class Message
Message objects are used to represent all outputs from the API including subscription data,
response, administrative and status messages. Message objects are obtained from a MessageIterator. A message always has a message type and may optionally contain the following
* topicName - valid for Subscription data messages
* service - The service from which this message was received from
* correlationId - one or more correlationIds if this message was
delivered for a pending request or a subscription
A Message object is a handle to a single underlying protocol message. The Message contents are represented as an Element and some convenient shortcuts are supplied to the Element accessors.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA message could be split into more than one fragments to reduce each message size.static enumSome subscription data messages (messages which originate from events with event typeEvent.EventType.SUBSCRIPTION_DATA) are recaps, which summarize the overall state of the data associated with a subscription. -
Method Summary
Modifier and TypeMethodDescriptionabstract ElementReturns the contents of this Message as a read-onlyElement.abstract CorrelationIDReturn the correlationId associated with this message.abstract CorrelationIDcorrelationID(int index) Return the correlationId associated with this message at the specified indexabstract CorrelationIDcorrelationIDAt(int index) Deprecated.abstract Message.FragmentReturn the fragment type.abstract ElementgetElement(Name name) Return the element of this message having the specified name.abstract ElementgetElement(String name) Deprecated.Use {getElement(Name)instead.abstract booleangetElementAsBool(Name name) Return the value of the element having specified name as a boolean valueabstract booleangetElementAsBool(String name) Deprecated.Use {getElementAsBool(Name)instead.abstract byte[]getElementAsBytes(Name name) Return the value of the element having specified name as a byte arrayabstract byte[]getElementAsBytes(String name) Deprecated.Use {getElementAsBytes(Name)instead.abstract chargetElementAsChar(Name name) Return the value of the element having specified name as a char valueabstract chargetElementAsChar(String name) Deprecated.Use {getElementAsChar(Name)instead.abstract DatetimegetElementAsDate(Name name) Return the value of the element having specified name as a Date valueabstract DatetimegetElementAsDate(String name) Deprecated.Use {getElementAsDate(Name)instead.abstract DatetimegetElementAsDatetime(Name name) Return the value of the element having specified name as a Datetime valueabstract DatetimegetElementAsDatetime(String name) Deprecated.Use {getElementAsDatetime(Name)instead.abstract floatgetElementAsFloat32(Name name) Return the value of the element having specified name as a float valueabstract floatgetElementAsFloat32(String name) Deprecated.Use {getElementAsFloat32(Name)instead.abstract doublegetElementAsFloat64(Name name) Return the value of the element having specified name as a double valueabstract doublegetElementAsFloat64(String name) Deprecated.Use {getElementAsFloat64(Name)instead.abstract intgetElementAsInt32(Name name) Return the value of the element having specified name as a int valueabstract intgetElementAsInt32(String name) Deprecated.Use {getElementAsInt32(Name)instead.abstract longgetElementAsInt64(Name name) Return the value of the element having specified name as a long valueabstract longgetElementAsInt64(String name) Deprecated.Use {getElementAsInt64(Name)instead.abstract NamegetElementAsName(Name name) Return the value of the element having specified name as a Constant valueabstract NamegetElementAsName(String name) Deprecated.Use {getElementAsName(Name)instead.abstract StringgetElementAsString(Name name) Return the value of the element having specified name as a String valueabstract StringgetElementAsString(String name) Deprecated.Use {getElementAsString(Name)instead.abstract DatetimegetElementAsTime(Name name) Return the value of the element having specified name as a Time valueabstract DatetimegetElementAsTime(String name) Deprecated.Use {getElementAsTime(Name)instead.abstract StringReturns the request id of the message if one exists, otherwise,null.abstract booleanhasElement(Name name) Return true if this message has the element having the specified name false otherwiseabstract booleanhasElement(Name name, boolean excludeNullElements) Return true if this message has the element having the specified name false otherwiseabstract booleanhasElement(String name) Deprecated.Use {hasElement(Name)instead.abstract booleanhasElement(String name, boolean excludeNullElements) Deprecated.Use {hasElement(Name, boolean)instead.abstract booleanisValid()abstract NameReturn the Name constant representing the type of the messageabstract intReturn the number of correlation ids associated with this message.abstract intReturn the number of elements contained by this messageabstract voidprint(OutputStream output) Prints the contents of this message to OutputStream.abstract voidPrints the contents of this message to Writer.abstract Message.RecapReturn the recap type.abstract Serviceservice()Return the Service associated with this message.abstract longReturn the time when the message was received by the SDK and '0' if there is no timestamp associated with this Message.abstract StringDeprecated.as of 3.15.0 This function has been deprecated because a message's payload can be associated with different correlation ids/subscriptions, and each of these correlation ids may map to different topic strings.abstract StringtoString()Returns the contents of this message as a String
-
Method Details
-
topicName
Deprecated.as of 3.15.0 This function has been deprecated because a message's payload can be associated with different correlation ids/subscriptions, and each of these correlation ids may map to different topic strings.In such scenarios, it will be incorrect to return one out of the topics (for the various correlation ids in the message) as the topic name for the message.
Applications should use correlation ids to map to the subscriptions.
Return the topic string associated with this message. Return an empty string if there is no topic associated with this message. -
service
Return the Service associated with this message. Return null if this method is not associated with a service -
messageType
Return the Name constant representing the type of the message -
fragmentType
Return the fragment type. The return value is a value of enum Fragment to indicate whether it is a fragmented message of a big message and its positions in fragmentation if it is. -
recapType
Return the recap type. The return value is a value ofMessage.Recapto indicate whether this message is a solicited recap, an unsolicited recap, or neither.- Returns:
- The recap type associated with this message
-
correlationID
Return the correlationId associated with this message.This is same as calling
correlationID(0). If there is more than one correlationId associated with this message return the first correlationId. If there are no correlationIds available for this message return null- Returns:
- correlationId associated with this message if available null otherwise
-
correlationIDAt
Deprecated.As of 3.2.1, usecorrelationID(int) -
correlationID
Return the correlationId associated with this message at the specified indexNormally each message is associated with only one correlationId. See "allowMultipeCorrelatorsPerMsg" option in
SessionOptionsfor more information on when multiple correlators can be returned per message- Throws:
IndexOutOfBoundsException- ifindex >=numCorrelationIds()
-
numCorrelationIds
public abstract int numCorrelationIds()Return the number of correlation ids associated with this message.Note: A Message will have exactly one CorrelationId unless "allowMultipleCorrelatorsPerMsg" option was enabled for the Session this Message came from. When allowMultipleCorrelatorsPerMsg is disabled (the default) and more than one active subscription would result in the same Message the Message is delivered multiple times (without making a physical copy). Each Message is accompanied by a single CorrelationId. When "allowMultipleCorrelatorsPerMsg" is enabled and more than one active subscription would result in the same Message the Message is delivered once with a list of corresponding CorrelationId values.
- See Also:
-
timeReceivedMillis
public abstract long timeReceivedMillis()Return the time when the message was received by the SDK and '0' if there is no timestamp associated with this Message.System.currentTimeMillis()is used to get the current time. Note that by default the subscription data messages are not timestamped (but all the other messages are). To enable recording receive time for all messages setSessionOptions.setRecordSubscriptionDataReceiveTimes(boolean). -
asElement
Returns the contents of this Message as a read-onlyElement. -
numElements
public abstract int numElements()Return the number of elements contained by this messageSame as calling
asElement().Element.numElements() -
isValid
public abstract boolean isValid() -
hasElement
Return true if this message has the element having the specified name false otherwiseSame as calling
asElement().Element.hasElement(Name) -
hasElement
Return true if this message has the element having the specified name false otherwiseSame as calling
asElement().Element.hasElement(Name, boolean) -
hasElement
Deprecated.Use {hasElement(Name)instead.Return true if this message has the element having the specified name false otherwiseSame as calling
asElement().Element.hasElement(String) -
hasElement
Deprecated.Use {hasElement(Name, boolean)instead.Return true if this message has the element having the specified name false otherwiseSame as calling
asElement().Element.hasElement(String, boolean) -
getElement
Return the element of this message having the specified name.Same as calling
asElement().Element.getElement(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified name
-
getElement
Deprecated.Use {getElement(Name)instead.Return the element of this message having the specified name.Same as calling
asElement().Element.getElement(String)- Throws:
NotFoundException- if this message does not contain an element having the specified name
-
getElementAsBool
Return the value of the element having specified name as a boolean valueSame as calling
asElement().Element.getElementAsBool(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a boolean value
-
getElementAsBool
Deprecated.Use {getElementAsBool(Name)instead.Return the value of the element having specified name as a boolean valueSame as calling
asElement().Element.getElementAsBool(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a boolean value
-
getElementAsBytes
Return the value of the element having specified name as a byte arraySame as calling
asElement().Element.getElementAsBytes(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a byte array
-
getElementAsBytes
Deprecated.Use {getElementAsBytes(Name)instead.Return the value of the element having specified name as a byte arraySame as calling
asElement().Element.getElementAsBytes(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a byte array
-
getElementAsChar
Return the value of the element having specified name as a char valueSame as calling
asElement().Element.getElementAsChar(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a char value
-
getElementAsChar
Deprecated.Use {getElementAsChar(Name)instead.Return the value of the element having specified name as a char valueSame as calling
asElement().Element.getElementAsChar(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a char value
-
getElementAsInt32
Return the value of the element having specified name as a int valueSame as calling
asElement().Element.getElementAsInt32(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a int value
-
getElementAsInt32
Deprecated.Use {getElementAsInt32(Name)instead.Return the value of the element having specified name as a int valueSame as calling
asElement().Element.getElementAsInt32(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a int value
-
getElementAsInt64
Return the value of the element having specified name as a long valueSame as calling
asElement().Element.getElementAsInt64(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a long value
-
getElementAsInt64
Deprecated.Use {getElementAsInt64(Name)instead.Return the value of the element having specified name as a long valueSame as calling
asElement().Element.getElementAsInt64(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a long value
-
getElementAsFloat64
Return the value of the element having specified name as a double valueSame as calling
asElement().Element.getElementAsFloat64(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a double value
-
getElementAsFloat64
Deprecated.Use {getElementAsFloat64(Name)instead.Return the value of the element having specified name as a double valueSame as calling
asElement().Element.getElementAsFloat64(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a double value
-
getElementAsFloat32
Return the value of the element having specified name as a float valueSame as calling
asElement().Element.getElementAsFloat32(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a float value
-
getElementAsFloat32
Deprecated.Use {getElementAsFloat32(Name)instead.Return the value of the element having specified name as a float valueSame as calling
asElement().Element.getElementAsFloat32(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a float value
-
getElementAsString
Return the value of the element having specified name as a String valueSame as calling
asElement().Element.getElementAsString(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a String value
-
getElementAsString
Deprecated.Use {getElementAsString(Name)instead.Return the value of the element having specified name as a String valueSame as calling
asElement().Element.getElementAsString(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a String value
-
getElementAsDatetime
Return the value of the element having specified name as a Datetime valueSame as calling
asElement().Element.getElementAsDatetime(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Datetime value
-
getElementAsDatetime
Deprecated.Use {getElementAsDatetime(Name)instead.Return the value of the element having specified name as a Datetime valueSame as calling
asElement().Element.getElementAsDatetime(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Datetime value
-
getElementAsDate
Return the value of the element having specified name as a Date valueSame as calling
asElement().Element.getElementAsDate(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Date value
-
getElementAsDate
Deprecated.Use {getElementAsDate(Name)instead.Return the value of the element having specified name as a Date valueSame as calling
asElement().Element.getElementAsDate(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Date value
-
getElementAsTime
Return the value of the element having specified name as a Time valueSame as calling
asElement().Element.getElementAsTime(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Time value
-
getElementAsTime
Deprecated.Use {getElementAsTime(Name)instead.Return the value of the element having specified name as a Time valueSame as calling
asElement().Element.getElementAsTime(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Time value
-
getElementAsName
Return the value of the element having specified name as a Constant valueSame as calling
asElement().Element.getElementAsName(Name)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Time value
-
getElementAsName
Deprecated.Use {getElementAsName(Name)instead.Return the value of the element having specified name as a Constant valueSame as calling
asElement().Element.getElementAsName(String)- Throws:
NotFoundException- if this message does not contain an element having the specified nameInvalidConversionException- if the value is not convertible to a Time value
-
getRequestId
Returns the request id of the message if one exists, otherwise,null.When present, the request id can be reported to Bloomberg to troubleshoot the cause of failure messages, or issues with the data contained in the message.
Note that request id is not the same as correlation id and should not be used for correlation purposes.
-
toString
Returns the contents of this message as a String -
print
Prints the contents of this message to OutputStream.- Throws:
IOException
-
print
Prints the contents of this message to Writer.- Throws:
IOException
-
correlationID(int)