Class Session

A Session object is a single-threaded context for producing and consuming messages.

A session serves several purposes:

A session can create and service multiple message producers and consumers.

One typical use is to have a thread block on a synchronous MessageConsumer until a message arrives. The thread may then use one or more of the Session's MessageProducers.

Once a connection has been started, any session with one or more registered message listeners is dedicated to the thread 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 thread of control. 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.

The close method is the only session method that can be called while some other session method is being executed in another thread.

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.


Field Summary
Number AUTO_ACKNOWLEDGE
          With this acknowledgment mode, the system processes acknowledgements when the consumer has successfully returned from its message handler.
Number CLIENT_ACKNOWLEDGE
          With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method.
Number DUPS_OK_ACKNOWLEDGE
          This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages.
Number SESSION_TRANSACTED
          This acknowledgement mode is used for transacted sessions.
 
Constructor Summary
Session()
            A Session object is a single-threaded context for producing and consuming messages.
 
Method Summary
 VoidFuture close(callback)
           Closes the session.
 VoidFuture commit(callback)
           Commits all messages done in this transaction and releases any locks currently held.
 BytesMessage createBytesMessage()
           Creates a BytesMessage object.
 MessageConsumer createConsumer(destination, messageSelector)
           Creates MessageConsumer for the specified destination.
 TopicSubscriber createDurableSubscriber(topic, durableName, messageSelector, noLocal)
           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.
 MapMessage createMapMessage()
           Creates a MapMessage object.
 Message createMessage()
           Creates a Message object.
 MessageProducer createProducer(destination)
           Creates a MessageProducer to send messages to the specified destination.
 Queue createQueue(queueName)
           Creates a queue identity given a Queue name.
 TemporaryQueue createTemporaryQueue()
           Creates a TemporaryQueue object.
 TemporaryTopic createTemporaryTopic()
           Creates a TemporaryTopic object.
 TextMessage createTextMessage(text)
           Creates an initialized TextMessage object.
 Topic createTopic(topicName)
           Creates a topic identity given a Topic name.
 Number getAcknowledgeMode()
           Returns the acknowledgement mode of the session.
 MessageListener getMessageListener()
           Returns the session's distinguished message listener (optional).
 boolean getTransacted()
           Indicates whether the session is in transacted mode.
 void recover()
           Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message.
 VoidFuture rollback()
           Rolls back any messages done in this transaction and releases any locks currently held.
 void setMessageListener(listener)
           Sets the session's distinguished message listener (optional).
 void unsubscribe(name)
           Unsubscribes a durable subscription that has been created by a client.
 
Field Detail

AUTO_ACKNOWLEDGE

Number AUTO_ACKNOWLEDGE

CLIENT_ACKNOWLEDGE

Number CLIENT_ACKNOWLEDGE

DUPS_OK_ACKNOWLEDGE

Number DUPS_OK_ACKNOWLEDGE

SESSION_TRANSACTED

Number SESSION_TRANSACTED

Constructor Detail

Session

Session()

Method Detail

close

VoidFuture close(callback)

commit

VoidFuture commit(callback)

createBytesMessage

BytesMessage createBytesMessage()

createConsumer

MessageConsumer createConsumer(destination, messageSelector)

createDurableSubscriber

TopicSubscriber createDurableSubscriber(topic, durableName, messageSelector, noLocal)

createMapMessage

MapMessage createMapMessage()

createMessage

Message createMessage()

createProducer

MessageProducer createProducer(destination)

createQueue

Queue createQueue(queueName)

createTemporaryQueue

TemporaryQueue createTemporaryQueue()

createTemporaryTopic

TemporaryTopic createTemporaryTopic()

createTextMessage

TextMessage createTextMessage(text)

createTopic

Topic createTopic(topicName)

getAcknowledgeMode

Number getAcknowledgeMode()

getMessageListener

MessageListener getMessageListener()

getTransacted

boolean getTransacted()

recover

void recover()

rollback

VoidFuture rollback()

setMessageListener

void setMessageListener(listener)

unsubscribe

void unsubscribe(name)