org.exolab.jms.client
Class JmsQueueSession

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

public class JmsQueueSession
extends org.exolab.jms.client.JmsSession
implements javax.jms.QueueSession

.

Version:
$Revision: 1.21 $ $Date: 2003/01/23 04:32:19 $
Author:
Jim Alateras

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 addBrowser(org.exolab.jms.client.JmsQueueBrowser browser)
          Register the queue browser with the server.
protected  void addConsumer(JmsMessageConsumer consumer)
          Add a consumer to the list of consumers managed by this session
protected  void addMessage(javax.jms.Message message)
          Add a message to the message cache.
protected  void addProducer(JmsMessageProducer producer)
          Add a producer to the list of producers managed by this session
protected  void addReceiver(JmsQueueReceiver receiver)
          Add the specified receiver to the list of managed receivers.
protected  void addSender(JmsQueueSender sender)
          Add the specified sender to the list of managed senders.
protected  boolean checkForValidTemporaryDestination(JmsDestination destination)
          This method checks the destination.
 void close()
          Closes all queue browsers and other consumers attached to this session
 void commit()
           
 javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue)
           
 javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue, java.lang.String messageSelector)
           
 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.Queue createQueue(java.lang.String queueName)
           
 javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue)
           
 javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue, java.lang.String messageSelector)
           
 javax.jms.QueueSender createSender(javax.jms.Queue queue)
           
 javax.jms.StreamMessage createStreamMessage()
           
 javax.jms.TemporaryQueue createTemporaryQueue()
           
 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  org.exolab.jms.client.JmsConnection getConnection()
          Return a reference to the connection that created this session
protected  java.util.Enumeration getConsumers()
          Returns a list of registered consumers 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
protected  java.util.Enumeration getProducers()
          Returns a list of registered producers for the session
 java.lang.String getSessionId()
          Returns 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 removeBrowser(org.exolab.jms.client.JmsQueueBrowser browser)
          De-register the queue browser from the server.
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
protected  void removeReceiver(JmsQueueReceiver receiver)
          Remove the specified receiver to the list of managed receivers.
protected  void removeSender(JmsQueueSender sender)
          Remove the specified sender to the list of managed senders.
 javax.jms.Message retrieveMessage(long clientId, long wait)
          Fetch the next message for this client.
 java.util.Vector retrieveMessages(long clientId, int count)
          Fetch up to 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
 
Methods inherited from interface javax.jms.Session
commit, createBytesMessage, createMapMessage, createMessage, createObjectMessage, createObjectMessage, createStreamMessage, createTextMessage, createTextMessage, getMessageListener, getTransacted, recover, rollback, run, setMessageListener
 

Method Detail

createQueue

public javax.jms.Queue createQueue(java.lang.String queueName)
                            throws javax.jms.JMSException
Specified by:
createQueue in interface javax.jms.QueueSession

createReceiver

public javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue)
                                       throws javax.jms.JMSException
Specified by:
createReceiver in interface javax.jms.QueueSession

createReceiver

public javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue,
                                              java.lang.String messageSelector)
                                       throws javax.jms.JMSException
Specified by:
createReceiver in interface javax.jms.QueueSession

createSender

public javax.jms.QueueSender createSender(javax.jms.Queue queue)
                                   throws javax.jms.JMSException
Specified by:
createSender in interface javax.jms.QueueSession

createBrowser

public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue)
                                     throws javax.jms.JMSException
Specified by:
createBrowser in interface javax.jms.QueueSession

createBrowser

public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue,
                                            java.lang.String messageSelector)
                                     throws javax.jms.JMSException
Specified by:
createBrowser in interface javax.jms.QueueSession

createTemporaryQueue

public javax.jms.TemporaryQueue createTemporaryQueue()
                                              throws javax.jms.JMSException
Specified by:
createTemporaryQueue in interface javax.jms.QueueSession

close

public void close()
           throws javax.jms.JMSException
Closes all queue browsers and other consumers attached to this session
Specified by:
close in interface javax.jms.Session
Overrides:
close in class org.exolab.jms.client.JmsSession
Throws:
javax.jms.JMSException -  

addReceiver

protected void addReceiver(JmsQueueReceiver receiver)
                    throws javax.jms.JMSException
Add the specified receiver to the list of managed receivers. It does not check for duplicates. It also registers the end point with the server.

If the queue is a temporary destination then it also checks that it is owned by the session's connection before proceeding. If it owned by some other connection then a JMSException is thrown.

Parameters:
receiver - receiver to add
Throws:
javax.jms.JMSException -  

addSender

protected void addSender(JmsQueueSender sender)
                  throws javax.jms.JMSException
Add the specified sender to the list of managed senders. It does not check for duplicates. It also registers the end point with the server.
Parameters:
receiver - receiver to add

addBrowser

protected void addBrowser(org.exolab.jms.client.JmsQueueBrowser browser)
                   throws javax.jms.JMSException
Register the queue browser with the server.
Parameters:
browser - queue browser to register

removeReceiver

protected void removeReceiver(JmsQueueReceiver receiver)
                       throws javax.jms.JMSException
Remove the specified receiver to the list of managed receivers. If it does exist then fail silently.

This method will not clean up the server side reciever until the session is closed.

Parameters:
receiver - receiver to remove

removeSender

protected void removeSender(JmsQueueSender sender)
                     throws javax.jms.JMSException
Remove the specified sender to the list of managed senders. If it does exist then fail silently.
Parameters:
receiver - receiver to add

removeBrowser

protected void removeBrowser(org.exolab.jms.client.JmsQueueBrowser browser)
                      throws javax.jms.JMSException
De-register the queue browser from the server.
Parameters:
browser - queue browser to de-register

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

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.

Parameters:
object - received message

getSessionId

public java.lang.String getSessionId()
Returns the session identifier
Returns:
the session identifier

getAckMode

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

sendMessage

protected void sendMessage(javax.jms.Message message)
                    throws javax.jms.JMSException
Send the specified message to the server.
Parameters:
message - the message to send
Throws:
javax.jms.JMSException - if the message can't be sent

getJmsSessionStub

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

getConnection

protected org.exolab.jms.client.JmsConnection getConnection()
Return a reference to the connection that created this session
Returns:
the owning connection

checkForValidTemporaryDestination

protected boolean checkForValidTemporaryDestination(JmsDestination destination)
This method checks the destination. If the destination is not temporary then return true. If it is a temporary destination and it is owned by this session's connection then it returns true. If it is a tmeporary destination and it is owned by another connection then it returns false
Parameters:
destination - the destination to check
Returns:
true if the destination is valid

getProducers

protected java.util.Enumeration getProducers()
Returns a list of registered producers for the session
Returns:
an enumeration of the producers managed by the session

getConsumers

protected java.util.Enumeration getConsumers()
Returns a list of registered consumers for the session
Returns:
an enumeration of the consumers managed by the session

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 up to count messages from the endpoint. This should only be called via a JmsQueueBrowser.
Parameters:
clientId - scoped to the session
count - the max messages to retrieve.
Returns:
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

addMessage

protected void addMessage(javax.jms.Message message)
Add a message to the message cache. This message will be processed when the run() method is called.
Parameters:
message - the message to add.


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