jrun.jms.core.client
Class JmsSession

jrun.jms.core.client.JmsSession
All Implemented Interfaces:
JmsMessageListener, MessageSessionIfc, QueueWorker

public abstract class JmsSession
implements 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.39 $ $Date: 2001/10/16 03:22:12 $
Author:
Jim Alateras

Field Summary
static java.lang.String MESSAGES_TO_COMMIT
           
static java.lang.String MESSAGES_TO_ROLLBACK
           
 
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
 void close()
           
 void commit()
           
 void commit(java.lang.String[] receivedMessages)
           
 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, long 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.
protected  Logger getLogger()
          Return a reference to the logger.
 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
 boolean isClosing()
           
 boolean isStopped()
          (Kint added 11/15/01) Needed so that consumers can determine if the connection is stopped so they know if non-blocking forms of receive [e.g.: receive(int timeOut) or receiveNoWait()] should return a message.
 void onMessage(javax.jms.Message message)
          This method is called when a messsges is asynchronously delivered to this session from the server.
 void onMessage(javax.jms.Message message, boolean autocommit)
          This method is called when a messsges is asynchronously delivered to this session from the ConnectionConsumer through the ServerSession pool.
 void onMessages(java.util.Vector messages)
          Process the collection of messages from the provider.
 void onMessages(java.util.Vector messages, boolean autocommit)
          Process the collection of messages from the provider.
 void processMessages()
           
 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)
          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 rollback(java.lang.String[] messages)
           
 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)
           
protected  void setParent(JmsSession session)
           
protected  void setUseByAplicationServerFacilities()
          Setst useByAplicationServerFacilities attribute, to signal that JMSsession have been used by ServerSession
 void start()
          This will start message delivery to this session.
 void stop()
          This will stop message delivery to this session.
 

Field Detail

MESSAGES_TO_COMMIT

public static final java.lang.String MESSAGES_TO_COMMIT

MESSAGES_TO_ROLLBACK

public static final java.lang.String MESSAGES_TO_ROLLBACK
Method Detail

isStopped

public boolean isStopped()
(Kint added 11/15/01) Needed so that consumers can determine if the connection is stopped so they know if non-blocking forms of receive [e.g.: receive(int timeOut) or receiveNoWait()] should return a message. The blocking form of receive and asyncronous receives using a listener already did the right thing in the case of a closed connection, but the non-blocking receives were returning a message even if the connection was closed; and that's illegal.

isClosing

public boolean isClosing()

setUseByAplicationServerFacilities

protected void setUseByAplicationServerFacilities()
Setst useByAplicationServerFacilities attribute, to signal that JMSsession have been used by ServerSession

setParent

protected void setParent(JmsSession session)

createBytesMessage

public javax.jms.BytesMessage createBytesMessage()
                                          throws javax.jms.JMSException

createMapMessage

public javax.jms.MapMessage createMapMessage()
                                      throws javax.jms.JMSException

createMessage

public javax.jms.Message createMessage()
                                throws javax.jms.JMSException

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage()
                                            throws javax.jms.JMSException

createObjectMessage

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

createStreamMessage

public javax.jms.StreamMessage createStreamMessage()
                                            throws javax.jms.JMSException

createTextMessage

public javax.jms.TextMessage createTextMessage()
                                        throws javax.jms.JMSException

createTextMessage

public javax.jms.TextMessage createTextMessage(java.lang.String text)
                                        throws javax.jms.JMSException

getTransacted

public boolean getTransacted()
                      throws javax.jms.JMSException

commit

public void commit(java.lang.String[] receivedMessages)
            throws javax.jms.JMSException

commit

public void commit()
            throws javax.jms.JMSException

rollback

public void rollback()
              throws javax.jms.JMSException

rollback

public void rollback(java.lang.String[] messages)
              throws javax.jms.JMSException

close

public void close()
           throws javax.jms.JMSException

recover

public void recover()
             throws javax.jms.JMSException

getMessageListener

public javax.jms.MessageListener getMessageListener()
                                             throws javax.jms.JMSException

setMessageListener

public void setMessageListener(javax.jms.MessageListener listener)
                        throws javax.jms.JMSException

processMessages

public void processMessages()

run

public void run()

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.If there is a problem starting message delivery then throw JMSException

It will throw a JMSException is the connection hasn't been started

Parameters:
JMSException -  

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.If there is aproblem stopping message delivery then throw JMSException
Parameters:
JMSException -  

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.

If there is any problem with the acking then throw a JMSException exception

Specified by:
acknowledgeMessage in interface MessageSessionIfc
Parameters:
message - message to acknowledge
Throws:
JMSException -  

enableAsynchronousDelivery

public void enableAsynchronousDelivery(long clientId,
                                       long 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
JMSException -  

onMessage

public void onMessage(javax.jms.Message message,
                      boolean autocommit)
This method is called when a messsges is asynchronously delivered to this session from the ConnectionConsumer through the ServerSession pool. It is stored in the incoming queue and processed later. This frees the server thread.
Parameters:
object - received message

onMessage

public void onMessage(javax.jms.Message message)
This method is called when a messsges is asynchronously delivered to this session from the server. It is stored in the incoming queue and processed later. This frees the server thread.
Parameters:
object - received message

onMessages

public void onMessages(java.util.Vector messages)
Process the collection of messages from the provider. The vector holds a set of MessageImpl objects.

These messages are added to the incoming queue and processed asynchronously

Specified by:
onMessages in interface JmsMessageListener
Parameters:
messages - - collection of messageas

onMessages

public void onMessages(java.util.Vector messages,
                       boolean autocommit)
Process the collection of messages from the provider. The vector holds a set of MessageImpl objects.

These messages are added to the incoming queue and processed asynchronously

Parameters:
messages - - collection of messageas

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 - message to send
Throws:
JMSException -  

getJmsSessionStub

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

getLogger

protected Logger getLogger()
Return a reference to the logger.
Returns:
Logger

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 boolean isClosed()
Check if the session is closed
Returns:
boolean - true if the session is closed

retrieveMessage

public javax.jms.Message retrieveMessage(long clientId)
                                  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 - - scoped to the session
Returns:
Message - the received message of null
Throws:
JMSException -  

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:
JMSException -  

destroy

public void destroy()
             throws javax.jms.JMSException
Release local resources used by this session object


Copyright � 2002 Macromedia Corporation. All Rights Reserved.