Session


public interface Session
extends java.lang.Runnable
Subinterfaces: QueueSession, TopicSession, XAQueueSession, XASession, and
XATopicSession

WebSphere MQ class: MQSession



java.lang.Object
   |
   +----com.ibm.mq.jms.MQSession

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

See also: QueueSession, TopicSession, XAQueueSession, XASession, and XATopicSession

Fields

AUTO_ACKNOWLEDGE
public static final int AUTO_ACKNOWLEDGE

With this acknowledgement mode, the session automatically acknowledges a message when it has either successfully returned from a call to receive, or the message listener it has called to process the message successfully returns.

CLIENT_ACKNOWLEDGE
public static final int CLIENT_ACKNOWLEDGE

With this acknowledgement mode, the client acknowledges a message by calling a message's acknowledge method.

DUPS_OK_ACKNOWLEDGE
public static final int DUPS_OK_ACKNOWLEDGE

This acknowledgement mode instructs the session to lazily acknowledge the delivery of messages.

Methods

close
public void close() throws JMSException

Because a provider may allocate some resources outside of the JVM on behalf of a Session, clients should close them when they are not needed. You cannot rely on garbage collection to reclaim these resources eventually, because this may not occur soon enough.

Closing a transacted session rolls back any in-progress transaction. Closing a session automatically closes its message producers and consumer, so there is no need to close them individually.

Throws:
JMSException - if the JMS implementation fails to close a Session because of an internal error.

commit
public void commit() throws JMSException

Commit all messages done in this transaction and release any locks currently held.

WebSphere MQ Event Broker note

This always throws a JMSException when you have a direct connection to WebSphere MQ Event Broker.

Throws:
  • JMSException - if JMS implementation fails to commit the transaction because of an internal error.
  • TransactionRolledBackException - if the transaction gets rolled back because of an internal error during commit.

createBytesMessage
public BytesMessage createBytesMessage()
                               throws JMSException

Create a BytesMessage. A BytesMessage is used to send a message containing a stream of uninterpreted bytes.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

createMapMessage
public MapMessage createMapMessage() throws JMSException

Create a MapMessage. A MapMessage is used to send a self-defining set of name-value pairs, where names are Strings, and values are Java primitive types.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

createMessage
public Message createMessage() throws JMSException

Create a Message. The Message interface is the root interface of all JMS messages. It holds all the standard message header information. It can be sent when a message containing only header information is sufficient.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

createObjectMessage
public ObjectMessage createObjectMessage()
                              throws JMSException

Create an ObjectMessage. An ObjectMessage is used to send a message that contains a serializable Java object.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

createObjectMessage
public ObjectMessage createObjectMessage
                             (java.io.Serializable object)
                              throws JMSException

Create an initialized ObjectMessage. An ObjectMessage is used to send a message that contains a serializable Java object.

Parameters:
object - the object to use to initialize this message.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

createStreamMessage
public StreamMessage createStreamMessage()
                               throws JMSException

Create a StreamMessage. A StreamMessage is used to send a self-defining stream of Java primitives.

Throws:
JMSException if JMS fails to create this message because of an internal error.

createTextMessage
public TextMessage createTextMessage() throws JMSException

Create a TextMessage. A TextMessage is used to send a message containing a String.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

createTextMessage
public TextMessage createTextMessage
                        (java.lang.String string)
                        throws JMSException

Create an initialized TextMessage. A TextMessage is used to send a message containing a String.

Parameters:
string - the string used to initialize this message.

Throws:
JMSException - if JMS fails to create this message because of an internal error.

getMessageListener
public MessageListener getMessageListener()
                                 throws JMSException

Return the session's distinguished message listener.

Returns:
the message listener associated with this session.

Throws:
JMSException - if JMS fails to get the message listener because of an internal error in the JMS Provider.

See also:
setMessageListener

getTransacted
public boolean getTransacted() throws JMSException

Is the session in transacted mode?

WebSphere MQ Event Broker note

This method always returns false when you have a direct connection to WebSphere MQ Event Broker.

Returns:
true if the session is in transacted mode.

Throws:
JMSException - if JMS fails to return the transaction mode because of an internal error in JMS Provider.

recover
public void recover() throws JMSException

Stop message delivery in this session, and restart sending messages with the oldest unacknowledged message.

WebSphere MQ Event Broker note

This always throws a JMSException when you have a direct connection to WebSphere MQ Event Broker.

Throws:
JMSException - if the JMS implementation fails to stop message delivery and restart message send because of an internal error.

rollback
public void rollback() throws JMSException

Roll back any messages done in this transaction and release any locks currently held.

WebSphere MQ Event Broker note

This always throws a JMSException when you have a direct connection to WebSphere MQ Event Broker.

Throws:
JMSException - if the JMS implementation fails to roll back the transaction because of an internal error.

run
public void run()

This method is intended for use only by application servers.

WebSphere MQ Event Broker note

This always throws an IllegalStateException when you have a direct connection to WebSphere MQ Event Broker.

Specified by:
run in the interface java.lang.Runnable

See also:
ServerSession

setMessageListener
public void setMessageListener(MessageListener listener)
                                            throws JMSException

Set the session's distinguished message listener. When it is set, no other form of message receipt in the session can be used. However, all forms of sending messages are still supported.

This is an expert facility that is not used by regular JMS clients.

Parameters:
listener - the message listener to associate with this session.

Throws:
JMSException - if JMS fails to set the message listener because of an internal error in the JMS Provider.

See also:
getMessageListener, ServerSessionPool, ServerSession



© IBM Corporation 1997, 2002. All Rights Reserved