com.caucho.jms.connection
Class JmsSession

java.lang.Object
  extended by com.caucho.jms.connection.JmsSession
All Implemented Interfaces:
ThreadTask, java.lang.Runnable, Session, XASession, XAResource
Direct Known Subclasses:
QueueSessionImpl, TopicSessionImpl

public class JmsSession
extends java.lang.Object
implements XASession, ThreadTask, XAResource

Manages the JMS session.


Field Summary
protected static L10N L
           
protected static java.util.logging.Logger log
           
 
Fields inherited from interface javax.jms.Session
AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, SESSION_TRANSACTED
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
JmsSession(ConnectionImpl connection, boolean isTransacted, int ackMode, boolean isXA)
           
 
Method Summary
 void acknowledge()
          Acknowledge received
 void acquireListenSemaphore()
           
protected  void addConsumer(MessageConsumerImpl consumer)
           
 void checkOpen()
          Checks that the session is open.
 void close()
          Closes the session
 void commit()
          Commits the messages.
 void commit(Xid xid, boolean onePhase)
          Called to commit.
 QueueBrowser createBrowser(Queue queue)
          Creates a QueueBrowser to browse messages in the queue.
 QueueBrowser createBrowser(Queue queue, java.lang.String messageSelector)
          Creates a QueueBrowser to browse messages in the queue.
 BytesMessage createBytesMessage()
          Creates a new byte[] message.
 MessageConsumer createConsumer(Destination destination)
          Creates a consumer to receive messages.
 MessageConsumer createConsumer(Destination destination, java.lang.String messageSelector)
          Creates a consumer to receive messages.
 MessageConsumer createConsumer(Destination destination, java.lang.String messageSelector, boolean noLocal)
          Creates a consumer to receive messages.
 TopicSubscriber createDurableSubscriber(Topic topic, java.lang.String name)
          Creates a durable subscriber to receive messages.
 TopicSubscriber createDurableSubscriber(Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal)
          Creates a subscriber to receive messages.
 MapMessage createMapMessage()
          Creates a new map message.
 Message createMessage()
          Creates a message.
 ObjectMessage createObjectMessage()
          Creates an object message.
 ObjectMessage createObjectMessage(java.io.Serializable obj)
          Creates an object message.
 MessageProducer createProducer(Destination destination)
          Creates a producer to produce messages.
 Queue createQueue(java.lang.String queueName)
          Creates a new queue.
 StreamMessage createStreamMessage()
          Creates a stream message.
 TemporaryQueue createTemporaryQueue()
          Creates a temporary queue.
 TemporaryTopic createTemporaryTopic()
          Creates a temporary topic.
 TextMessage createTextMessage()
          Creates a text message.
 TextMessage createTextMessage(java.lang.String message)
          Creates a text message.
 Topic createTopic(java.lang.String topicName)
          Creates a new topic.
 void end(Xid xid, int flags)
          Called when the resource is is done with a transaction.
 void forget(Xid xid)
          Called to forget an Xid that had a heuristic commit.
 int getAcknowledgeMode()
          Returns the acknowledge mode for the session.
 java.lang.String getClientID()
          Returns the connection's clientID
 MessageListener getMessageListener()
          Returns the message listener
 java.lang.String getPublisherId()
           
 Session getSession()
           
 boolean getTransacted()
          Returns true if the session is in a transaction.
 int getTransactionTimeout()
          Gets the transaction timeout in seconds.
 XAResource getXAResource()
           
 boolean isActive()
          Returns true if the connection is active.
 boolean isClosed()
           
 boolean isSameRM(XAResource xa)
          Returns true if the specified resource has the same RM.
 int prepare(Xid xid)
          Called to start the first phase of the commit.
 void recover()
          Recovers the messages.
 Xid[] recover(int flag)
          Called to find Xid's that need recovery.
 void releaseListenSemaphore()
           
protected  void removeConsumer(MessageConsumerImpl consumer)
           
 void rollback()
          Rollsback the messages.
 void rollback(Xid xid)
          Called to roll back.
 void rollbackImpl()
          Rollsback the messages.
 void run()
          Called to synchronously receive messages
 void send(AbstractDestination queue, Message appMessage, int deliveryMode, int priority, long timeout)
          Adds a message to the session message queue.
 void setMessageListener(MessageListener listener)
          Sets the message listener
 boolean setTransactionTimeout(int timeout)
          Sets the transaction timeout in seconds.
 void start(Xid xid, int flags)
          Called when the resource is associated with a transaction.
 java.lang.String toString()
           
 void unsubscribe(java.lang.String name)
          Unsubscribe from a durable subscription.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log

L

protected static final L10N L
Constructor Detail

JmsSession

public JmsSession(ConnectionImpl connection,
                  boolean isTransacted,
                  int ackMode,
                  boolean isXA)
           throws JMSException
Throws:
JMSException
Method Detail

getClientID

public java.lang.String getClientID()
                             throws JMSException
Returns the connection's clientID

Throws:
JMSException

getPublisherId

public java.lang.String getPublisherId()

isActive

public boolean isActive()
Returns true if the connection is active.


getTransacted

public boolean getTransacted()
                      throws JMSException
Returns true if the session is in a transaction.

Specified by:
getTransacted in interface Session
Specified by:
getTransacted in interface XASession
Throws:
JMSException

getAcknowledgeMode

public int getAcknowledgeMode()
                       throws JMSException
Returns the acknowledge mode for the session.

Specified by:
getAcknowledgeMode in interface Session
Throws:
JMSException

getMessageListener

public MessageListener getMessageListener()
                                   throws JMSException
Returns the message listener

Specified by:
getMessageListener in interface Session
Throws:
JMSException

setMessageListener

public void setMessageListener(MessageListener listener)
                        throws JMSException
Sets the message listener

Specified by:
setMessageListener in interface Session
Throws:
JMSException

createBytesMessage

public BytesMessage createBytesMessage()
                                throws JMSException
Creates a new byte[] message.

Specified by:
createBytesMessage in interface Session
Throws:
JMSException

createMapMessage

public MapMessage createMapMessage()
                            throws JMSException
Creates a new map message.

Specified by:
createMapMessage in interface Session
Throws:
JMSException

createMessage

public Message createMessage()
                      throws JMSException
Creates a message. Used when only header info is important.

Specified by:
createMessage in interface Session
Throws:
JMSException

createObjectMessage

public ObjectMessage createObjectMessage()
                                  throws JMSException
Creates an object message.

Specified by:
createObjectMessage in interface Session
Throws:
JMSException

createObjectMessage

public ObjectMessage createObjectMessage(java.io.Serializable obj)
                                  throws JMSException
Creates an object message.

Specified by:
createObjectMessage in interface Session
Parameters:
obj - a serializable message.
Throws:
JMSException

createStreamMessage

public StreamMessage createStreamMessage()
                                  throws JMSException
Creates a stream message.

Specified by:
createStreamMessage in interface Session
Throws:
JMSException

createTextMessage

public TextMessage createTextMessage()
                              throws JMSException
Creates a text message.

Specified by:
createTextMessage in interface Session
Throws:
JMSException

createTextMessage

public TextMessage createTextMessage(java.lang.String message)
                              throws JMSException
Creates a text message.

Specified by:
createTextMessage in interface Session
Throws:
JMSException

createConsumer

public MessageConsumer createConsumer(Destination destination)
                               throws JMSException
Creates a consumer to receive messages.

Specified by:
createConsumer in interface Session
Parameters:
destination - the destination to receive messages from.
Throws:
JMSException

createConsumer

public MessageConsumer createConsumer(Destination destination,
                                      java.lang.String messageSelector)
                               throws JMSException
Creates a consumer to receive messages.

Specified by:
createConsumer in interface Session
Parameters:
destination - the destination to receive messages from.
messageSelector - query to restrict the messages.
Throws:
JMSException

createConsumer

public MessageConsumer createConsumer(Destination destination,
                                      java.lang.String messageSelector,
                                      boolean noLocal)
                               throws JMSException
Creates a consumer to receive messages.

Specified by:
createConsumer in interface Session
Parameters:
destination - the destination to receive messages from.
messageSelector - query to restrict the messages.
Throws:
JMSException

createProducer

public MessageProducer createProducer(Destination destination)
                               throws JMSException
Creates a producer to produce messages.

Specified by:
createProducer in interface Session
Parameters:
destination - the destination to send messages from.
Throws:
JMSException

createBrowser

public QueueBrowser createBrowser(Queue queue)
                           throws JMSException
Creates a QueueBrowser to browse messages in the queue.

Specified by:
createBrowser in interface Session
Parameters:
queue - the queue to send messages to.
Throws:
JMSException

createBrowser

public QueueBrowser createBrowser(Queue queue,
                                  java.lang.String messageSelector)
                           throws JMSException
Creates a QueueBrowser to browse messages in the queue.

Specified by:
createBrowser in interface Session
Parameters:
queue - the queue to send messages to.
Throws:
JMSException

createQueue

public Queue createQueue(java.lang.String queueName)
                  throws JMSException
Creates a new queue.

Specified by:
createQueue in interface Session
Throws:
JMSException

createTemporaryQueue

public TemporaryQueue createTemporaryQueue()
                                    throws JMSException
Creates a temporary queue.

Specified by:
createTemporaryQueue in interface Session
Throws:
JMSException

createTopic

public Topic createTopic(java.lang.String topicName)
                  throws JMSException
Creates a new topic.

Specified by:
createTopic in interface Session
Throws:
JMSException

createTemporaryTopic

public TemporaryTopic createTemporaryTopic()
                                    throws JMSException
Creates a temporary topic.

Specified by:
createTemporaryTopic in interface Session
Throws:
JMSException

createDurableSubscriber

public TopicSubscriber createDurableSubscriber(Topic topic,
                                               java.lang.String name)
                                        throws JMSException
Creates a durable subscriber to receive messages.

Specified by:
createDurableSubscriber in interface Session
Parameters:
topic - the topic to receive messages from.
Throws:
JMSException

createDurableSubscriber

public TopicSubscriber createDurableSubscriber(Topic topic,
                                               java.lang.String name,
                                               java.lang.String messageSelector,
                                               boolean noLocal)
                                        throws JMSException
Creates a subscriber to receive messages.

Specified by:
createDurableSubscriber in interface Session
Parameters:
topic - the topic to receive messages from.
messageSelector - topic to restrict the messages.
noLocal - if true, don't receive messages we've sent
Throws:
JMSException

unsubscribe

public void unsubscribe(java.lang.String name)
                 throws JMSException
Unsubscribe from a durable subscription.

Specified by:
unsubscribe in interface Session
Throws:
JMSException

commit

public void commit()
            throws JMSException
Commits the messages.

Specified by:
commit in interface Session
Specified by:
commit in interface XASession
Throws:
JMSException

acknowledge

public void acknowledge()
                 throws JMSException
Acknowledge received

Throws:
JMSException

recover

public void recover()
             throws JMSException
Recovers the messages.

Specified by:
recover in interface Session
Throws:
JMSException

rollback

public void rollback()
              throws JMSException
Rollsback the messages.

Specified by:
rollback in interface Session
Specified by:
rollback in interface XASession
Throws:
JMSException

rollbackImpl

public void rollbackImpl()
                  throws JMSException
Rollsback the messages.

Throws:
JMSException

close

public void close()
           throws JMSException
Closes the session

Specified by:
close in interface Session
Throws:
JMSException

addConsumer

protected void addConsumer(MessageConsumerImpl consumer)

removeConsumer

protected void removeConsumer(MessageConsumerImpl consumer)

send

public void send(AbstractDestination queue,
                 Message appMessage,
                 int deliveryMode,
                 int priority,
                 long timeout)
          throws JMSException
Adds a message to the session message queue.

Throws:
JMSException

getSession

public Session getSession()
Specified by:
getSession in interface XASession

getXAResource

public XAResource getXAResource()
Specified by:
getXAResource in interface XASession

isSameRM

public boolean isSameRM(XAResource xa)
                 throws XAException
Returns true if the specified resource has the same RM.

Specified by:
isSameRM in interface XAResource
Throws:
XAException

setTransactionTimeout

public boolean setTransactionTimeout(int timeout)
                              throws XAException
Sets the transaction timeout in seconds.

Specified by:
setTransactionTimeout in interface XAResource
Throws:
XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException
Gets the transaction timeout in seconds.

Specified by:
getTransactionTimeout in interface XAResource
Throws:
XAException

start

public void start(Xid xid,
                  int flags)
           throws XAException
Called when the resource is associated with a transaction.

Specified by:
start in interface XAResource
Throws:
XAException

end

public void end(Xid xid,
                int flags)
         throws XAException
Called when the resource is is done with a transaction.

Specified by:
end in interface XAResource
Throws:
XAException

prepare

public int prepare(Xid xid)
            throws XAException
Called to start the first phase of the commit.

Specified by:
prepare in interface XAResource
Throws:
XAException

commit

public void commit(Xid xid,
                   boolean onePhase)
            throws XAException
Called to commit.

Specified by:
commit in interface XAResource
Throws:
XAException

rollback

public void rollback(Xid xid)
              throws XAException
Called to roll back.

Specified by:
rollback in interface XAResource
Throws:
XAException

forget

public void forget(Xid xid)
            throws XAException
Called to forget an Xid that had a heuristic commit.

Specified by:
forget in interface XAResource
Throws:
XAException

recover

public Xid[] recover(int flag)
              throws XAException
Called to find Xid's that need recovery.

Specified by:
recover in interface XAResource
Throws:
XAException

acquireListenSemaphore

public void acquireListenSemaphore()

releaseListenSemaphore

public void releaseListenSemaphore()

run

public void run()
Called to synchronously receive messages

Specified by:
run in interface ThreadTask
Specified by:
run in interface java.lang.Runnable
Specified by:
run in interface Session

isClosed

public boolean isClosed()

checkOpen

public void checkOpen()
               throws IllegalStateException
Checks that the session is open.

Throws:
IllegalStateException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object