org.springframework.integration.gateway
Class RequestReplyTemplate

java.lang.Object
  extended by org.springframework.integration.gateway.RequestReplyTemplate
All Implemented Interfaces:
MessageBusAware

public class RequestReplyTemplate
extends java.lang.Object
implements MessageBusAware

A template that facilitates the implementation of request-reply usage scenarios above one-way MessageChannels.

Author:
Mark Fisher

Nested Class Summary
private static class RequestReplyTemplate.ReplyHandlingChannelAdapter
           
 
Field Summary
private  EndpointRegistry endpointRegistry
           
private  MessageChannel replyChannel
           
private  ReplyMessageCorrelator replyMessageCorrelator
           
private  java.lang.Object replyMessageCorrelatorMonitor
           
private  long replyTimeout
           
private  MessageChannel requestChannel
           
private  long requestTimeout
           
 
Constructor Summary
RequestReplyTemplate()
           
RequestReplyTemplate(MessageChannel requestChannel)
          Create a RequestReplyTemplate that will use anonymous temporary channels for replies.
RequestReplyTemplate(MessageChannel requestChannel, MessageChannel replyChannel)
          Create a RequestReplyTemplate.
 
Method Summary
 Message<?> receive()
           
private  Message<?> receiveResponse(MessageChannel channel)
           
private  void registerReplyMessageCorrelator()
           
 Message<?> request(Message<?> message)
          Send a request message and wait for a reply message using the configured timeout values.
 boolean request(Message<?> message, ReplyHandler replyHandler)
          Send a request message whose reply should be handled be the provided callback.
 boolean send(Message<?> message)
           
private  Message<?> sendAndReceiveWithReplyMessageCorrelator(Message<?> message)
           
private  Message<?> sendAndReceiveWithTemporaryChannel(Message<?> message)
           
 void setEndpointRegistry(EndpointRegistry endpointRegistry)
           
 void setMessageBus(MessageBus messageBus)
           
 void setReplyChannel(MessageChannel replyChannel)
          Set the reply channel.
 void setReplyTimeout(long replyTimeout)
          Set the timeout value for receiving reply messages.
 void setRequestChannel(MessageChannel requestChannel)
          Set the request channel.
 void setRequestTimeout(long requestTimeout)
          Set the timeout value for sending request messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestChannel

private MessageChannel requestChannel

replyChannel

private MessageChannel replyChannel

requestTimeout

private volatile long requestTimeout

replyTimeout

private volatile long replyTimeout

replyMessageCorrelator

private ReplyMessageCorrelator replyMessageCorrelator

endpointRegistry

private EndpointRegistry endpointRegistry

replyMessageCorrelatorMonitor

private final java.lang.Object replyMessageCorrelatorMonitor
Constructor Detail

RequestReplyTemplate

public RequestReplyTemplate(MessageChannel requestChannel,
                            MessageChannel replyChannel)
Create a RequestReplyTemplate.

Parameters:
requestChannel - the channel to which request messages will be sent
replyChannel - the channel from which reply messages will be received

RequestReplyTemplate

public RequestReplyTemplate(MessageChannel requestChannel)
Create a RequestReplyTemplate that will use anonymous temporary channels for replies.

Parameters:
requestChannel - the channel to which request messages will be sent

RequestReplyTemplate

public RequestReplyTemplate()
Method Detail

setRequestChannel

public void setRequestChannel(MessageChannel requestChannel)
Set the request channel.

Parameters:
requestChannel - the channel to which request messages will be sent

setReplyChannel

public void setReplyChannel(MessageChannel replyChannel)
Set the reply channel. If no reply channel is provided, this template will always use an anonymous, temporary channel for handling replies.

Parameters:
replyChannel - the channel from which reply messages will be received

setRequestTimeout

public void setRequestTimeout(long requestTimeout)
Set the timeout value for sending request messages. If not explicitly configured, the default is an indefinite timeout.

Parameters:
requestTimeout - the timeout value in milliseconds

setReplyTimeout

public void setReplyTimeout(long replyTimeout)
Set the timeout value for receiving reply messages. If not explicitly configured, the default is an indefinite timeout.

Parameters:
replyTimeout - the timeout value in milliseconds

setEndpointRegistry

public void setEndpointRegistry(EndpointRegistry endpointRegistry)

setMessageBus

public void setMessageBus(MessageBus messageBus)
Specified by:
setMessageBus in interface MessageBusAware

send

public boolean send(Message<?> message)

receive

public Message<?> receive()

request

public boolean request(Message<?> message,
                       ReplyHandler replyHandler)
Send a request message whose reply should be handled be the provided callback.


request

public Message<?> request(Message<?> message)
Send a request message and wait for a reply message using the configured timeout values.

Parameters:
requestMessage - the request message to send
Returns:
the reply message or null

sendAndReceiveWithReplyMessageCorrelator

private Message<?> sendAndReceiveWithReplyMessageCorrelator(Message<?> message)

sendAndReceiveWithTemporaryChannel

private Message<?> sendAndReceiveWithTemporaryChannel(Message<?> message)

receiveResponse

private Message<?> receiveResponse(MessageChannel channel)

registerReplyMessageCorrelator

private void registerReplyMessageCorrelator()