|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
org.springframework.integration.ip.udp.UnicastSendingMessageHandler
public class UnicastSendingMessageHandler
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.
Field Summary | |
---|---|
protected java.util.Map<java.lang.String,java.util.concurrent.CountDownLatch> |
ackControl
|
protected int |
ackCounter
|
protected int |
ackPort
|
protected java.net.DatagramSocket |
ackSocket
|
protected int |
ackTimeout
|
protected java.lang.Exception |
fatalException
|
protected DatagramPacketMessageMapper |
mapper
|
protected java.net.DatagramSocket |
socket
|
protected int |
soReceiveBufferSize
|
protected boolean |
waitForAck
If true adds headers to instruct receiving adapter to return an ack. |
Fields inherited from class org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler |
---|
destinationAddress, executorService, host, logger, port, soSendBufferSize, soTimeout |
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 | |
---|---|
protected java.net.DatagramSocket |
getSocket()
|
void |
handleMessage(Message<?> message)
Handles the message if possible. |
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)
|
protected void |
setReliabilityAttributes(boolean lengthCheck,
boolean acknowledge,
java.lang.String ackHost,
int ackPort,
int ackTimeout)
|
protected void |
setSocketAttributes(java.net.DatagramSocket socket)
|
void |
setSoReceiveBufferSize(int size)
|
void |
shutDown()
|
Methods inherited from class org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler |
---|
getPort, setSoSendBufferSize, setSoTimeout |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final DatagramPacketMessageMapper mapper
protected volatile java.net.DatagramSocket socket
protected volatile boolean waitForAck
protected volatile int ackPort
protected volatile int ackTimeout
protected volatile int ackCounter
protected volatile java.util.Map<java.lang.String,java.util.concurrent.CountDownLatch> ackControl
protected volatile java.net.DatagramSocket ackSocket
protected volatile java.lang.Exception fatalException
protected int soReceiveBufferSize
Constructor Detail |
---|
public UnicastSendingMessageHandler(java.lang.String host, int port)
host
- Destination host.port
- Destination port.public UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck)
host
- Destination Host.port
- Destination Port.lengthCheck
- If true, packets will contain a length.public UnicastSendingMessageHandler(java.lang.String host, int port, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)
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.public UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)
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 |
---|
protected void setReliabilityAttributes(boolean lengthCheck, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)
public void handleMessage(Message<?> message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException
MessageHandler
MessageRejectedException
e.g.
in case of a Selective Consumer. When a consumer tries to handle a
message, but fails to do so, a MessageHandlingException
is
thrown. In the last case it is recommended to treat the message as tainted
and go into an error scenario.
When the handling results in a message being sent failure to send that
message will result in a MessageDeliveryException
.
handleMessage
in interface MessageHandler
message
- the message to be handled
MessageRejectedException
- if the handler doesn't select these
types of messages
MessageHandlingException
- when something went wrong during the
handling
MessageDeliveryException
- when this handler failed to deliver the
reply related to the handling of the messageprotected void send(java.net.DatagramPacket packet) throws java.lang.Exception
java.lang.Exception
protected java.net.DatagramSocket getSocket() throws java.io.IOException
java.io.IOException
protected void setSocketAttributes(java.net.DatagramSocket socket) throws java.net.SocketException
java.net.SocketException
public void run()
run
in interface java.lang.Runnable
public void restartAckThread()
public void shutDown()
public void setSoReceiveBufferSize(int size)
setSoReceiveBufferSize
in interface CommonSocketOptions
setSoReceiveBufferSize
in class AbstractInternetProtocolSendingMessageHandler
size
- Socket#setReceiveBufferSize(int)} and {@link DatagramSocket#setReceiveBufferSize(int)}
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |