|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface MessageChannel
Represents a SMA channel for message exchange.
An SMA message channel is a named conduit for message exchange between SMA messaging participants. User's open and close channels using their message bus bindings. Channel export primitives using which users can send messages to and receive messages from other messaging participants.
Each message channel maintains an outbound message queue. This queue is used to send messages through the channel. When a user wishes to send one or more messages through a channel, the user enqueues the message(s) in the outbound queue of the channel and then flushes the queue. A successful return from the flush operation guarantees that the SMA runtime has stabilized the message for delivery as per the channel's configured QOS.
Nested Class Summary | |
---|---|
static class |
MessageChannel.Qos
Enumerates the different supported Qualities of Service |
static interface |
MessageChannel.RawKeyResolutionTable
A MessageChannel.RawKeyResolutionTable is used to build a message key
from a given channel key, by providing substitution values for
variable components in the key. |
static class |
MessageChannel.State
Enumerates the different channel states. |
Field Summary | |
---|---|
static int |
ALREADY_SYNCD
Indicates that a message view has already been sync'd and need not be done so again. |
static int |
FLUSH_FORCE
Forces a flush of outbound messages buffered by a channel's binding. |
static int |
KEY_ALREADY_RESOLVED
Indicates that a message's key has already been resolved. |
static int |
SENDER_ALREADY_RESOLVED
Indicates that a message's sender has already been resolved. |
static int |
SNO_ALREADY_RESOLVED
Indicates that a message's sequence number has already been resolved. |
Method Summary | |
---|---|
void |
close()
Close a message channel. |
Object |
getAttachment()
This method is reserved for internal use. |
MessageChannelDescriptor |
getDescriptor()
Get a channel's descriptor. |
short |
getId()
Get the id of a message channel. |
Properties |
getKeyResolutionTable()
Get a channel's key resolution table. |
MessageBusBinding |
getMessageBusBinding()
Get the message bus binding to which a message channel belongs. |
String |
getName()
Get the name of a message channel. |
com.neeve.raw.RawString |
getNameAsRaw()
Get the name of a message channel as a RawString . |
MessageChannel.Qos |
getQos()
Get a channel's Qos. |
MessageChannel.RawKeyResolutionTable |
getRawKeyResolutionTable()
Get a channel's key resolution table. |
MessageChannel.State |
getState()
Get a channel's state. |
String |
getType()
Get a message channel's type. |
boolean |
isJoined()
Get whether the channel is joined. |
void |
join(int flags)
Join a message channel's inbound stream. |
void |
leave(int flags)
Leave a message channel's inbound stream. |
String |
resolveMessageKey(MessageView view,
Properties keyResolutionTable)
Resolve a message's key using the channel key. |
com.neeve.raw.RawString |
resolveMessageKeyToRaw(com.neeve.raw.RawString target,
MessageView view,
MessageChannel.RawKeyResolutionTable keyResolutionTable)
Resolve a message's key using the channel key, into the provided RawString . |
boolean |
sendMessage(MessageView view,
MessageBusBinding.FlushContext flushContext,
int flags)
Send a message. |
boolean |
sendMessage(MessageView view,
Properties keyResolutionTable,
MessageBusBinding.FlushContext flushContext,
int flags)
Send a message. |
boolean |
sendMessageWithRawKRT(MessageView view,
MessageChannel.RawKeyResolutionTable rawKeyResolutionTable,
MessageBusBinding.FlushContext flushContext,
int flags)
This method is identical to sendMessage(MessageView, Properties, com.neeve.sma.MessageBusBinding.FlushContext, int) ,
except that it accepts a MessageChannel.RawKeyResolutionTable allow the message key to be resolved without producing
garbage. |
void |
setAttachment(Object object)
This method is reserved for internal use. |
void |
setKeyResolutionTable(Properties table)
Set a channel's key resolution table. |
void |
setRawKeyResolutionTable(MessageChannel.RawKeyResolutionTable table)
Set a channel's key resolution table. |
Field Detail |
---|
static final int FLUSH_FORCE
This flag is intended for use with the sendMessage(com.neeve.sma.MessageView, java.util.Properties, com.neeve.sma.MessageBusBinding.FlushContext, int)
method. It
causes the method to forcibly invoke {#link MessageBusBinding#flush}
static final int ALREADY_SYNCD
This flag is intended for use with the sendMessage(com.neeve.sma.MessageView, java.util.Properties, com.neeve.sma.MessageBusBinding.FlushContext, int)
method. It
causes the method to not invoke {#link MessageView#sync}
static final int SENDER_ALREADY_RESOLVED
This flag is intended for use with the sendMessage(com.neeve.sma.MessageView, java.util.Properties, com.neeve.sma.MessageBusBinding.FlushContext, int)
method. It
causes the method to not go through resolving the message sender.
static final int SNO_ALREADY_RESOLVED
This flag is intended for use with the sendMessage(com.neeve.sma.MessageView, java.util.Properties, com.neeve.sma.MessageBusBinding.FlushContext, int)
method. It
causes the method to not go through resolving the message sequence number.
static final int KEY_ALREADY_RESOLVED
This flag is intended for use with the sendMessage(com.neeve.sma.MessageView, java.util.Properties, com.neeve.sma.MessageBusBinding.FlushContext, int)
method. It
causes the method to not go through the key resolution machinery.
Method Detail |
---|
void setAttachment(Object object)
Object getAttachment()
String getName()
getName
in interface com.neeve.event.IEventSource
This method can be invoked on a channel in any state.
com.neeve.raw.RawString getNameAsRaw()
RawString
.
This method can be invoked on a channel in any state.
short getId()
A message channel's id uniquely identifies a message channel within its message bus. A channel may or may not be assigned an ID. If assigned the SMA runtime will use the id to identify the channel in its bus. Otherwise it will be identified by name. The id value of a channel not assigned an id is -1.
This method can be invoked on a channel in any state.
String getType()
This method returns a string describing the channel type.
This method can be invoked on a channel in any state.
MessageChannelDescriptor getDescriptor()
This method can be invoked on a channel in any state.
MessageBusBinding getMessageBusBinding()
This method can be invoked on a channel in any state.
MessageChannel.State getState()
This method can be invoked on a channel in any state.
MessageChannel.Qos getQos()
void setKeyResolutionTable(Properties table) throws IllegalStateException
table
- The resolution table. Can be null which effectively removes
the channel's key resolution table.
IllegalStateException
- If a MessageChannel.RawKeyResolutionTable
is already installedThis method installs the channels key resolution table. This table is consulted during send while resolving a message key if a variable channel key element could not be resolved from the message being sent (either because a field with the same name as the key was not present in the message, was present but was not reflectable or had a value of null) or from the key resolution table provided to the send method.
This method can be called on a channel in any state.
A MessageChannel
cannot have both a MessageChannel.RawKeyResolutionTable
and a Properties
table. Calling setKeyResolutionTable(Properties)
and setRawKeyResolutionTable(RawKeyResolutionTable)
with non null values
will result in an IllegalStateException
Properties getKeyResolutionTable()
This method can be called on a channel in any state.
void setRawKeyResolutionTable(MessageChannel.RawKeyResolutionTable table) throws IllegalStateException
table
- The resolution table. Can be null which effectively removes
the channel's key resolution table.
IllegalStateException
- If a MessageChannel.RawKeyResolutionTable
is already installedThis method installs the channels key resolution table. This table is consulted during send while resolving a message key if a variable channel key element could not be resolved from the message being sent (either because a field with the same name as the key was not present in the message, was present but was not reflectable or had a value of null) or from the key resolution table provided to the send method.
This method can be called on a channel in any state.
AMessageChannel
cannot have both a MessageChannel.RawKeyResolutionTable
and a Properties
table. Calling setKeyResolutionTable(Properties)
and setRawKeyResolutionTable(RawKeyResolutionTable)
with non null values
will result in an IllegalStateException
MessageChannel.RawKeyResolutionTable getRawKeyResolutionTable()
This method can be called on a channel in any state.
String resolveMessageKey(MessageView view, Properties keyResolutionTable) throws SmaException
view
- The message view whose key is to be resolved.keyResolutionTable
- A table to be used during the key resolution process.
SmaException
This method is resolves a message's key by substituting variable key
elements in the channel's key from the following sources in the specified
order:
- The message contents
- The channel's key resolution table
- The key resolution table supplied to this method
The method returns null if no channel key has been set for the channel
and throws an exception if the message key could not be resolved because
one or more variable channel key elements could not be resolved from
the above listed sources.
com.neeve.raw.RawString resolveMessageKeyToRaw(com.neeve.raw.RawString target, MessageView view, MessageChannel.RawKeyResolutionTable keyResolutionTable) throws SmaException
RawString
. This
method produces the same key as resolveMessageKey(MessageView, Properties)
, but
does not produce garbage if the provided target RawString
is mutable.
target
- The message view whose key is to be resolved.view
- The message view whose key is to be resolved.keyResolutionTable
- A table to be used during the key resolution process.
RawString
containing the resolved key. If not null the returned
RawString
will be the same as that passed into the method unless the passed
in RawString
is immutable in which case a new RawString
will be
allocated.
SmaException
This method is resolves a message's key by substituting variable key
elements in the channel's key from the following sources in the specified
order:
- The message contents
- The channel's key resolution table
- The key resolution table supplied to this method
The method returns null if no channel key has been set for the channel
and throws an exception if the message key could not be resolved because
one or more variable channel key elements could not be resolved from
the above listed sources.
boolean sendMessage(MessageView view, Properties keyResolutionTable, MessageBusBinding.FlushContext flushContext, int flags) throws SmaException
view
- A message view object containing the message to be sent.keyResolutionTable
- A table to use in resolving the message's
key (from the channel key). This table only comes into play for
channels that have a key associated with them. For such channels,
this table is consulted by this method if a variable channel key
element could not be resolved from the message being sent.flushContext
- A context object indicating the IO semantics to
be used in case the channel's binding is automatically flushed from
within this method alongwith runtime context information related to
the flush. A value of null is interpreted as request for synchronous
flush (in case triggered by the method).flags
- Flags that qualify the send operation. The following flags
are permitted for use in this method:FLUSH_FORCE
ALREADY_SYNCD
SENDER_ALREADY_RESOLVED
SNO_ALREADY_RESOLVED
KEY_ALREADY_RESOLVED
SmaException
- Thrown in case an error is encountered while
enqueuing the message.
This method sends a message through a message channel. The completion of
a send call does not guarantee that the message has been transmitted
to the recipients. It is permissible for the channel's binding to
buffer sent messages to optimize transmission throughput. To ensure the
sent messages and all prior buffered messages are transmitted before
the send call returns, specify the FLUSH_FORCE
flag. The user
can also invoke MessageBusBinding.flush(com.neeve.sma.MessageBusBinding.FlushContext)
to flush all messages
buffered by a binding.
This method may choose to implicitly transmit some or all of messages
buffered by the channel's even if the FLUSH_FORCE
flag is not
specified. The caller can test the return value from this method to test
whether the method attempted to flush buffered messages or not. However,
unless the FLUSH_FORCE
flag is specified, a return value of
true does not guarantee that all buffered messages have been transmitted.
The caller should either use the force flush flag or explicitly call
MessageBusBinding.flush(com.neeve.sma.MessageBusBinding.FlushContext)
to flush all buffered messages.
This method checks for the following fields set in a message during its
processing:
key: The message key set using MessageView.setMessageKey(java.lang.String)
.
A non-null value in this parameter will override dynamic introspection
of the message and supplied key resolution tables for resolution of the
message key.
flow: The message flow set using MessageView.setMessageFlow(int)
.
Flows define order of processing. They are orthogonal to channels which
define expression of interest. A single flow can be comprised of messages
across channels. Since flows define order of processing, messages in the
same flow must be sent and received by the same thread. On the sending side,
it is the responsibility of the user to ensure that messages in the same flow
are sent by the same thread. The SMA runtime will ensure that messages on
the same flow are sent on the wire in correct sequence. On the receiving side,
the SMA runtime determines whether and how to spin up multiple threads to
process inbound traffic subject constrained by the requirement that messages
in a single flow must be dispatched by the same thread.
sno: The message sequence number set using MessageView.setMessageSequenceNumber(long)
.
A value of < 0 will cause the SMA runtime to use its internal sequence number
space.
This method can only be invoked on open channels. An exception will be thrown if invoked on channels in any other state.
boolean sendMessageWithRawKRT(MessageView view, MessageChannel.RawKeyResolutionTable rawKeyResolutionTable, MessageBusBinding.FlushContext flushContext, int flags) throws SmaException
sendMessage(MessageView, Properties, com.neeve.sma.MessageBusBinding.FlushContext, int)
,
except that it accepts a MessageChannel.RawKeyResolutionTable
allow the message key to be resolved without producing
garbage.
view
- A message view object containing the message to be sent.rawKeyResolutionTable
- A table to use in resolving the message's
key (from the channel key). This table only comes into play for
channels that have a key associated with them. For such channels,
this table is consulted by this method if a variable channel key
element could not be resolved from the message being sent.flushContext
- A context object indicating the IO semantics to
be used in case the channel's binding is automatically flushed from
within this method along with runtime context information related to
the flush. A value of null is interpreted as request for synchronous
flush (in case triggered by the method).flags
- Flags that qualify the send operation. The following flags
are permitted for use in this method:FLUSH_FORCE
ALREADY_SYNCD
SENDER_ALREADY_RESOLVED
SNO_ALREADY_RESOLVED
KEY_ALREADY_RESOLVED
SmaException
- Thrown in case an error is encountered while
enqueuing the message.boolean sendMessage(MessageView view, MessageBusBinding.FlushContext flushContext, int flags) throws SmaException
Invoking this method is equivalent to invoking
sendMessage(view, null, flushContext, flags)
SmaException
boolean isJoined()
This method can only be invoked on channels in any state.
void join(int flags) throws SmaException
flags
- Flags that qualify the join operation. Currently, there are
no flags defined. The user should specify 0 in this parameter.
SmaException
- Thrown in case an error is encountered while
joining the channel's inbound stream.This method is used to join a message channel's inbound message stream. Upon successful return from this method, messages inbound from the channel will be dispatched to the event multiplexer associated with the channel's bus binding.
This method can be invoked multiple times. The method will do nothing and return without error in case invoked on an already joined channel.
This method can only be invoked on open channels. An exception will be thrown if invoked on channels in any other state.
void leave(int flags) throws SmaException
flags
- Flags that qualify the leave operation. There are no flags
currently defined for this method.
SmaException
- Thrown in case a runtime error is encountered
while leaving the channel's inbound stream. The user should treat
the channel's inbound stream as still joined in case an exception
is thrown.This method is used to leave a message channel's inbound message stream. The method will do nothing in case invoked on a channel that has not been joined (or joined and subsequently left).
This method can only be invoked on open channels. An exception will be thrown if invoked on channels in any other state.
void close() throws SmaException
SmaException
- Thrown in case an error is encountered during
this method. The caller should treat the channel as still open
in case an exception is thrown.
This method is called by a user when it is done using a message channel.
This method will implicitly call leave(int)
in case the channel is
joined at the time this method is invoked (a failed channel is not
considered to be joined). The user should release the channel for
garbage collection after this method returns.
This method can only be invoked on open or failed channels. An exception will be thrown if invoked on channels in any other state.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |