| Package | com.kaazing.gateway.jms.client |
| Interface | public interface Session |
Session object is a (single-threaded) context for producing and consuming messages.
A session serves several purposes:
TemporaryTopics and
TemporaryQueues.
Queue or Topic
objects for those clients that need to dynamically manipulate
provider-specific destination names.
QueueBrowsers.
A session can create and service multiple message producers and consumers.
One typical use is to have one flow of control wait using a
MessageConsumer until a message arrives, then
use one or more of the Session's MessageProducers.
If a client desires to have one flow of execution produce messages while others consume them, the client should use a separate session for producing messages.
Once a connection has been started, any session with one or more
registered message listeners is dedicated to the flow of control that
delivers messages to it. It is erroneous for client code to use this session
or any of its constituent objects from another flow of control (execute
concurrently). The
only exception to this rule is the use of the session or connection
close method.
It should be easy for most clients to partition their work naturally into sessions. This model allows clients to start simply and incrementally add message processing complexity as their need for concurrency grows.
The close method is the only session method that can be
called while some other session method is being executed in another flow of
control.
A session may be specified as transacted. Each transacted session supports a single series of transactions. Each transaction groups a set of message sends and a set of message receives into an atomic unit of work. In effect, transactions organize a session's input message stream and output message stream into series of atomic units. When a transaction commits, its atomic unit of input is acknowledged and its associated atomic unit of output is sent. If a transaction rollback is done, the transaction's sent messages are destroyed and the session's input is automatically recovered.
The content of a transaction's input and output units is simply those messages that have been produced and consumed within the session's current transaction.
A transaction is completed using either its session's commit
method or its session's rollback method. The completion of a
session's current transaction automatically begins the next. The result is
that a transacted session always has a current transaction within which its
work is done.
The Java Transaction Service (JTS) or some other transaction monitor may
be used to combine a session's transaction with transactions on other
resources (databases, other JMS sessions, etc.). Since Java distributed
transactions are controlled via the Java Transaction API (JTA), use of the
session's commit and rollback methods in
this context is prohibited.
The JMS API does not require support for JTA; however, it does define how a provider supplies this support.
Although it is also possible for a JMS client to handle distributed transactions directly, it is unlikely that many JMS clients will do this. Support for JTA in the JMS API is targeted at systems vendors who will be integrating the JMS API into their application server products.
| Property | Defined by | ||
|---|---|---|---|
| acknowledgeMode : int [read-only] Returns the acknowledgement mode of the session.
| Session | ||
| messageListener : MessageListener
Returns the session's distinguished message listener (optional).
| Session | ||
| transacted : Boolean [read-only] Indicates whether the session is in transacted mode.
| Session | ||
| Method | Defined by | ||
|---|---|---|---|
|
close(callback:Function = null):VoidFuture
Closes the session asynchronously, meaning that the function itself
returns immediately, with close processing happening in the background,
and finally invoking the callback upon completion.
| Session | ||
|
commit(callback:Function = null):VoidFuture
Commits all messages done in this transaction and releases any locks
currently held.
| Session | ||
|
Creates a
QueueBrowser object to peek at the messages on
the specified queue using a message selector. | Session | ||
|
Creates a
BytesMessage object. | Session | ||
|
createConsumer(destination:Destination, messageSelector:String = null, noLocal:Boolean = false):MessageConsumer
Creates
MessageConsumer for the specified destination, using a
message selector. | Session | ||
|
createDurableSubscriber(topic:Topic, name:String, messageSelector:String = null, noLocal:Boolean = false):TopicSubscriber
Creates a durable subscriber to the specified topic, using a
message selector and specifying whether messages published by its
own connection should be delivered to it.
| Session | ||
|
Creates a
MapMessage object. | Session | ||
|
Creates a
Message object. | Session | ||
|
Creates a
MessageProducer to send messages to the specified
destination. | Session | ||
|
createQueue(queueName:String):Queue
Creates a queue identity given a
Queue name. | Session | ||
|
Creates a
TemporaryQueue object. | Session | ||
|
Creates a
TemporaryTopic object. | Session | ||
|
createTextMessage(text:String = null):TextMessage
Creates an initialized
TextMessage object. | Session | ||
|
createTopic(topicName:String):Topic
Creates a topic identity given a
Topic name. | Session | ||
|
recover():void
Stops message delivery in this session, and restarts message delivery
with the oldest unacknowledged message.
| Session | ||
|
rollback(callback:Function = null):VoidFuture
Rolls back any messages done in this transaction and releases any locks
currently held.
| Session | ||
|
unsubscribe(name:String):void
Unsubscribes a durable subscription that has been created by a client.
| Session | ||
| acknowledgeMode | property |
acknowledgeMode:int [read-only]Returns the acknowledgement mode of the session. The acknowledgement mode is set at the time that the session is created. If the session is transacted, the acknowledgement mode is ignored. return If the session is not transacted, returns the current acknowledgement mode for the session. If the session is transacted, returns SESSION_TRANSACTED. exception JMSException if the JMS provider fails to return the acknowledgment mode due to some internal error. see Connection#createSession since 1.1
Implementation public function get acknowledgeMode():int
| messageListener | property |
messageListener:MessageListener [read-write]Returns the session's distinguished message listener (optional).
Implementation public function get messageListener():MessageListener
public function set messageListener(value:MessageListener):void
| transacted | property |
transacted:Boolean [read-only]Indicates whether the session is in transacted mode.
Implementation public function get transacted():Boolean
| close | () | method |
public function close(callback:Function = null):VoidFutureCloses the session asynchronously, meaning that the function itself returns immediately, with close processing happening in the background, and finally invoking the callback upon completion.
Since a provider may allocate some resources on behalf of a session outside the JVM, clients should close the resources when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.
There is no need to close the producers and consumers of a closed session.
The operation does not complete until a receive call
or message listener in progress has completed. A message consumer
receive call waiting for messages asynchronously will
return null when this session is closed.
Closing a transacted session must roll back the transaction in progress.
This method is the only Session method that can
be called concurrently.
Invoking any other Session method on a closed session
must throw a JMSException.IllegalStateException. Closing a
closed session must not throw an exception.
callback:Function (default = null) — called when function has returned a value or thrown an exception
|
VoidFuture |
| commit | () | method |
public function commit(callback:Function = null):VoidFutureCommits all messages done in this transaction and releases any locks currently held. The callback is invoked when all processing has completed.
Parameterscallback:Function (default = null) — called when function has returned a value or thrown an exception
|
VoidFuture |
| createBrowser | () | method |
public function createBrowser(queue:Queue, messageSelector:String = null):QueueBrowser Creates a QueueBrowser object to peek at the messages on
the specified queue using a message selector.
queue:Queue — the queue to access
|
|
messageSelector:String (default = null) — only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.
|
QueueBrowser |
| createBytesMessage | () | method |
public function createBytesMessage():BytesMessage Creates a BytesMessage object. A BytesMessage
object is used to send a message containing a stream of uninterpreted
bytes.
BytesMessage |
| createConsumer | () | method |
public function createConsumer(destination:Destination, messageSelector:String = null, noLocal:Boolean = false):MessageConsumer Creates MessageConsumer for the specified destination, using a
message selector. This method can specify whether messages published by
its own connection should be delivered to it, if the destination is a
topic.
Since Queue and Topic
both inherit from Destination, they can be used in
the destination parameter to create a MessageConsumer.
A client uses a MessageConsumer object to receive
messages that have been published to a destination.
In some cases, a connection may both publish and subscribe to a
topic. The consumer NoLocal attribute allows a consumer
to inhibit the delivery of messages published by its own connection.
The default value for this attribute is False. The noLocal
value must be supported by destinations that are topics.
destination:Destination — the Destination to access
|
|
messageSelector:String (default = null) — only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.
|
|
noLocal:Boolean (default = false) — - if true, and the destination is a topic,
inhibits the delivery of messages published
by its own connection. The behavior for
NoLocal is
not specified if the destination is a queue.
|
MessageConsumer |
| createDurableSubscriber | () | method |
public function createDurableSubscriber(topic:Topic, name:String, messageSelector:String = null, noLocal:Boolean = false):TopicSubscriberCreates a durable subscriber to the specified topic, using a message selector and specifying whether messages published by its own connection should be delivered to it.
If a client needs to receive all the messages published on a
topic, including the ones published while the subscriber is inactive,
it uses a durable TopicSubscriber. The JMS provider
retains a record of this
durable subscription and insures that all messages from the topic's
publishers are retained until they are acknowledged by this
durable subscriber or they have expired.
Sessions with durable subscribers must always provide the same
client identifier. In addition, each client must specify a name which
uniquely identifies (within client identifier) each durable
subscription it creates. Only one session at a time can have a
TopicSubscriber for a particular durable subscription.
An inactive durable subscriber is one that exists but
does not currently have a message consumer associated with it.
A client can change an existing durable subscription by creating
a durable TopicSubscriber with the same name and a new
topic and/or
message selector. Changing a durable subscriber is equivalent to
unsubscribing (deleting) the old one and creating a new one.
topic:Topic — the non-temporary Topic to subscribe to
|
|
name:String — the name used to identify this subscription
|
|
messageSelector:String (default = null) — only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.
|
|
noLocal:Boolean (default = false) — if set, inhibits the delivery of messages published
by its own connection
|
TopicSubscriber |
| createMapMessage | () | method |
public function createMapMessage():MapMessage Creates a MapMessage object. A MapMessage
object is used to send a self-defining set of name-value pairs, where
names are String objects and values are primitive values
in the Actionscript programming language.
MapMessage |
| createMessage | () | method |
public function createMessage():Message Creates a Message object. The Message
interface is the root interface of all JMS messages. A
Message object holds all the
standard message header information. It can be sent when a message
containing only header information is sufficient.
Message |
| createProducer | () | method |
public function createProducer(destination:Destination):MessageProducer Creates a MessageProducer to send messages to the specified
destination.
A client uses a MessageProducer object to send
messages to a destination. Since Queue and Topic
both inherit from Destination, they can be used in
the destination parameter to create a MessageProducer object.
destination:Destination — the Destination to send to,
or null if this is a producer which does not have a specified
destination.
|
MessageProducer |
| createQueue | () | method |
public function createQueue(queueName:String):Queue Creates a queue identity given a Queue name.
This facility is provided for the rare cases where clients need to dynamically manipulate queue identity. It allows the creation of a queue identity with a provider-specific name. Clients that depend on this ability are not portable.
Note that this method is not for creating the physical queue.
The physical creation of queues is an administrative task and is not
to be initiated by the JMS API. The one exception is the
creation of temporary queues, which is accomplished with the
createTemporaryQueue method.
queueName:String — the name of this Queue
|
Queue —
a Queue with the given name
|
| createTemporaryQueue | () | method |
public function createTemporaryQueue():TemporaryQueue Creates a TemporaryQueue object. Its lifetime will be that
of the Connection unless it is deleted earlier.
TemporaryQueue —
a temporary queue identity
|
| createTemporaryTopic | () | method |
public function createTemporaryTopic():TemporaryTopic Creates a TemporaryTopic object. Its lifetime will be that
of the Connection unless it is deleted earlier.
TemporaryTopic —
a temporary topic identity
|
| createTextMessage | () | method |
public function createTextMessage(text:String = null):TextMessage Creates an initialized TextMessage object. A
TextMessage object is used to send
a message containing a String.
text:String (default = null) — the string used to initialize this message
|
TextMessage |
| createTopic | () | method |
public function createTopic(topicName:String):Topic Creates a topic identity given a Topic name.
This facility is provided for the rare cases where clients need to dynamically manipulate topic identity. This allows the creation of a topic identity with a provider-specific name. Clients that depend on this ability are not portable.
Note that this method is not for creating the physical topic.
The physical creation of topics is an administrative task and is not
to be initiated by the JMS API. The one exception is the
creation of temporary topics, which is accomplished with the
createTemporaryTopic method.
topicName:String — the name of this Topic
|
Topic —
a Topic with the given name
|
| recover | () | method |
public function recover():voidStops message delivery in this session, and restarts message delivery with the oldest unacknowledged message.
All consumers deliver messages in a serial order. Acknowledging a received message automatically acknowledges all messages that have been delivered to the client.
Restarting a session causes it to take the following actions:
| rollback | () | method |
public function rollback(callback:Function = null):VoidFutureRolls back any messages done in this transaction and releases any locks currently held. The callback is invoked when all processing has completed.
Parameterscallback:Function (default = null) — called when function has returned a value or thrown an exception
|
VoidFuture |
| unsubscribe | () | method |
public function unsubscribe(name:String):voidUnsubscribes a durable subscription that has been created by a client.
This method deletes the state being maintained on behalf of the subscriber by its provider.
It is erroneous for a client to delete a durable subscription
while there is an active MessageConsumer
or TopicSubscriber for the
subscription, or while a consumed message is part of a pending
transaction or has not been acknowledged in the session.
name:String — the name used to identify this subscription
|