public interface MessageView extends UtlReferenceTracker.HasReferenceTracker
From SMA's perspective, a message is just an object with a specific encoding e.g. a byte buffer, a hash table, an STO Container etc. A message view is an in-memory wrapper around a message that provides a specific view into the message contents. This interface defines the base class for all message views.
There are two views defined by SMA - the 'raw' view and the 'map' view.
The raw view (defined by this interface) exposes the message as an object
of a specific encoding type. No additional visibility is available with
the raw view. The map view (defined by MapMessageView
) enables a
user, in addition to seeing the raw message, to view the message as a map
i.e. a set of named fields.
Each message transported through SMA needs to be associated with a specific view. The user instantiates a view around a message and then hands the view over to one of SMAs send methods for delivery. The SMA send side machinery transports the underlying message as well as enough of information to reconsititute the send side message view on the receive side.
The SMA send and receive side machinery implement functionality conditional on the message view supplied. Some functionality requires the 'map' message view e.g. dynamic message key resolution. Functionality dependent on a specific message view will not be available for messages instantiated with message views not derived from the required message view.
Message views are instantiated by message view factories. View factories are
configured with SMA (served by MessageViewFactoryRegistry
). Each
view factory has a system wide unique id. Each instantiated view is uniquely
associated with one and only one factory. It is the id of the factory that
a view is associated that is transported by SMA along with the message. On the
receive side, the transported id is used to locate the appropriate factory
that is invoked to reconstitute the view around the message.
Modifier and Type | Field and Description |
---|---|
static int |
ENCODING_TYPE_CUSTOM
Identifies the user custom encoding type
|
static int |
ENCODING_TYPE_JSON
Identifies the 'JSON' message encoding
|
static int |
ENCODING_TYPE_PROTOBUF
Identifies the 'Protocol Buffer' message encoding
|
static int |
ENCODING_TYPE_QUARK
Identifies the 'Quark' message encoding
|
static int |
ENCODING_TYPE_XBUF
Identifies the 'X Buffer' message encoding
|
static int |
ENCODING_TYPE_XBUF2
Identifies the 'X Buffer 2' message encoding
|
static int |
NEXT_FREE_ENCODING_TYPE
Identifies the next free encoding type
|
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Increase a message view's ownership count.
|
MessageView |
deserializeFromByteArray(byte[] serializedMessage)
Deserialize a view's backing message from a byte array.
|
MessageView |
deserializeFromByteBuffer(ByteBuffer serializedMessage)
Deserialize a view's backing message from a byte buffer.
|
MessageView |
deserializeFromJson(String serializedMessage)
Deserialize a view's backing message from a json string
|
MessageView |
deserializeFromPacket(PktPacket serializedMessage)
Deserialize a view's backing message from a packet.
|
int |
dispose()
Dispose a message view.
|
long |
getAppSendBeginTs()
Get's the time at which the application considers send for a message to start.
|
long |
getAppSendDoneTs()
Get's the time at which the application considers send for a message to be complete.
|
long |
getCreateTs()
Get a message's create timestamp.
|
long |
getEnqueueTs()
Get a message's enqueue timestamp in milliseconds
|
long |
getEnqueueTsMicros()
Get a message's enqueue timestamp
This timestamp, in microseconds, specifies the time just
before a message was enqueued on an application's input queue.
|
Object |
getMessage()
Get a view's backing message.
|
String |
getMessageBus()
Get the message bus name.
|
XString |
getMessageBusAsRaw()
Get the message bus in
XString form. |
String |
getMessageChannel()
Get the message channel name.
|
XString |
getMessageChannelAsRaw()
Get the message channel in
XString form. |
int |
getMessageEncodingType()
Get the message's encoding type.
|
int |
getMessageFlow()
Get the message flow.
|
String |
getMessageKey()
Get the message key.
|
XString |
getMessageKeyAsRaw()
Get the message key.
|
int |
getMessageSender()
Get the message sender.
|
long |
getMessageSequenceNumber()
Get the message sequence number.
|
MessageTransportHeaders |
getMessageTransportHeaders()
Returns the message's transport headers.
|
long |
getOriginTs()
Get a message's origin timestamp.
|
long |
getOutTs()
Get a message's out timestamp.
|
long |
getOutTsMicros()
Get a message's out timestamp in microseconds since the epoch.
|
int |
getOwnershipCount()
Get a message view's ownership count.
|
long |
getPostDeserializeTs()
Get a message's post-deserialize timestamp.
|
long |
getPostProcessingTs()
Deprecated.
use
getPostProcessingTsMicros() instead. |
long |
getPostProcessingTsMicros()
Get a message's post-processing timestamp.
|
long |
getPostSerializeTs()
Get a message's post-serialize timestamp.
|
long |
getPostWireSendTs()
Get a message's post-wire timestamp.
|
long |
getPostWireTs()
Get a message's post-wire timestamp.
|
long |
getPreDeserializeTs()
Get a message's pre-deserialize timestamp.
|
long |
getPreProcessingTs()
Get a message's pre-processing timestamp.
|
long |
getPreProcessingTsMicros()
Get a message's pre-processing timestamp in microseconds.
|
long |
getPreSerializeTs()
Get a message's pre-serialize timestamp.
|
long |
getPreWireTs()
Get a message's pre-wire timestamp.
|
long |
getReceiveTs()
Get a message's receive timestamp.
|
long |
getSendStartTs()
Get a message's send timestamp.
|
long |
getSendTs()
Get a message's send timestamp.
|
Object |
getTag(int id)
Get a message view tag.
|
short |
getType()
Get the view type.
|
short |
getVfid()
Get the view factory identifier.
|
boolean |
isPossibleDuplicate()
Get whether a message is a possible duplicate..
|
void |
resolveMessageKeyWith(MessageChannelKeyResolver keyResolver,
MessageChannel.RawKeyResolutionTable keyResolutionTable)
Set the message key for this message using the provided keyResolver and keyResolutionTable.
|
void |
resolveMessageKeyWith(MessageChannelKeyResolver keyResolver,
Properties keyResolutionTable)
Set the message key for this message using the provided keyResolver and keyResolutionTable.
|
byte[] |
serializeToByteArray()
Serialize a view's backing message to a byte array.
|
ByteBuffer |
serializeToByteBuffer()
Serialize a view's backing message to a byte buffer.
|
com.neeve.io.IOBuffer |
serializeToIOBuffer(boolean useNative)
Serializes the
MessageView to an IOBuffer. |
String |
serializeToJson()
Serialize a view's backing message to JSON.
|
PktPacket |
serializeToPacket()
Serialize a view's backing message to a packet.
|
MessageView |
setAppSendBeginTs(long ts)
Time at which the application considers send for a message to start.
|
MessageView |
setAppSendDoneTs(long ts)
Set's the time at which the application considers send for a message to be complete.
|
MessageView |
setCreateTs(long ts)
Set a message's create timestamp.
|
MessageView |
setEnqueueTsMicros(long ts)
Sets a message's enqueue timestamp
This timestamp, in microseconds, specifies the time just
before a message was enqueued on an application's input queue.
|
MessageView |
setMessageBus(String name)
Set the message bus name.
|
MessageView |
setMessageBusAsRaw(XString bus)
Set the message bus.
|
MessageView |
setMessageChannel(String name)
Set the message channel name.
|
MessageView |
setMessageChannelAsRaw(XString channel)
Set the message channel.
|
MessageView |
setMessageFlow(int flow)
Set the message flow.
|
MessageView |
setMessageKey(String key)
Set the message key.
|
MessageView |
setMessageKeyAsRaw(XString key)
Set the message key.
|
MessageView |
setMessageSender(int sender)
Set the message sender.
|
MessageView |
setMessageSequenceNumber(long sno)
Set the message sequence number.
|
MessageView |
setMessageTransportHeaders(MessageTransportHeaders headers)
Copies the provided transport headers into this message.
|
MessageView |
setOriginTs(long ts)
Set a message's origin timestamp.
|
MessageView |
setOutTs(long ts)
Deprecated.
Use
setOutTsMicros(long) instead |
MessageView |
setOutTsMicros(long ts)
Set a message's out timestamp in microseconds since the epoch.
|
MessageView |
setPossibleDuplicate()
Set a message as a possible duplicate.
|
MessageView |
setPostDeserializeTs(long ts)
Set a message's post-deserialize timestamp.
|
MessageView |
setPostProcessingTs(long ts)
Deprecated.
use
setPostProcessingTsMicros(long) instead. |
MessageView |
setPostProcessingTsMicros(long ts)
Set a message's post-processing timestamp.
|
MessageView |
setPostSerializeTs(long ts)
Set a message's post-serialize timestamp.
|
MessageView |
setPostWireSendTs(long ts)
Set a message's post-wire send timestamp.
|
MessageView |
setPostWireTs(long ts)
Set a message's post-wire timestamp.
|
MessageView |
setPreDeserializeTs(long ts)
Set a message's pre-deserialize timestamp.
|
MessageView |
setPreProcessingTs(long ts)
Deprecated.
To prevent loss of timestamp precision use
setPreProcessingTsMicros(long) instead. |
MessageView |
setPreProcessingTsMicros(long ts)
Set a message's pre-processing timestamp in microseconds.
|
MessageView |
setPreSerializeTs(long ts)
Set a message's pre-serialize timestamp.
|
MessageView |
setPreWireTs(long ts)
Set a message's pre-wire timestamp.
|
MessageView |
setReceiveTs(long ts)
Set a message's receive timestamp.
|
MessageView |
setSendStartTs(long ts)
Set a message's send timestamp.
|
MessageView |
setSendTs(long ts)
Set a message's send timestamp.
|
void |
setTag(int id,
Object tag)
Set a message view tag.
|
void |
sync()
Ensure a view's backing message is prepared and ready for transport
|
referenceTracker
static final int ENCODING_TYPE_CUSTOM
static final int ENCODING_TYPE_QUARK
static final int ENCODING_TYPE_XBUF
static final int ENCODING_TYPE_XBUF2
static final int ENCODING_TYPE_PROTOBUF
static final int ENCODING_TYPE_JSON
static final int NEXT_FREE_ENCODING_TYPE
void setTag(int id, Object tag)
getTag(int)
A message view tag is an opaque object that can be tagged to a message
view object. Each tag is uniquely identified in the system via a numeric
value View tag ids reserved for internal use by the X Platform are
defined in MessageViewTags
.
Object getTag(int id)
setTag(int, java.lang.Object)
short getVfid()
This method returns the system wide unique identifier of the view factory that instantiated this message view.
short getType()
A message view type uniquely identifies a message within its factory.
int getMessageEncodingType()
This method returns a message's encoding type.
MessageView setMessageBus(String name)
name
- The message bus name to set.String getMessageBus()
This method returns the bus associated with a message.
MessageView setMessageBusAsRaw(XString bus)
bus
- The message bus to set.XString getMessageBusAsRaw()
XString
form.
For a received message, the bus name is set on the message using via the message bus bus binding that received it. For performance reasons a message bus implementation may not set the channel name on a received message unless it is configured to do so.
For a sent message the bus name would typically be set by the sending application when the message is sent.
MessageView setMessageChannel(String name)
name
- The message channel name to set.String getMessageChannel()
This method returns the channel associated with a message.
For a received message, the channel name is set on the message using the channel that was resolved by the message bus binding that received it. For performance reasons a message bus implementation may not set the channel name on a received message unless it is configured to do so.For a sent message the channel name would typically be set by the sending application when the message is sent.
MessageView setMessageChannelAsRaw(XString channel)
channel
- The message channel to set.XString getMessageChannelAsRaw()
XString
form.
This method returns the channel associated with a message.
Note that it is not safe to hold onto a reference to the returned XString as it is pooled with the underling message.getMessageChannel()
MessageView setMessageKey(String key)
key
- The message key to set.void resolveMessageKeyWith(MessageChannelKeyResolver keyResolver, Properties keyResolutionTable) throws SmaException
This method can be more efficient than first resolving the key using the key resolver and setting it on the message, because the message view implementation can potentially resolve the key directly into the backing buffer rather than having to copy it from a key resolved first through the key resolver.
This method is not necessarily zero garbage. For zero garbage key resolution use
#resolveMessageKeyWith(MessageChannelKeyResolver, RawKeyResolutionTable)
keyResolver
- The message key resolver used to build the key.keyResolutionTable
- The key resolution table.SmaException
- If there is an error in key resolution.MessageChannelKeyResolver.resolveMessageKey(MessageView, Properties)
String getMessageKey()
This method returns the key associated with a message.
MessageView setMessageKeyAsRaw(XString key)
key
- The message key to set.void resolveMessageKeyWith(MessageChannelKeyResolver keyResolver, MessageChannel.RawKeyResolutionTable keyResolutionTable) throws SmaException
This method can be more efficient than first resolving the key using the key resolver and setting it on the message, because the message view implementation can potentially resolve the key directly into the backing buffer rather than having to copy it from a key resolved first through the key resolver.
keyResolver
- The message key resolver used to build the key.keyResolutionTable
- The key resolution table.SmaException
- If there is an error in key resolution.MessageChannelKeyResolver#resolveMessageKey(XString, MessageView, RawKeyResolutionTable)
XString getMessageKeyAsRaw()
This method returns the key associated with a message.
Note that it is not safe to hold onto a reference to the returned XString as it is pooled with the underling message.getMessageKey()
MessageView setMessageSender(int sender)
sender
- The message sender to setint getMessageSender()
This method returns the system-wide unique sender id. Sequence numbers
returned by getMessageSequenceNumber()
are scoped by sender.
MessageTransportHeaders getMessageTransportHeaders()
Message transport headers store generic name/value pairs that are specific to a concrete messaging provider. Each message bus binding will typically support a different set of transport headers. On receipt of a message the binding pulls values off of the native message type and stores them in the transport header. For sent messages a binding implementation may support propagating values set in the transport header on the underlying native message type.
null
if transport headers are disabled, not present,
or unsupported by the MessageView
MessageView setMessageTransportHeaders(MessageTransportHeaders headers)
headers
- The headers to set on the message (or null to clear the transport headers).MessageView setMessageFlow(int flow)
flow
- The message flow to set.int getMessageFlow()
This method returns the system-wide unique flow id. Flows define the order in which messages need to be processed.
MessageView setMessageSequenceNumber(long sno)
sno
- The sequence number to set.long getMessageSequenceNumber()
This method returns the sender scoped message sequence number.
MessageView setPossibleDuplicate()
boolean isPossibleDuplicate()
MessageView setOriginTs(long ts)
ts
- The timestamp to set.long getOriginTs()
This timestamp, in microseconds, specifies the time at which the first message in this message's flow originated.
MessageView setCreateTs(long ts)
ts
- The timestamp to set.long getCreateTs()
This timestamp, in microseconds, specifies the time at which the message was created or, if the message is pooled, the time at which the message was resuscitated from its pool.
MessageView setAppSendBeginTs(long ts)
ts
- The application's send start timestamp.long getAppSendBeginTs()
This timestamp, in microseconds, specifies the time at which the send started from from the application's view point. This timestamp is the same as outTs unless an application explicitly sets it to an earlier value.
MessageView setAppSendDoneTs(long ts)
long getAppSendDoneTs()
This timestamp, in microseconds, specifies the time at which
the send completes from an application's perspective. If the message is sent
in the background this value can be lower even the getSendStartTs()
MessageView setSendTs(long ts)
ts
- The timestamp to set.long getSendTs()
This timestamp, in microseconds, specifies the time at which the message was offered to the bus for begin the send.
MessageView setSendStartTs(long ts)
ts
- The timestamp to set.long getSendStartTs()
This timestamp, in microseconds, specifies the time at which the message was offered to the bus for send.
@Deprecated MessageView setOutTs(long ts)
setOutTsMicros(long)
insteadts
- The timestamp to set.long getOutTs()
This timestamp is the same as getOutTsMicros()
/ 1000.
getOutTsMicros()
MessageView setOutTsMicros(long ts)
It is expected that this field will be set via a value obtained from
UtlTime#nowSinceEpoch()
ts
- The timestamp to set.UtlTime.nowSinceEpoch()
long getOutTsMicros()
This timestamp is the same timestamp as which an application called send to initiate the send for the message.
Note that this timestamp is not the timestamp at which a message is actually written to the wire for delivery. A sent message is queued for delivery until the transaction that is is part of is committed.
MessageView setPreSerializeTs(long ts)
ts
- The timestamp to set.long getPreSerializeTs()
This timestamp, in microseconds, specifies the time just before a message was serialized for transport.
MessageView setPostSerializeTs(long ts)
ts
- The timestamp to set.long getPostSerializeTs()
This timestamp, in microseconds, specifies the time just after a message was serialized for transport.
MessageView setPreWireTs(long ts)
This timestamp, in microseconds, specifies the time just before a message was sent on the network (the accuracy of this depends on how close to the wire the SMA binding used can timestamp the message)
ts
- The timestamp to set.long getPreWireTs()
This timestamp, in microseconds, specifies the time just before a message was sent on the network (the accuracy of this depends on how close to the wire the SMA binding used can timestamp the message).
The returned timestamp is in microseconds.
MessageView setPostWireSendTs(long ts)
ts
- The timestamp to set.long getPostWireSendTs()
This timestamp, in microseconds, specifies the time just
after the bus provider specific network send call returns.
Comparing this timestamp to getPreWireTs()
determines
the time spent in the bus provider's send call.
MessageView setPostWireTs(long ts)
ts
- The timestamp to set.long getPostWireTs()
This timestamp, in microseconds, specifies the time just after a message was received from the network (the accuracy of this depends on how close to the wire the SMA binding used can timestamp the message)
MessageView setPreDeserializeTs(long ts)
ts
- The timestamp to set.long getPreDeserializeTs()
This timestamp, in microseconds, specifies the time just before a message was de-serialized after transport.
MessageView setPostDeserializeTs(long ts)
ts
- The timestamp to set.long getPostDeserializeTs()
This timestamp, in microseconds, specifies the time just after a message was de-serialized after transport.
MessageView setReceiveTs(long ts)
ts
- The timestamp to set.long getReceiveTs()
This timestamp, in microseconds, specifies the time just before a message was received by X's application dispatch machinery. It is the same as the pre-processing timestamp if the message is not being redelivered to the application by the in-process X runtime.
long getEnqueueTs()
getEnqueueTsMicros()
MessageView setEnqueueTsMicros(long ts)
This timestamp, in microseconds, specifies the time just before a message was enqueued on an application's input queue.
ts
- the enqueue timestamp in microseconds.long getEnqueueTsMicros()
This timestamp, in microseconds, specifies the time just before a message was enqueued on an application's input queue.
This timestamp can be compared with getPreProcessingTsMicros()
to determine the amount of time that the message spent on an
application's input queue unless the application is configured to
use Event Sourcing and the message is one re-enqueued during recovery
from a transaction or received by a backup instance via replication.
@Deprecated MessageView setPreProcessingTs(long ts)
setPreProcessingTsMicros(long)
instead.ts
- The timestamp to set.long getPreProcessingTs()
This timestamp is the same as getPreProcessingTsMicros()
/ 1000.
getPreProcessingTsMicros()
MessageView setPreProcessingTsMicros(long ts)
It is expected that this field will be set via a value obtained from
UtlTime#nowSinceEpoch()
ts
- The timestamp to set.UtlTime.nowSinceEpoch()
long getPreProcessingTsMicros()
This timestamp records the time just before a message was dispatched to the application for processing.
Because the pre-processing timestamp is used to provide HA consistent time for an application that is using Event Sourcing as an HaPolicy, this value is guaranteed to be set to the same value as used on the primary instance. A backup instance or a primary recovering from a transaciton log will see the original preProcessingTs value.
@Deprecated MessageView setPostProcessingTs(long ts)
setPostProcessingTsMicros(long)
instead.ts
- The timestamp to set.@Deprecated long getPostProcessingTs()
getPostProcessingTsMicros()
instead.This timestamp, in milliseconds, specifies the time just after a message processing handler completes.
MessageView setPostProcessingTsMicros(long ts)
ts
- The timestamp to set.long getPostProcessingTsMicros()
This timestamp, in microseconds, specifies the time just after a message processing handler completes.
Object getMessage()
This method returns the actual message wrapped by the view. It is the message that is transported
void sync()
byte[] serializeToByteArray()
ByteBuffer serializeToByteBuffer()
com.neeve.io.IOBuffer serializeToIOBuffer(boolean useNative)
MessageView
to an IOBuffer.
Ownership of the returned IOBuffer is given to the caller which should dispose of it when done.
The buffer backing the IOBuffer should be flipped (ready for read) upon return.
useNative
- Whether the returned buffer should be native.MessageView
serialized to an IOBuffer.PktPacket serializeToPacket()
String serializeToJson()
Serializing/deserializing a message to/from JSON is an optional operation
MessageView deserializeFromByteArray(byte[] serializedMessage)
serializedMessage
- The view's backing message serialized as a byte array.MessageView deserializeFromByteBuffer(ByteBuffer serializedMessage)
serializedMessage
- The view's backing message serialized as a byte buffer.MessageView deserializeFromPacket(PktPacket serializedMessage)
serializedMessage
- The view's backing message serialized as a packet.MessageView deserializeFromJson(String serializedMessage)
serializedMessage
- The view's backing message serialized as a json string.
Serializing/deserializing a message to/from JSON is an optional operation
void acquire()
This method increments a message view's ownership count. View ownership
is used in conjunction with managing message view pools. If a view is
tagged to an object pool, the packet is released back to the pool
by dispose()
when the ownership count reduces to 0. If not
tagged to a pool, change of ownership count has no side effects.
A packet's ownership count starts at 1.
int getOwnershipCount()
int dispose()
This method should be invoked by the user when done with a message view. It decrements the view's ownership count and releases it to its object pool if one is tagged to it and this method cause the ownership count to reduce to zero. If not tagged to a pool, ownership change methods have no side effects aside from just updating the ownership counter.
Once disposed, all references to the disposed view should be discarded.
Copyright © 2019 Neeve Research, LLC. All Rights Reserved.