org.apache.commons.messagelet
Class BridgeMDO

java.lang.Object
  extended by org.apache.commons.messagelet.MessageDrivenObjectSupport
      extended by org.apache.commons.messagelet.MessengerMDO
          extended by org.apache.commons.messagelet.BridgeMDO
All Implemented Interfaces:
javax.jms.MessageListener, MessageDrivenObject, MessengerListener
Direct Known Subclasses:
DistributeBridgeMDO

public class BridgeMDO
extends MessengerMDO

BridgeMDO is an MDO which implements a JMS bridge from one JMS destination and connection to another. This allows messages to be consumed on one destination and sent to another JMS destination, using possibly different JMS providers. For example this can be used to bridge from SpiritWave to MQSeries.

This class is a useful base class to other possible bridge implementations such as 2 phase commit bridges or bridges with some complex transformation etc. This class has a number of Factory and Strategy methods to further customize the acknowledgement and transaction management, the message construction, transformation and how to handle message headers etc.

Version:
$Revision: 1.7 $
Author:
James Strachan

Field Summary
private  int bufferSize
          the buffer size used for ByteMessage and StreamMessage copying
private static org.apache.commons.logging.Log log
          Logger
private  java.lang.String outputConnection
          the name of the messenger to use for output
private  javax.jms.Destination outputDestination
          the Destination output messages will be sent to
private  Messenger outputMessenger
          the Messenger used to output messages
private  java.lang.String outputSubject
          the name of the destination to use
private  boolean transacted
          should this MDO work in transacted mode
 
Constructor Summary
BridgeMDO()
           
 
Method Summary
protected  void acknowledge(javax.jms.Message message)
          Strategy method to allow different derived classes to acknowledge messages differently, such as to disable acknowledgements
protected  void commit()
          Strategy method to perform a commit() on both the incoming Messenger and the output Messenger.
protected  javax.jms.BytesMessage createOutputBytesMessage(javax.jms.BytesMessage inputMessage)
          Factory method to create BytesMessage Derived classes could override this method to perform any kind of Message transformation.
protected  javax.jms.MapMessage createOutputMapMessage(javax.jms.MapMessage inputMessage)
          Factory method to create MapMessage Derived classes could override this method to perform any kind of Message transformation.
protected  javax.jms.Message createOutputMessage(javax.jms.Message inputMessage)
          Factory method to create an output message given an input message.
protected  javax.jms.ObjectMessage createOutputObjectMessage(javax.jms.ObjectMessage inputMessage)
          Factory method to create ObjectMessage Derived classes could override this method to perform any kind of Message transformation.
protected  javax.jms.StreamMessage createOutputStreamMessage(javax.jms.StreamMessage inputMessage)
          Factory method to create StreamMessage Derived classes could override this method to perform any kind of Message transformation.
protected  javax.jms.TextMessage createOutputTextMessage(javax.jms.TextMessage inputMessage)
          Factory method to create TextMessage Derived classes could override this method to perform any kind of Message transformation.
 int getBufferSize()
          Gets the buffer size used for ByteMessage and StreamMessage copying
 java.lang.String getOutputConnection()
           
 javax.jms.Destination getOutputDestination()
          Gets the Destination output messages will be sent to
 Messenger getOutputMessenger()
          Gets the Messenger used to output messages
 java.lang.String getOutputSubject()
           
 void init()
          This method allows the init() method to be overriden without having to call the super.init( ServletContext ) method first.
 boolean isTransacted()
           
 void onMessage(javax.jms.Message message)
           
protected  void processMessageHeaders(javax.jms.Message inputMessage, javax.jms.Message outputMessage)
          Strategy method to add any headers required on the output message.
protected  void rollback()
          Strategy method to perform a rollback() on both the incoming Messenger and the output Messenger.
 void setBufferSize(int bufferSize)
          Sets the buffer size used for ByteMessage and StreamMessage copying
 void setOutputConnection(java.lang.String outputConnection)
          Sets the connection name (messenger instance) to use to output messages
 void setOutputDestination(javax.jms.Destination outputDestination)
          Sets the Destination output messages will be sent to
 void setOutputMessenger(Messenger outputMessenger)
          Sets the Messenger used to output messages
 void setOutputSubject(java.lang.String outputSubject)
          Sets the subject (i.e.
 void setTransacted(boolean transacted)
          Sets whether this MDO should work in transacted mode
protected  void validateOutputDestination()
          Validates that there is a valid output destintation that we can use.
 
Methods inherited from class org.apache.commons.messagelet.MessengerMDO
getMessenger, getMessengerManager, setMessenger, setMessengerManager
 
Methods inherited from class org.apache.commons.messagelet.MessageDrivenObjectSupport
destroy, getLog, getServletContext, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log
Logger


outputMessenger

private Messenger outputMessenger
the Messenger used to output messages


outputDestination

private javax.jms.Destination outputDestination
the Destination output messages will be sent to


outputConnection

private java.lang.String outputConnection
the name of the messenger to use for output


outputSubject

private java.lang.String outputSubject
the name of the destination to use


bufferSize

private int bufferSize
the buffer size used for ByteMessage and StreamMessage copying


transacted

private boolean transacted
should this MDO work in transacted mode

Constructor Detail

BridgeMDO

public BridgeMDO()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Description copied from class: MessageDrivenObjectSupport
This method allows the init() method to be overriden without having to call the super.init( ServletContext ) method first. This is similar to the init() method in GenericServlet.

Overrides:
init in class MessageDrivenObjectSupport
Throws:
javax.servlet.ServletException

onMessage

public void onMessage(javax.jms.Message message)

isTransacted

public boolean isTransacted()
Returns:
true if this MDO should work in transacted mode

setTransacted

public void setTransacted(boolean transacted)
Sets whether this MDO should work in transacted mode


getOutputConnection

public java.lang.String getOutputConnection()

setOutputConnection

public void setOutputConnection(java.lang.String outputConnection)
Sets the connection name (messenger instance) to use to output messages


getOutputSubject

public java.lang.String getOutputSubject()

setOutputSubject

public void setOutputSubject(java.lang.String outputSubject)
Sets the subject (i.e. destination name) to send messages to


getOutputMessenger

public Messenger getOutputMessenger()
                             throws javax.jms.JMSException
Gets the Messenger used to output messages

Throws:
javax.jms.JMSException

setOutputMessenger

public void setOutputMessenger(Messenger outputMessenger)
Sets the Messenger used to output messages


getOutputDestination

public javax.jms.Destination getOutputDestination()
                                           throws javax.jms.JMSException
Gets the Destination output messages will be sent to

Throws:
javax.jms.JMSException

setOutputDestination

public void setOutputDestination(javax.jms.Destination outputDestination)
Sets the Destination output messages will be sent to


getBufferSize

public int getBufferSize()
Gets the buffer size used for ByteMessage and StreamMessage copying


setBufferSize

public void setBufferSize(int bufferSize)
Sets the buffer size used for ByteMessage and StreamMessage copying


commit

protected void commit()
               throws javax.jms.JMSException
Strategy method to perform a commit() on both the incoming Messenger and the output Messenger.

Throws:
javax.jms.JMSException

rollback

protected void rollback()
Strategy method to perform a rollback() on both the incoming Messenger and the output Messenger.


createOutputMessage

protected javax.jms.Message createOutputMessage(javax.jms.Message inputMessage)
                                         throws javax.jms.JMSException
Factory method to create an output message given an input message. Derived classes could override this method to perform any kind of Message transformation.

Throws:
javax.jms.JMSException

createOutputObjectMessage

protected javax.jms.ObjectMessage createOutputObjectMessage(javax.jms.ObjectMessage inputMessage)
                                                     throws javax.jms.JMSException
Factory method to create ObjectMessage Derived classes could override this method to perform any kind of Message transformation.

Throws:
javax.jms.JMSException

createOutputTextMessage

protected javax.jms.TextMessage createOutputTextMessage(javax.jms.TextMessage inputMessage)
                                                 throws javax.jms.JMSException
Factory method to create TextMessage Derived classes could override this method to perform any kind of Message transformation.

Throws:
javax.jms.JMSException

createOutputMapMessage

protected javax.jms.MapMessage createOutputMapMessage(javax.jms.MapMessage inputMessage)
                                               throws javax.jms.JMSException
Factory method to create MapMessage Derived classes could override this method to perform any kind of Message transformation.

Throws:
javax.jms.JMSException

createOutputBytesMessage

protected javax.jms.BytesMessage createOutputBytesMessage(javax.jms.BytesMessage inputMessage)
                                                   throws javax.jms.JMSException
Factory method to create BytesMessage Derived classes could override this method to perform any kind of Message transformation.

Throws:
javax.jms.JMSException

createOutputStreamMessage

protected javax.jms.StreamMessage createOutputStreamMessage(javax.jms.StreamMessage inputMessage)
                                                     throws javax.jms.JMSException
Factory method to create StreamMessage Derived classes could override this method to perform any kind of Message transformation.

Throws:
javax.jms.JMSException

processMessageHeaders

protected void processMessageHeaders(javax.jms.Message inputMessage,
                                     javax.jms.Message outputMessage)
                              throws javax.jms.JMSException
Strategy method to add any headers required on the output message. Derived classes could override this method to perform any kind of header processing, such as copying the correlation ID, copying all headers or adding some new custom headers etc.

Throws:
javax.jms.JMSException

acknowledge

protected void acknowledge(javax.jms.Message message)
                    throws javax.jms.JMSException
Strategy method to allow different derived classes to acknowledge messages differently, such as to disable acknowledgements

Throws:
javax.jms.JMSException

validateOutputDestination

protected void validateOutputDestination()
                                  throws javax.jms.JMSException,
                                         javax.servlet.ServletException
Validates that there is a valid output destintation that we can use. Derivations of this class could use multiple destinations

Throws:
javax.jms.JMSException
javax.servlet.ServletException