org.springframework.integration.message
Class MessageExchangeTemplate

java.lang.Object
  extended by org.springframework.integration.message.MessageExchangeTemplate
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
AsyncMessageExchangeTemplate

public class MessageExchangeTemplate
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean

This is the central class for invoking message exchange operations across PollableSources and MessageTargets. It supports one-way send and receive calls as well as request/reply. Additionally, the receiveAndForward(PollableSource, MessageTarget) method plays the role of a polling-consumer while actually sending any received message to an event-driven consumer.

To enable transactions, configure the 'transactionManager' property with a reference to an instance of Spring's PlatformTransactionManager strategy and optionally provide the other transactional attributes (e.g. 'propagationBehaviorName').

Author:
Mark Fisher

Nested Class Summary
private static class MessageExchangeTemplate.TemporaryReturnAddress
           
 
Field Summary
private  java.lang.Object initializationMonitor
           
private  boolean initialized
           
private  java.lang.String isolationLevelName
           
protected  org.apache.commons.logging.Log logger
           
private  java.lang.String propagationBehaviorName
           
private  boolean readOnly
           
private  long receiveTimeout
           
private  long sendTimeout
           
private  org.springframework.transaction.PlatformTransactionManager transactionManager
           
private  org.springframework.transaction.support.TransactionTemplate transactionTemplate
           
private  int transactionTimeout
           
 
Constructor Summary
MessageExchangeTemplate()
           
 
Method Summary
 void afterPropertiesSet()
           
private  Message<?> doReceive(PollableSource<?> source)
           
private  boolean doReceiveAndForward(PollableSource<?> source, MessageTarget target)
           
private  boolean doSend(Message<?> message, MessageTarget target)
           
private  Message<?> doSendAndReceive(Message<?> request, MessageTarget target)
           
private  org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
           
 Message<?> receive(PollableSource<?> source)
           
 boolean receiveAndForward(PollableSource<?> source, MessageTarget target)
           
 boolean send(Message<?> message, MessageTarget target)
           
 Message<?> sendAndReceive(Message<?> request, MessageTarget target)
           
 void setIsolationLevelName(java.lang.String isolationLevelName)
           
 void setPropagationBehaviorName(java.lang.String propagationBehaviorName)
           
 void setReceiveTimeout(long receiveTimeout)
          Specify the timeout value to use for receive operations.
 void setSendTimeout(long sendTimeout)
          Specify the timeout value to use for send operations.
 void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
          Specify a transaction manager to use for all exchange operations.
 void setTransactionReadOnly(boolean readOnly)
           
 void setTransactionTimeout(int transactionTimeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger

sendTimeout

private volatile long sendTimeout

receiveTimeout

private volatile long receiveTimeout

transactionManager

private volatile org.springframework.transaction.PlatformTransactionManager transactionManager

transactionTemplate

private volatile org.springframework.transaction.support.TransactionTemplate transactionTemplate

propagationBehaviorName

private volatile java.lang.String propagationBehaviorName

isolationLevelName

private volatile java.lang.String isolationLevelName

transactionTimeout

private volatile int transactionTimeout

readOnly

private volatile boolean readOnly

initialized

private volatile boolean initialized

initializationMonitor

private final java.lang.Object initializationMonitor
Constructor Detail

MessageExchangeTemplate

public MessageExchangeTemplate()
Method Detail

setSendTimeout

public void setSendTimeout(long sendTimeout)
Specify the timeout value to use for send operations. Note that this value will only apply to BlockingTargets.

Parameters:
sendTimeout - the send timeout in milliseconds

setReceiveTimeout

public void setReceiveTimeout(long receiveTimeout)
Specify the timeout value to use for receive operations. Note that this value will only apply to BlockingSources.

Parameters:
receiveTimeout - the receive timeout in milliseconds

setTransactionManager

public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
Specify a transaction manager to use for all exchange operations. If none is provided, then the operations will occur without any transactional behavior (i.e. there is no default transaction manager).


setPropagationBehaviorName

public void setPropagationBehaviorName(java.lang.String propagationBehaviorName)

setIsolationLevelName

public void setIsolationLevelName(java.lang.String isolationLevelName)

setTransactionTimeout

public void setTransactionTimeout(int transactionTimeout)

setTransactionReadOnly

public void setTransactionReadOnly(boolean readOnly)

getTransactionTemplate

private org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

send

public boolean send(Message<?> message,
                    MessageTarget target)

sendAndReceive

public Message<?> sendAndReceive(Message<?> request,
                                 MessageTarget target)

receive

public Message<?> receive(PollableSource<?> source)

receiveAndForward

public boolean receiveAndForward(PollableSource<?> source,
                                 MessageTarget target)

doSend

private boolean doSend(Message<?> message,
                       MessageTarget target)

doReceive

private Message<?> doReceive(PollableSource<?> source)

doSendAndReceive

private Message<?> doSendAndReceive(Message<?> request,
                                    MessageTarget target)

doReceiveAndForward

private boolean doReceiveAndForward(PollableSource<?> source,
                                    MessageTarget target)