org.exolab.jms.client
Class JmsSession

java.lang.Object
  |
  +--org.exolab.jms.client.JmsSession
All Implemented Interfaces:
JmsMessageListener, javax.jms.MessageListener, MessageSessionIfc, QueueWorker, java.lang.Runnable, javax.jms.Session
Direct Known Subclasses:
JmsQueueSession, JmsTopicSession

public abstract class JmsSession
extends java.lang.Object
implements javax.jms.Session, JmsMessageListener, MessageSessionIfc, QueueWorker

This class implements a Session interface and supports a single threaded context. A session supports multiple consumers and producers but only within the context of a single thread, which is the thread creating this object. Any attempt to use an instance of this class in a thread, aside from the one that created it will result in a MessageException

Version:
$Revision: 1.55 $ $Date: 2003/10/19 14:37:27 $
Author:
Jim Alateras, Tim Anderson

Fields inherited from interface javax.jms.Session
AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE
 
Method Summary
 void acknowledgeMessage(javax.jms.Message message)
          Acknowledge the specified message.
protected  void addConsumer(JmsMessageConsumer consumer)
          Add a consumer to the list of consumers managed by this session
protected  void addProducer(JmsMessageProducer producer)
          Add a producer to the list of producers managed by this session
protected  void checkThreadContext()
          This method checks that the thread using this object is indeed the thread that originally created this object, If this is not the case then the routine throws a JMSException indicating that the current thread is not registered to use this object This now logs a warning message, that another thread
 void close()
           
 void commit()
           
 javax.jms.BytesMessage createBytesMessage()
           
 javax.jms.MapMessage createMapMessage()
           
 javax.jms.Message createMessage()
           
 javax.jms.ObjectMessage createObjectMessage()
           
 javax.jms.ObjectMessage createObjectMessage(java.io.Serializable object)
           
 javax.jms.StreamMessage createStreamMessage()
           
 javax.jms.TextMessage createTextMessage()
           
 javax.jms.TextMessage createTextMessage(java.lang.String text)
           
 void destroy()
          Release local resources used by this session object
 void enableAsynchronousDelivery(long clientId, java.lang.String id, boolean enable)
          Enable or disable asynchronous message delivery for the specified client.
 void execute(java.lang.Object object)
          This is the called to process messages asynchronously delivered by the server.
 int getAckMode()
          Return the acknowledgement mode for the session
protected  JmsSessionStubIfc getJmsSessionStub()
          Return an instance of the remote stub.
 javax.jms.MessageListener getMessageListener()
           
protected  long getNextConsumerId()
          Returns the next seed value to be allocated to a new consumer
 java.lang.String getSessionId()
          Return a reference to the session identifier
 boolean getTransacted()
           
protected  boolean isClosed()
          Check if the session is closed
 void onMessage(javax.jms.Message message)
           
 void onMessageAvailable(long clientId)
          Inform the session that there is a message available for the message consumer with the specified identity
 void onMessages(java.util.Vector messages)
          Send the specified collection of messages to the client
 void recover()
           
protected  void removeConsumer(JmsMessageConsumer consumer)
          Remove the consumer with the specified id from the list of managed consumers
 void removeMessageListener(JmsMessageConsumer listener)
          Remove the message listener for the specified destination
protected  void removeProducer(JmsMessageProducer producer)
          Remove the producer from the list of managed producers
 javax.jms.Message retrieveMessage(long clientId, long wait)
          Fetch the next message for this client.
 java.util.Vector retrieveMessages(long clientId, int count)
          Fetch upto count messages from the endpoint.
 void rollback()
           
 void run()
           
protected  void sendMessage(javax.jms.Message message)
          Send the specified message to the server.
 void setMessageListener(JmsMessageConsumer listener)
          This will set the message listener for a particular consumer.
 void setMessageListener(javax.jms.MessageListener listener)
           
 void start()
          This will start message delivery to this session.
 void stop()
          This will stop message delivery to this session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createBytesMessage

public javax.jms.BytesMessage createBytesMessage()
                                          throws javax.jms.JMSException
Specified by:
createBytesMessage in interface javax.jms.Session

createMapMessage

public javax.jms.MapMessage createMapMessage()
                                      throws javax.jms.JMSException
Specified by:
createMapMessage in interface javax.jms.Session

createMessage

public javax.jms.Message createMessage()
                                throws javax.jms.JMSException
Specified by:
createMessage in interface javax.jms.Session

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage()
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface javax.jms.Session

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage(java.io.Serializable object)
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface javax.jms.Session

createStreamMessage

public javax.jms.StreamMessage createStreamMessage()
                                            throws javax.jms.JMSException
Specified by:
createStreamMessage in interface javax.jms.Session

createTextMessage

public javax.jms.TextMessage createTextMessage()
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface javax.jms.Session

createTextMessage

public javax.jms.TextMessage createTextMessage(java.lang.String text)
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface javax.jms.Session

getTransacted

public boolean getTransacted()
                      throws javax.jms.JMSException
Specified by:
getTransacted in interface javax.jms.Session

commit

public void commit()
            throws javax.jms.JMSException
Specified by:
commit in interface javax.jms.Session

rollback

public void rollback()
              throws javax.jms.JMSException
Specified by:
rollback in interface javax.jms.Session

close

public void close()
           throws javax.jms.JMSException
Specified by:
close in interface javax.jms.Session

recover

public void recover()
             throws javax.jms.JMSException
Specified by:
recover in interface javax.jms.Session

getMessageListener

public javax.jms.MessageListener getMessageListener()
                                             throws javax.jms.JMSException
Specified by:
getMessageListener in interface javax.jms.Session

setMessageListener

public void setMessageListener(javax.jms.MessageListener listener)
                        throws javax.jms.JMSException
Specified by:
setMessageListener in interface javax.jms.Session

run

public void run()
Specified by:
run in interface javax.jms.Session

setMessageListener

public void setMessageListener(JmsMessageConsumer listener)
                        throws javax.jms.JMSException
This will set the message listener for a particular consumer.

If a listener is already registered for the consumer, it will be automatically overwritten

Parameters:
listener - the message listener

removeMessageListener

public void removeMessageListener(JmsMessageConsumer listener)
                           throws javax.jms.JMSException
Remove the message listener for the specified destination
Parameters:
listener - the message listener

start

public void start()
           throws javax.jms.JMSException
This will start message delivery to this session. If message delivery has already started then this is a no-op.
Throws:
javax.jms.IllegalStateException - if the session is closed
javax.jms.JMSException - if message delivery can't be started

stop

public void stop()
          throws javax.jms.JMSException
This will stop message delivery to this session. If message delivery has already stoped then this is a no-op.
Throws:
javax.jms.IllegalStateException - if the session is closed
javax.jms.JMSException - if message delivery can't be stopped

acknowledgeMessage

public void acknowledgeMessage(javax.jms.Message message)
                        throws javax.jms.JMSException
Acknowledge the specified message. If the session is transacted then cache the acks until commit or rollback, otherwise just forward the ack.

Acking a message automatically acks all those that have come before it.

Specified by:
acknowledgeMessage in interface MessageSessionIfc
Parameters:
message - the message to acknowledge
Throws:
javax.jms.JMSException - if the message can't be acknowledged

enableAsynchronousDelivery

public void enableAsynchronousDelivery(long clientId,
                                       java.lang.String id,
                                       boolean enable)
                                throws javax.jms.JMSException
Enable or disable asynchronous message delivery for the specified client.
Parameters:
clientId - - the client identity
id - - the last message delivered asynchronously
enable - - true to enable; false to disable
Throws:
javax.jms.JMSException -  

onMessage

public void onMessage(javax.jms.Message message)
Specified by:
onMessage in interface javax.jms.MessageListener

onMessages

public void onMessages(java.util.Vector messages)
Description copied from interface: JmsMessageListener
Send the specified collection of messages to the client
Specified by:
onMessages in interface JmsMessageListener
Following copied from interface: org.exolab.jms.client.JmsMessageListener
Parameters:
messages - - collection of MessageHandle objects

onMessageAvailable

public void onMessageAvailable(long clientId)
Description copied from interface: JmsMessageListener
Inform the session that there is a message available for the message consumer with the specified identity
Specified by:
onMessageAvailable in interface JmsMessageListener
Following copied from interface: org.exolab.jms.client.JmsMessageListener
Parameters:
clientId - - the identity of the client

execute

public void execute(java.lang.Object object)
This is the called to process messages asynchronously delivered by the server. The session is then responsible for delivering it to the appropriate registered consumer. If it cannot resolve the consumer then it must log an exception

If the session has a registered listener then all messages will be delivered to the session's listener instead of the individual consumer message listeners.

Specified by:
execute in interface QueueWorker
Parameters:
object - received message

getSessionId

public java.lang.String getSessionId()
Return a reference to the session identifier
Returns:
String

getAckMode

public int getAckMode()
Return the acknowledgement mode for the session
Returns:
int

sendMessage

protected void sendMessage(javax.jms.Message message)
                    throws javax.jms.JMSException
Send the specified message to the server. If the message is null or there is any other problem then throw JMSException.
Parameters:
message - the message to send
Throws:
javax.jms.JMSException - if the message can't be sent

checkThreadContext

protected void checkThreadContext()
This method checks that the thread using this object is indeed the thread that originally created this object, If this is not the case then the routine throws a JMSException indicating that the current thread is not registered to use this object This now logs a warning message, that another thread

getJmsSessionStub

protected JmsSessionStubIfc getJmsSessionStub()
Return an instance of the remote stub. This is set during object creation time
Returns:
JmsSessionStubIfc

getNextConsumerId

protected long getNextConsumerId()
Returns the next seed value to be allocated to a new consumer
Returns:
a unique identifier for a consumer for this session

addConsumer

protected void addConsumer(JmsMessageConsumer consumer)
Add a consumer to the list of consumers managed by this session
Parameters:
consumer - - the consumer to add

removeConsumer

protected void removeConsumer(JmsMessageConsumer consumer)
Remove the consumer with the specified id from the list of managed consumers
Parameters:
id - - the consumer id to remove

addProducer

protected void addProducer(JmsMessageProducer producer)
Add a producer to the list of producers managed by this session
Parameters:
producer - - the producer to add

removeProducer

protected void removeProducer(JmsMessageProducer producer)
Remove the producer from the list of managed producers
Parameters:
producer - - the producer to remove

isClosed

protected final boolean isClosed()
Check if the session is closed
Returns:
true if the session is closed

retrieveMessage

public javax.jms.Message retrieveMessage(long clientId,
                                         long wait)
                                  throws javax.jms.JMSException
Fetch the next message for this client. If the session's ackMode is client acknowledge then set the session for the message, othwerwise ack the message before returning it.
Parameters:
clientId - the consumer identififer.
wait - the maximum time to wait for a message, in milliseconds. If -1, don't wait, if 0 wait indefinitely, otherwise wait the specified time.
Returns:
the received message, or null, if no message is available
Throws:
javax.jms.JMSException - if an error occurs retrieving the message

retrieveMessages

public java.util.Vector retrieveMessages(long clientId,
                                         int count)
                                  throws javax.jms.JMSException
Fetch upto count messages from the endpoint. This should only be called through JmsQueueBrowser..
Parameters:
clientId - - scoped to the session
count - - max messages to retrieve.
Returns:
Vector - the set of retrieve messages
Throws:
javax.jms.JMSException -  

destroy

public void destroy()
             throws javax.jms.JMSException
Release local resources used by this session object
Throws:
javax.jms.JMSException - - if there is a problem completing this request


Copyright © 1999-2003 The OpenJMS Group. All Rights Reserved.