Spring Integration

org.springframework.integration.ip.udp
Class UnicastSendingMessageHandler

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.AbstractMessageHandler
          extended by org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
              extended by org.springframework.integration.ip.udp.UnicastSendingMessageHandler
All Implemented Interfaces:
java.lang.Runnable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered, NamedComponent, Orderable, MessageHandler, TrackableComponent, CommonSocketOptions
Direct Known Subclasses:
MulticastSendingMessageHandler

public class UnicastSendingMessageHandler
extends AbstractInternetProtocolSendingMessageHandler
implements java.lang.Runnable

A MessageHandler implementation that maps a Message into a UDP datagram packet and sends that to the specified host and port. Messages can be basic, with no support for reliability, can be prefixed by a length so the receiving end can detect truncation, and can require a UDP acknowledgment to confirm delivery.

Since:
2.0
Author:
Gary Russell

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
UnicastSendingMessageHandler(java.lang.String host, int port)
          Basic constructor; no reliability; no acknowledgment.
UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck)
          Can used to add a length to each packet which can be checked at the destination.
UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)
          Add a length and/or acknowledgment request to packets.
UnicastSendingMessageHandler(java.lang.String host, int port, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)
          Add an acknowledgment request to packets.
 
Method Summary
 int getAckPort()
           
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
protected  java.net.DatagramSocket getSocket()
           
 int getSoReceiveBufferSize()
           
protected  java.net.DatagramSocket getTheSocket()
           
 void handleMessageInternal(Message<?> message)
           
 boolean isAcknowledge()
           
 void onInit()
          Subclasses may implement this for initialization logic.
 void restartAckThread()
          If exposed as an MBean, can be used to restart the ack thread if a fatal (bind) error occurred, without bouncing the JVM.
 void run()
          Process acknowledgments, if requested.
protected  void send(java.net.DatagramPacket packet)
           
 void setAckCounter(int ackCounter)
           
 void setLocalAddress(java.lang.String localAddress)
          On a multi-homed system, specifies the ip address of the network interface used to communicate.
protected  void setReliabilityAttributes(boolean lengthCheck, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)
           
protected  void setSocket(java.net.DatagramSocket socket)
           
protected  void setSocketAttributes(java.net.DatagramSocket socket)
           
 void setSoReceiveBufferSize(int size)
           
 void setTaskExecutor(java.util.concurrent.Executor taskExecutor)
           
 void shutDown()
           
 
Methods inherited from class org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
getDestinationAddress, getHost, getPort, getSoSendBufferSize, getSoTimeout, setSoSendBufferSize, setSoTimeout
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getOrder, handleMessage, setOrder, setShouldTrack
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.context.NamedComponent
getComponentName
 

Constructor Detail

UnicastSendingMessageHandler

public UnicastSendingMessageHandler(java.lang.String host,
                                    int port)
Basic constructor; no reliability; no acknowledgment.

Parameters:
host - Destination host.
port - Destination port.

UnicastSendingMessageHandler

public UnicastSendingMessageHandler(java.lang.String host,
                                    int port,
                                    boolean lengthCheck)
Can used to add a length to each packet which can be checked at the destination.

Parameters:
host - Destination Host.
port - Destination Port.
lengthCheck - If true, packets will contain a length.

UnicastSendingMessageHandler

public UnicastSendingMessageHandler(java.lang.String host,
                                    int port,
                                    boolean acknowledge,
                                    java.lang.String ackHost,
                                    int ackPort,
                                    int ackTimeout)
Add an acknowledgment request to packets.

Parameters:
host - Destination Host.
port - Destination Port.
acknowledge - If true, packets will request acknowledgment.
ackHost - The host to which acks should be sent. Required if ack true.
ackPort - The port to which acks should be sent.
ackTimeout - How long we will wait (milliseconds) for the ack.

UnicastSendingMessageHandler

public UnicastSendingMessageHandler(java.lang.String host,
                                    int port,
                                    boolean lengthCheck,
                                    boolean acknowledge,
                                    java.lang.String ackHost,
                                    int ackPort,
                                    int ackTimeout)
Add a length and/or acknowledgment request to packets.

Parameters:
host - Destination Host.
port - Destination Port.
lengthCheck - If true, packets will contain a length.
acknowledge - If true, packets will request acknowledgment.
ackHost - The host to which acks should be sent. Required if ack true.
ackPort - The port to which acks should be sent.
ackTimeout - How long we will wait (milliseconds) for the ack.
Method Detail

setReliabilityAttributes

protected final void setReliabilityAttributes(boolean lengthCheck,
                                              boolean acknowledge,
                                              java.lang.String ackHost,
                                              int ackPort,
                                              int ackTimeout)

onInit

public void onInit()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class IntegrationObjectSupport

handleMessageInternal

public void handleMessageInternal(Message<?> message)
                           throws MessageRejectedException,
                                  MessageHandlingException,
                                  MessageDeliveryException
Specified by:
handleMessageInternal in class AbstractMessageHandler
Throws:
MessageRejectedException
MessageHandlingException
MessageDeliveryException

send

protected void send(java.net.DatagramPacket packet)
             throws java.lang.Exception
Throws:
java.lang.Exception

setSocket

protected void setSocket(java.net.DatagramSocket socket)

getTheSocket

protected java.net.DatagramSocket getTheSocket()

getSocket

protected java.net.DatagramSocket getSocket()
                                     throws java.io.IOException
Throws:
java.io.IOException

setSocketAttributes

protected void setSocketAttributes(java.net.DatagramSocket socket)
                            throws java.net.SocketException
Throws:
java.net.SocketException

run

public void run()
Process acknowledgments, if requested.

Specified by:
run in interface java.lang.Runnable

restartAckThread

public void restartAckThread()
If exposed as an MBean, can be used to restart the ack thread if a fatal (bind) error occurred, without bouncing the JVM.


shutDown

public void shutDown()

setSoReceiveBufferSize

public void setSoReceiveBufferSize(int size)
Specified by:
setSoReceiveBufferSize in interface CommonSocketOptions
Overrides:
setSoReceiveBufferSize in class AbstractInternetProtocolSendingMessageHandler
See Also:
Socket.setReceiveBufferSize(int), DatagramSocket.setReceiveBufferSize(int)

setLocalAddress

public void setLocalAddress(java.lang.String localAddress)
Description copied from interface: CommonSocketOptions
On a multi-homed system, specifies the ip address of the network interface used to communicate. For inbound adapters and gateways, specifies the interface used to listed for incoming connections. If omitted, the endpoint will listen on all available adapters. For the UDP multicast outbound adapter specifies the interface to which multicast packets will be sent. For UDP unicast and multicast adapters, specifies which interface to which the acknowledgment socket will be bound. Does not apply to TCP outbound adapters and gateways.

Specified by:
setLocalAddress in interface CommonSocketOptions

setTaskExecutor

public void setTaskExecutor(java.util.concurrent.Executor taskExecutor)

setAckCounter

public void setAckCounter(int ackCounter)
Parameters:
ackCounter - the ackCounter to set

getComponentType

public java.lang.String getComponentType()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this method to provide component type information.

Specified by:
getComponentType in interface NamedComponent
Overrides:
getComponentType in class AbstractMessageHandler

isAcknowledge

public boolean isAcknowledge()
Returns:
the acknowledge

getAckPort

public int getAckPort()
Returns:
the ackPort

getSoReceiveBufferSize

public int getSoReceiveBufferSize()
Returns:
the soReceiveBufferSize

Spring Integration