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 target while still sending the original message to the main channel.

Author:
Mark Fisher

Field Summary
private static org.apache.commons.logging.Log logger
           
private  boolean running
           
private  MessageSelector selector
           
private  MessageTarget target
           
private  long timeout
           
 
Constructor Summary
WireTap(MessageTarget target)
          Create a new wire tap with no MessageSelector.
WireTap(MessageTarget target, MessageSelector selector)
          Create a new wire tap with the provided MessageSelector.
 
Method Summary
 boolean isRunning()
          Check whether the wire tap is currently running.
 Message<?> preSend(Message<?> message, MessageChannel channel)
          Intercept the Message and, if accepted by the MessageSelector, send it to the secondary target.
 void setTimeout(long timeout)
          Specify the timeout value for sending to the intercepting target.
 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

logger

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

target

private final MessageTarget target

timeout

private volatile long timeout

selector

private final MessageSelector selector

running

private volatile boolean running
Constructor Detail

WireTap

public WireTap(MessageTarget target)
Create a new wire tap with no MessageSelector.

Parameters:
target - the MessageTarget to which intercepted messages will be sent

WireTap

public WireTap(MessageTarget target,
               MessageSelector selector)
Create a new wire tap with the provided MessageSelector.

Parameters:
target - the target to which intercepted messages will be sent
selector - the selector that must accept a message for it to be sent to the intercepting target
Method Detail

setTimeout

public void setTimeout(long timeout)
Specify the timeout value for sending to the intercepting target. Note that this value will only apply if the target is a BlockingTarget. The default value is 0.

Parameters:
timeout - the timeout in milliseconds

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 Message<?> preSend(Message<?> message,
                          MessageChannel channel)
Intercept the Message and, if accepted by the MessageSelector, send it to the secondary target. If this wire tap's MessageSelector is null, it will accept all messages.

Specified by:
preSend in interface ChannelInterceptor
Overrides:
preSend in class ChannelInterceptorAdapter