ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.util.jms
Class QueueReceiver

java.lang.Object
  extended by com.ehsbe.commons.util.jms.QueueReceiver
All Implemented Interfaces:
javax.jms.ExceptionListener

public class QueueReceiver
extends Object
implements javax.jms.ExceptionListener

Convinience class to initially setup a message consumer. NOTE: Needs to be retrofitted to glassfish - has been developed wrt. JBOSS JNLP.

Version:
$Revision: 432 $
Author:
Jens Elkner

Constructor Summary
QueueReceiver(InitialContext ctx, String destination)
          Create a new consumer container for a message queue.
 
Method Summary
 void add(javax.jms.MessageListener l)
          Add the given listener to the internal message listener list.
 void add(QueueEventListener l)
          Add the given listener to the internal queue event listener list.
 void dispose()
          Close everything and nullify all cached data.
protected  void fireMessage(javax.jms.Message msg)
          Refire a message received from the JMS queue.
protected  void fireQueueEvent(QueueEvent e)
          Fires the given event.
 String getClientID()
          Get the ID of the client connection to the server
 void onException(javax.jms.JMSException exception)
          Handles Receiver exceptions, like disconnect exceptions.
 void remove(javax.jms.MessageListener l)
          Remove the given listener from the internal message listener list.
 void remove(QueueEventListener l)
          Remove the given listener from the internal queue event listener list.
 void setReconnectIntervall(long millis)
          Set the time to wait in milliseconds, until the receivers tries to reconnect to a topic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueueReceiver

public QueueReceiver(InitialContext ctx,
                     String destination)
              throws NamingException,
                     javax.jms.JMSException
Create a new consumer container for a message queue. The connection is automatically started.

Parameters:
ctx - initial context to use for lookups
destination - the name of the destination queue - e.g. "queue/foo" or "topic/bar"
Throws:
NamingException - on context lookup errors
javax.jms.JMSException - if there are problems to create/start the connection, session, or consumer
Method Detail

dispose

public void dispose()
Close everything and nullify all cached data. After this, the object should not be used anymore.


onException

public void onException(javax.jms.JMSException exception)
Handles Receiver exceptions, like disconnect exceptions.

Informs all queue listener by sending a disconnect queue event and closes all possibly open connections. After that, a reconnect thread is started, which will send a connect message to queue listeners, when the connection to the message queue has been re-established. dispose() will stop the re-connect thread automatically.

Specified by:
onException in interface javax.jms.ExceptionListener
Parameters:
exception -

fireQueueEvent

protected void fireQueueEvent(QueueEvent e)
Fires the given event.

Parameters:
e - event to fire.

fireMessage

protected void fireMessage(javax.jms.Message msg)
Refire a message received from the JMS queue.

If the message contains a CrudEventList, all events are extracted and all QueueEventListener notified first.

Parameters:
msg - message to fire.

setReconnectIntervall

public void setReconnectIntervall(long millis)
Set the time to wait in milliseconds, until the receivers tries to reconnect to a topic.

Parameters:
millis - time in millis. If less than 1000, the default is used instead.

add

public void add(QueueEventListener l)
Add the given listener to the internal queue event listener list.

Parameters:
l - listener to add.

remove

public void remove(QueueEventListener l)
Remove the given listener from the internal queue event listener list.

Parameters:
l - listener to remove.

add

public void add(javax.jms.MessageListener l)
Add the given listener to the internal message listener list.

Parameters:
l - listener to add.

remove

public void remove(javax.jms.MessageListener l)
Remove the given listener from the internal message listener list.

Parameters:
l - listener to remove.

getClientID

public String getClientID()
Get the ID of the client connection to the server

Returns:
null if there is no connection, the id otherwise.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.