org.springframework.integration.channel.interceptor
Class WireTap

java.lang.Object
  extended by org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter
      extended by org.springframework.integration.channel.interceptor.WireTap
All Implemented Interfaces:
org.springframework.context.Lifecycle, ChannelInterceptor

public class WireTap
extends ChannelInterceptorAdapter
implements org.springframework.context.Lifecycle

A ChannelInterceptor that publishes a copy of the intercepted message to a secondary channel while still sending the original message to the main channel.

Author:
Mark Fisher

Field Summary
private  org.apache.commons.logging.Log logger
           
static java.lang.String ORIGINAL_MESSAGE_ID_KEY
          key for the attribute containing the original Message's id
private  boolean running
           
private  MessageChannel secondaryChannel
           
private  java.util.List<MessageSelector> selectors
           
 
Constructor Summary
WireTap(MessageChannel secondaryChannel)
          Create a new wire tap with no MessageSelectors.
WireTap(MessageChannel secondaryChannel, java.util.List<MessageSelector> selectors)
          Create a new wire tap with MessageSelectors.
 
Method Summary
 boolean isRunning()
          Check whether the wire tap is currently running.
 boolean preSend(Message<?> message, MessageChannel channel)
           
private  boolean selectorsAccept(Message<?> message)
          If this wire tap has any MessageSelectors, check whether they accept the current message.
 void start()
          Restart the wire tap if it has been stopped.
 void stop()
          Stop the wire tap.
 
Methods inherited from class org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter
postReceive, postSend, preReceive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIGINAL_MESSAGE_ID_KEY

public static final java.lang.String ORIGINAL_MESSAGE_ID_KEY
key for the attribute containing the original Message's id

See Also:
Constant Field Values

logger

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

secondaryChannel

private final MessageChannel secondaryChannel

selectors

private final java.util.List<MessageSelector> selectors

running

private volatile boolean running
Constructor Detail

WireTap

public WireTap(MessageChannel secondaryChannel)
Create a new wire tap with no MessageSelectors.

Parameters:
secondaryChannel - the channel to which duplicate messages will be sent

WireTap

public WireTap(MessageChannel secondaryChannel,
               java.util.List<MessageSelector> selectors)
Create a new wire tap with MessageSelectors.

Parameters:
secondaryChannel - the channel to which duplicate messages will be sent
selectors - the list of selectors that must accept a message for it to be sent to the secondary channel
Method Detail

isRunning

public boolean isRunning()
Check whether the wire tap is currently running.

Specified by:
isRunning in interface org.springframework.context.Lifecycle

start

public void start()
Restart the wire tap if it has been stopped. It is running by default.

Specified by:
start in interface org.springframework.context.Lifecycle

stop

public void stop()
Stop the wire tap. To restart, invoke start().

Specified by:
stop in interface org.springframework.context.Lifecycle

preSend

public boolean preSend(Message<?> message,
                       MessageChannel channel)
Specified by:
preSend in interface ChannelInterceptor
Overrides:
preSend in class ChannelInterceptorAdapter

selectorsAccept

private boolean selectorsAccept(Message<?> message)
If this wire tap has any MessageSelectors, check whether they accept the current message. If any of them do not accept it, the message will not be sent to the secondary channel.