jrun.jms.core.client.mipc
Class IpcJmsSessionStub

java.lang.Object
  |
  +--jrun.jms.core.client.mipc.IpcJmsSessionStub
All Implemented Interfaces:
JmsSessionStubIfc, java.lang.Runnable

public class IpcJmsSessionStub
extends java.lang.Object
implements JmsSessionStubIfc, java.lang.Runnable

The client side stub implementing the JmsServerSession. All session requests are passed on to the server. This class also an IPC server connection when a listener os subscriber is set up.

Note: There is only one receive connection per client, all JmsMessages for any queue/topic that the client is interested in receiving are multiplexed on this single connection. The connection is not bi-directional, that is no replies are sent back using this connection. It is assumed that the underlying IPC protocol will confirm delivery to the client. After that it is the clients responsibility to ensure correct message processing. Durable messages are acked on a separate port, reliable messages, are not.

Version:
$Revision: 1.10 $ $Date: 2001/10/24 00:12:47 $
Author:
Jim Mourikis
See Also:
org.exolab.jms.server.mipc.IpcJmsSessionConnection, org.exolab.core.ipc.Server

Constructor Summary
IpcJmsSessionStub(IpcIfc connection, java.lang.String clientId, java.lang.String connectionId, java.lang.String sessionId)
          A new session has been established with these ids.
 
Method Summary
 void acknowledgeMessage(long clientId, java.lang.String messageId)
          Extract the destination and messageId for the message and send back an ack.
 void beforeClose()
          This method is called before the call to close, so that the stub can do some local clean up
 void close()
          Close this session.
 void commit()
          Commit the session which will send all the published messages and acknowledge all received messages
 void commit(java.lang.String[] ids)
          Commit messages on the session which will send all specified published messages and acknowledge all specified received messages
 void createBrowser(JmsQueue queue, long clientId, java.lang.String selector)
          Create a queue browser for this session.
 void createPublisher(JmsTopic topic)
          Create a new topic publisher
 void createQueue(JmsQueue queue)
          Create a new Queue.
 void createReceiver(JmsQueue queue, long clientId, java.lang.String selector)
          Create a receiver.
 void createSender(JmsQueue queue)
          Create a queue sender
 void createSubscriber(JmsTopic topic, java.lang.String name, long clientId, java.lang.String selector, boolean noLocal)
          Create a new topic subscriber
 void createTopic(JmsTopic topic)
          Create a new topic
 void deleteBrowser(long clientId)
          Delete the queue browser associated with the specified queue from the session.
 void deleteReceiver(long clientId)
          Delete the receiver for this queue.
 void deleteSubscriber(long clientId)
          Delete the subscriber for this topic
 void enableAsynchronousDelivery(long clientId, long id, boolean enable)
          Enable or disable asynchronous message delivery for a particular consumer
 java.lang.String getClientId()
          Get the client Id
protected  Logger getLogger()
          Return a reference to the logger
 java.lang.String getSessionId()
          Get the sessionId
 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 a collection of messages from the specified client upto the nominated count.
 void recover()
          Recover the session.
 void rollback()
          Rollback the session, which will not acknowledge any of the sent messages
 void rollback(java.lang.String[] ids)
          Rollback messages on the session, which will not acknowledge any of the specified sent messages
 void run()
          This is called when we start up an inbound message pump in a a separate thread.
 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 to be called when new Messages arrive from the server.
 void startMessageDelivery()
          Start message delivery for this session.
 void stopMessageDelivery()
          Stop message delivery for this session.
static void stopReceiver()
          Stop the message receiver thread.
 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
 

Constructor Detail

IpcJmsSessionStub

public IpcJmsSessionStub(IpcIfc connection,
                         java.lang.String clientId,
                         java.lang.String connectionId,
                         java.lang.String sessionId)
A new session has been established with these ids.
Parameters:
connection - The ipc connection to the server.
clientId - This clients unique id.
connectionId - This objects connection identifier.
sessionId - The unique session id for this object.
Method Detail

getClientId

public java.lang.String getClientId()
                             throws javax.jms.JMSException
Get the client Id
Specified by:
getClientId in interface JmsSessionStubIfc
Returns:
String The client id
Throws:
JMSException - On error

getSessionId

public java.lang.String getSessionId()
                              throws javax.jms.JMSException
Get the sessionId
Specified by:
getSessionId in interface JmsSessionStubIfc
Returns:
String The session id of this session
Throws:
JMSException - On error

beforeClose

public void beforeClose()
                 throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
This method is called before the call to close, so that the stub can do some local clean up
Specified by:
beforeClose in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Throws:
JMSException -  

close

public void close()
           throws javax.jms.JMSException
Close this session.
Specified by:
close in interface JmsSessionStubIfc
Throws:
JMSException - On error

acknowledgeMessage

public void acknowledgeMessage(long clientId,
                               java.lang.String messageId)
                        throws javax.jms.JMSException
Extract the destination and messageId for the message and send back an ack.
Specified by:
acknowledgeMessage in interface JmsSessionStubIfc
Parameters:
clientId - the identity ofthe client
messageId - the message identity to ack
Throws:
JMSException -  

sendMessage

public void sendMessage(javax.jms.Message message)
                 throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Send the specified message to the server. If there is any problem then throw the JMSException exception
Specified by:
sendMessage in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Parameters:
message - message to send
Throws:
JMSException -  

sendMessages

public void sendMessages(java.util.Vector messages)
                  throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Send the specified messages to the server. If there is any problem then throw the JMSException exception
Specified by:
sendMessages in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Parameters:
messages - - messages to send
Throws:
JMSException -  

receiveMessage

public javax.jms.Message receiveMessage(long clientId,
                                        long wait)
                                 throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Return the next message for the specified client. The client id maps to a consumer on the server side. The caller can also specify how long to wait if no messages are currently available. If the caller specifies 0 then the call will return immediately if there are no messages available. If the caller specified -1 then the call will block until a message becomes available.
Specified by:
receiveMessage in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Parameters:
client - the client identity
wait - the number of ms to wait. -1 means wait indefinitely.
Returns:
Message the next message or null

receiveMessages

public java.util.Vector receiveMessages(long clientId,
                                        int count)
                                 throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Return a collection of messages from the specified client upto the nominated count. This method may return less than count messages but it will never return more than count messages
Specified by:
receiveMessages in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Parameters:
client - the client identity
count - max messages to return
Returns:
Vector collection of MessageImpl objects
Throws:
JMSException -  

createQueue

public void createQueue(JmsQueue queue)
                 throws javax.jms.JMSException
Create a new Queue.
Specified by:
createQueue in interface JmsSessionStubIfc
Parameters:
queue - The queue to create.
Throws:
JMSException - On error

createTopic

public void createTopic(JmsTopic topic)
                 throws javax.jms.JMSException
Create a new topic
Specified by:
createTopic in interface JmsSessionStubIfc
Parameters:
topic - The topic to create.
Throws:
JMSException - On error

createReceiver

public void createReceiver(JmsQueue queue,
                           long clientId,
                           java.lang.String selector)
                    throws javax.jms.JMSException
Create a receiver. Get the IP address of the machine the consumer runs on, and the port it is listening too, and pass this to the server, so it can make a new dedicated connection for sending all messages to this client.
Specified by:
createReceiver in interface JmsSessionStubIfc
Parameters:
queue - The queue to listen to
clientId - The session allocated identifier
selector - The selector to filter messages (may be null)
Throws:
JMSException - On error

createSender

public void createSender(JmsQueue queue)
                  throws javax.jms.JMSException
Create a queue sender
Specified by:
createSender in interface JmsSessionStubIfc
Parameters:
queue - The queue to send messages to
Throws:
JMSException - On error

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.

Specified by:
createBrowser in interface JmsSessionStubIfc
Parameters:
queue - queue to browse
clientId - idenity of the client
selector - message selector. This may be null
Throws:
JMSException -  

deleteReceiver

public void deleteReceiver(long clientId)
                    throws javax.jms.JMSException
Delete the receiver for this queue.
Specified by:
deleteReceiver in interface JmsSessionStubIfc
Parameters:
clientId - The id of the client to delete
Throws:
JMSException - On error

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
Specified by:
deleteBrowser in interface JmsSessionStubIfc
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 new topic subscriber
Specified by:
createSubscriber in interface JmsSessionStubIfc
Parameters:
topic - The topic to subscribe to
name - The subscribers name
client - The client identity
selector - The selector to filter messages (may be null)
Throws:
JMSException - On error

createPublisher

public void createPublisher(JmsTopic topic)
                     throws javax.jms.JMSException
Create a new topic publisher
Specified by:
createPublisher in interface JmsSessionStubIfc
Parameters:
topic - The topic to publish to
Throws:
JMSException - On error

unsubscribe

public void unsubscribe(java.lang.String name)
                 throws javax.jms.JMSException
Unsubscribe a durable subscription
Specified by:
unsubscribe in interface JmsSessionStubIfc
Parameters:
name - the name used to identify the subscription
Throws:
JMSException - if the subscription cannot be removed

deleteSubscriber

public void deleteSubscriber(long clientId)
                      throws javax.jms.JMSException
Delete the subscriber for this topic
Specified by:
deleteSubscriber in interface JmsSessionStubIfc
Parameters:
clientId - - the client identity
Throws:
JMSException - On error

stopMessageDelivery

public void stopMessageDelivery()
                         throws javax.jms.JMSException
Stop message delivery for this session.
Specified by:
stopMessageDelivery in interface JmsSessionStubIfc
Throws:
JMSException - On error

startMessageDelivery

public void startMessageDelivery()
                          throws javax.jms.JMSException
Start message delivery for this session.
Specified by:
startMessageDelivery in interface JmsSessionStubIfc
Throws:
JMSException - On error

recover

public void recover()
             throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Recover the session. This means all unacknowledged messages are resent with the redelivery flag set
Specified by:
recover in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Throws:
JMSException - - if we are unable to recover

commit

public void commit(java.lang.String[] ids)
            throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Commit messages on the session which will send all specified published messages and acknowledge all specified received messages
Specified by:
commit in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Throws:
JMSException - - if we cannot commit the session

commit

public void commit()
            throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Commit the session which will send all the published messages and acknowledge all received messages
Specified by:
commit in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Throws:
JMSException - - if we cannot commit the session

rollback

public void rollback(java.lang.String[] ids)
              throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Rollback messages on the session, which will not acknowledge any of the specified sent messages
Specified by:
rollback in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Throws:
JMSException - - if there is an error with this operation

rollback

public void rollback()
              throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Rollback the session, which will not acknowledge any of the sent messages
Specified by:
rollback in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Throws:
JMSException - - if there is an error with this operation

setMessageListener

public void setMessageListener(JmsMessageListener listener)
Set a message listener to be called when new Messages arrive from the server.
Specified by:
setMessageListener in interface JmsSessionStubIfc
Parameters:
listener - A reference to the client listener.
Throws:
JMSException - On error

enableAsynchronousDelivery

public void enableAsynchronousDelivery(long clientId,
                                       long id,
                                       boolean enable)
                                throws javax.jms.JMSException
Description copied from interface: JmsSessionStubIfc
Enable or disable asynchronous message delivery for a particular consumer
Specified by:
enableAsynchronousDelivery in interface JmsSessionStubIfc
Following copied from interface: jrun.jms.core.client.JmsSessionStubIfc
Parameters:
clientId - - the id of the client to check
id - - the message id of the last delivered message
enable - - true to enable; false to disable

stopReceiver

public static void stopReceiver()
                         throws javax.jms.JMSException
Stop the message receiver thread.
Throws:
JMSException - If the IpcConnection cannot be created

run

public void run()
This is called when we start up an inbound message pump in a a separate thread. The method sits in a loop and consumes messages coming from the server.
Specified by:
run in interface java.lang.Runnable

getLogger

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


Copyright � 2002 Macromedia Corporation. All Rights Reserved.