jrun.jms.core.server
Class JmsServerSession

java.lang.Object
  |
  +--jrun.jms.core.server.JmsServerSession
All Implemented Interfaces:
InternalMessageListener

public class JmsServerSession
extends java.lang.Object
implements InternalMessageListener

A session represents a server side endpoint to the JMSServer. A client can create producers, consumers and destinations through the session in addi- tion to other functions. A session has a unique identifer which is a comb- ination of clientId-connectionId-sessionId.

A session represents a single-threaded context which implies that it cannot be used with more than one thread concurrently. Threads registered with this session are synchronized.

Finally, instances of this object can only be created by classes within the same package.

Version:
$Revision: 1.56 $ $Date: 2001/10/12 07:55:32 $
Author:
Jim Alateras, Tim Anderson
See Also:
org.exolab.jms.server.JmsConnection

Method Summary
 void acknowledgeMessage(long clientId, java.lang.String id)
          Acknowledge that the message with the following id has been processed
 void close()
          Close and release any resource allocated to this session.
 void commit()
          Commit this session, which will acknowledge all sent messages for all consumers.
 void commit(java.lang.String[] messages)
          Commit this session, which will acknowledge all sent messages for all consumers.
 boolean containsUnackedHandle(MessageHandle handle)
          Check if the specified message handle is in the session's list of unacked messages
 void createBrowser(JmsQueue queue, long clientId, java.lang.String selector)
          Create a queue browser for this session.
 void createPublisher(JmsTopic topic)
          This should be a no operation.
 void createQueue(JmsQueue queue)
          Create an amdinistered queue, through the message manager admin interface.
 void createReceiver(JmsQueue queue, long clientId, java.lang.String selector)
          Create a receiver endpoint for this session.
 void createSender(JmsQueue queue)
          This is a noop
 void createSubscriber(JmsTopic topic, java.lang.String name, long clientId, java.lang.String selector, boolean noLocal)
          Create a subscriber endpoint for this session.
 void createTopic(JmsTopic topic)
          Create an administered topic, through the message manager admin interface.
 void deleteBrowser(long clientId)
          Delete the queue browser associated with the specified queue from the session.
 void deletePublisher(JmsTopic topic)
          Delete the publisher associated with the specified topic from the session.
 void deleteReceiver(long clientId)
          Delete the receiver with the specified identity and clean up all associated resources.
 void deleteSender(long clientId)
          Delete the sender associated with the specified queue from the session If the corresponding sender does not exist or it cannot delete it then throw the JMSException.
 void deleteSubscriber(long clientId)
          This function deletes a persistent subsrciber and its history from the database.
 void enableAsynchronousDelivery(long clientId, long id, boolean enable)
          Check whether to enable asynchronous message delivery for a particular consumer
 java.lang.String getClientId()
          Return a reference to the client id
protected  Logger getLogger()
          Return an instance of the logger
 java.lang.String getSessionId()
          Return a reference to the session id
 boolean isClientEndpointActive()
          This will send a null message down the connection to the client to test whether the client endpoint is alive.
 void onMessage(MessageHandle handle, boolean ack)
          When consumers register message listeners then all messages for all consumers for that session will be sent through this method.
 void onMessages(java.util.Vector handles)
          This call is currently on used for the QueueBrowserEndpoint.
 javax.jms.Message receiveMessage(long clientId, long wait)
          Return the next message for the specified client.
 java.util.Vector receiveMessages(long clientId, int count)
          Return upto count messages from the endpoint with the specified client identity.
 void recover()
          Call recover on all registered consumers.
 void rollback()
          Abort, will return all unacked messages to their respective endpoints, if they are still active.
 void rollback(java.lang.String[] messages)
          Abort, will return group of unacked messages to their respective endpoints, if they are still active.
 void sendMessage(javax.jms.Message message)
          Send the specified message to the server.
 void sendMessages(java.util.Vector messages)
          Send the specified messages to the server.
 void setMessageListener(JmsMessageListener listener)
          Set a message listener for the session.
 void start()
          Start the message delivery for the session.
 void startMessageDelivery()
          Start message delivery to this session.
 void stop()
          Stop message delivery for the session
 void stopMessageDelivery()
          Stop message delivery to this session.
 void unsubscribe(java.lang.String name)
          Unsubscribe a durable subscription.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getClientId

public java.lang.String getClientId()
Return a reference to the client id
Returns:
String client id

getSessionId

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

start

public void start()
Start the message delivery for the session. If session delivery has already started then treat the operation as an no-op

stop

public void stop()
Stop message delivery for the session

close

public void close()
           throws javax.jms.JMSException
Close and release any resource allocated to this session. Throw the JMSException exception is a problem is encountered
Throws:
JMSException -  

acknowledgeMessage

public void acknowledgeMessage(long clientId,
                               java.lang.String id)
                        throws javax.jms.JMSException
Acknowledge that the message with the following id has been processed
Parameters:
clientId - - the clientId that sent the message to the client
id - - message to ack
Throws:
JMSException - - if method does not complete

sendMessage

public void sendMessage(javax.jms.Message message)
                 throws javax.jms.JMSException
Send the specified message to the server. If there is any problem then throw the JMSException exception
Parameters:
message - message to send
Throws:
JMSException -  

sendMessages

public void sendMessages(java.util.Vector messages)
                  throws javax.jms.JMSException
Send the specified messages to the server. If there is any problem then throw the JMSException exception
Parameters:
messages - messages to send
Throws:
JMSException -  

receiveMessage

public javax.jms.Message receiveMessage(long clientId,
                                        long wait)
                                 throws javax.jms.JMSException
Return the next message for the specified client. The wait parameter indicates how long many milliseconds to wait for a message before returning. If wait is 0 then do not wait at all. If wait is -1 then wait indefinitely for the next message
Parameters:
clientId - the client identity
wait - number of ms to wait
Returns:
Message the next message or null
Throws:
JMSException - if there is an app level problem

receiveMessages

public java.util.Vector receiveMessages(long clientId,
                                        int count)
                                 throws javax.jms.JMSException
Return upto count messages from the endpoint with the specified client identity. If the endpoint does not exist then throw an JMSException exception. If the endpoint is not of type QueueBrowserEndpoint then do not process the request and throw a JMSException exception. The reason for this is that this method does not take into account any acking policy. The messages are not placed on any sent list.
Parameters:
clientId - the client identity
count - the maximum number of messages retrieve
Returns:
Message the next message or null
Throws:
JMSException - if there is an app level problem

createQueue

public void createQueue(JmsQueue queue)
                 throws javax.jms.JMSException
Create an amdinistered queue, through the message manager admin interface. If it already exists then don't worry. If it cannot create the administered queue for any reason then throw the JMSException exception.
Parameters:
queue - - administered queue to create
Throws:
JMSException -  

createTopic

public void createTopic(JmsTopic topic)
                 throws javax.jms.JMSException
Create an administered topic, through the message manager admin interface. If it already exists then don't worry. If it cannot create hte administered topic for any reason then throw the JMSException exception
Parameters:
topic - - administered topic to create
Throws:
JMSException -  

createReceiver

public void createReceiver(JmsQueue queue,
                           long clientId,
                           java.lang.String selector)
                    throws javax.jms.JMSException
Create a receiver endpoint for this session. A reciever is a message consumer specific to the queue message model. The receiver is associated with a queue.

You cannot create more than one receiver for the same destination

Parameters:
queue - receiver destination
consumerId - the client session allocated identifier of the consumer
selector - the selector to filter messages. This may be null.
Throws:
JMSException. -  

createSender

public void createSender(JmsQueue queue)
                  throws javax.jms.JMSException
This is a noop

createBrowser

public void createBrowser(JmsQueue queue,
                          long clientId,
                          java.lang.String selector)
                   throws javax.jms.JMSException
Create a queue browser for this session. This allows clients to browse a queue without removing any messages.

You cannot create more than one queue browser for the same queue in a single session.

Parameters:
queue - queue to browse
clientId - the client identity
selector - message selector. This may be null
Throws:
JMSException. -  

deleteReceiver

public void deleteReceiver(long clientId)
                    throws javax.jms.JMSException
Delete the receiver with the specified identity and clean up all associated resources.
Parameters:
queue - receiver's queue
Throws:
JMSException. -  

deleteSender

public void deleteSender(long clientId)
                  throws javax.jms.JMSException
Delete the sender associated with the specified queue from the session If the corresponding sender does not exist or it cannot delete it then throw the JMSException.
Parameters:
clientId - the client identity
Throws:
JMSException. -  

deleteBrowser

public void deleteBrowser(long clientId)
                   throws javax.jms.JMSException
Delete the queue browser associated with the specified queue from the session. If the corresponding queue does not exist or it cannot be deleted, then throw a JMSException.
Parameters:
clientId - identity of the browser
Throws:
JMSException. -  

createSubscriber

public void createSubscriber(JmsTopic topic,
                             java.lang.String name,
                             long clientId,
                             java.lang.String selector,
                             boolean noLocal)
                      throws javax.jms.JMSException
Create a subscriber endpoint for this session. A subscriber is a message consumer specific to the topic message model. The subscriber is associated with a topic. Register the consumer with the message manager so that a queue can be set up for it. Finally add the consumer to the list of consumers managed by this session.

Note that the message manager manages consumers for all server sessions

You cannot create more than one subscriber for the same destination. Currently we don't check this

Parameters:
topic - subscriber destination
name - consumer name
clientId - the client session allocated identifier of the consumer
selector - the selector to filter messages. This may be null.
noLocal - true to inhibit consumption of messages published on this connection.
Throws:
JMSException. -  

createPublisher

public void createPublisher(JmsTopic topic)
                     throws javax.jms.JMSException
This should be a no operation. Do we need to maintain state information that a publisher has been created.
Parameters:
topic - receiver destination
Throws:
JMSException. -  

deleteSubscriber

public void deleteSubscriber(long clientId)
                      throws javax.jms.JMSException
This function deletes a persistent subsrciber and its history from the database. It his subscriber re-connects it get everything available for the queue topic. If the subscriber is reliable, this is a no op. See UnregisterSubscriber below for just unregistering the subscriber but leaving its persistent data in the db.

The data contains information necessary to delete the subscriber

Parameters:
clientId - the client identity
Throws:
JMSException. -  

deletePublisher

public void deletePublisher(JmsTopic topic)
                     throws javax.jms.JMSException
Delete the publisher associated with the specified topic from the session. If the corresponding publisher does not exist or it cannot delete it then throw the JMSException.
Parameters:
topic - sender destination
Throws:
JMSException. -  

unsubscribe

public void unsubscribe(java.lang.String name)
                 throws javax.jms.JMSException
Unsubscribe a durable subscription. This will delete the state of the durable subscriber maintained by the server. A durable subscriber is uniquely identifiable and the same subscriber cannot be associated with more than topic.
Parameters:
name - the name used to uniquelly identify the subscription
Throws:
JMSException - if the subscription cannot be removed or any other problem.

stopMessageDelivery

public void stopMessageDelivery()
                         throws javax.jms.JMSException
Stop message delivery to this session. If there are any problems completing the request then throw the JMSException exception
Throws:
JMSException -  

startMessageDelivery

public void startMessageDelivery()
                          throws javax.jms.JMSException
Start message delivery to this session. If there are any problems completing this request then throw the JMSException exception
Throws:
JMSException -  

containsUnackedHandle

public boolean containsUnackedHandle(MessageHandle handle)
Check if the specified message handle is in the session's list of unacked messages
Parameters:
handle - - the handle to query
Returns:
boolean - true if it is and false otherwise

onMessage

public void onMessage(MessageHandle handle,
                      boolean ack)
When consumers register message listeners then all messages for all consumers for that session will be sent through this method.
Specified by:
onMessage in interface InternalMessageListener
Parameters:
handle - - message to send
ack - - false ignores the acking policy

isClientEndpointActive

public boolean isClientEndpointActive()
This will send a null message down the connection to the client to test whether the client endpoint is alive.
Returns:
boolean - true if it is active and false otherwise.

onMessages

public void onMessages(java.util.Vector handles)
This call is currently on used for the QueueBrowserEndpoint. It is not used and should not be used for any other endpoint.
Specified by:
onMessages in interface InternalMessageListener
Parameters:
handles - - collection of handles

setMessageListener

public void setMessageListener(JmsMessageListener listener)
Set a message listener for the session. This is the channel used to asynchronously deliver messages to consumers created on this session.
Parameters:
listener - message listener

enableAsynchronousDelivery

public void enableAsynchronousDelivery(long clientId,
                                       long id,
                                       boolean enable)
                                throws javax.jms.JMSException
Check whether to enable asynchronous message delivery for a particular consumer
Parameters:
clientId - - the id of the client to check
id - - the last processed message
enable - - true to enable; false to disable

recover

public void recover()
             throws javax.jms.JMSException
Call recover on all registered consumers. This will cause all unacknowledged messages to be redelivered. Before we recover we need to stop messages delivery. We then need to start redelivery when the recovery has been completed
Throws:
JMSException - - it will throw JMSException if it cannot complete this request.

commit

public void commit(java.lang.String[] messages)
            throws javax.jms.JMSException
Commit this session, which will acknowledge all sent messages for all consumers.
Throws:
JMSException - - if there are any problems

commit

public void commit()
            throws javax.jms.JMSException
Commit this session, which will acknowledge all sent messages for all consumers.
Throws:
JMSException - - if there are any problems

rollback

public void rollback(java.lang.String[] messages)
              throws javax.jms.JMSException
Abort, will return group of unacked messages to their respective endpoints, if they are still active.
Parameters:
messages - to be returned
Throws:
JMSException - - if there are any problems

rollback

public void rollback()
              throws javax.jms.JMSException
Abort, will return all unacked messages to their respective endpoints, if they are still active.
Throws:
JMSException - - if there are any problems

getLogger

protected Logger getLogger()
Return an instance of the logger
Returns:
Logger


Copyright � 2002 Macromedia Corporation. All Rights Reserved.