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: 155459 $
Author:
James Strachan

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
 String getOutputConnection()
           
 javax.jms.Destination getOutputDestination()
          Gets the Destination output messages will be sent to
 Messenger getOutputMessenger()
          Gets the Messenger used to output messages
 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(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(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
 

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 String getOutputConnection()

setOutputConnection

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


getOutputSubject

public String getOutputSubject()

setOutputSubject

public void setOutputSubject(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


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.