public class UnicastSendingMessageHandler extends AbstractInternetProtocolSendingMessageHandler implements Runnable
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.IntegrationManagement.ManagementOverridesEXPRESSION_PARSER, loggerHIGHEST_PRECEDENCE, LOWEST_PRECEDENCEMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME| Constructor and Description |
|---|
UnicastSendingMessageHandler(Expression destinationExpression)
Construct UnicastSendingMessageHandler based on the destination SpEL expression to
determine the target destination at runtime against requestMessage.
|
UnicastSendingMessageHandler(String destinationExpression)
Construct UnicastSendingMessageHandler based on the destination SpEL expression to
determine the target destination at runtime against requestMessage.
|
UnicastSendingMessageHandler(String host,
int port)
Basic constructor; no reliability; no acknowledgment.
|
UnicastSendingMessageHandler(String host,
int port,
boolean lengthCheck)
Can used to add a length to each packet which can be checked at the destination.
|
UnicastSendingMessageHandler(String host,
int port,
boolean lengthCheck,
boolean acknowledge,
String ackHost,
int ackPort,
int ackTimeout)
Add a length and/or acknowledgment request to packets.
|
UnicastSendingMessageHandler(String host,
int port,
boolean acknowledge,
String ackHost,
int ackPort,
int ackTimeout)
Add an acknowledgment request to packets.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
convertAndSend(Message<?> message) |
void |
doStart() |
protected void |
doStop() |
int |
getAckPort() |
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected DatagramSocket |
getSocket() |
int |
getSoReceiveBufferSize() |
protected DatagramSocket |
getTheSocket() |
void |
handleMessageInternal(Message<?> message) |
boolean |
isAcknowledge() |
protected 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.
|
void |
setAckCounter(int ackCounter) |
void |
setLengthCheck(boolean lengthCheck) |
void |
setLocalAddress(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,
String ackHost,
int ackPort,
int ackTimeout) |
protected void |
setSocket(DatagramSocket socket) |
protected void |
setSocketAttributes(DatagramSocket socket) |
void |
setSocketCustomizer(SocketCustomizer socketCustomizer)
Set a customizer to further configure the socket after creation.
|
void |
setSocketExpression(Expression socketExpression) |
void |
setSocketExpressionString(String socketExpression) |
void |
setSoReceiveBufferSize(int size) |
void |
setTaskExecutor(Executor taskExecutor) |
void |
startAckThread() |
protected void |
updateAckAddress() |
getDestinationAddress, getHost, getPort, getSoSendBufferSize, getSoTimeout, isRunning, setSoSendBufferSize, setSoTimeout, start, stophandleMessage, onComplete, onError, onNext, onSubscribebuildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetThisAsgetBeanName, getComponentNamepublic UnicastSendingMessageHandler(String host, int port)
host - Destination host.port - Destination port.public UnicastSendingMessageHandler(String destinationExpression)
destinationExpression - the SpEL expression to evaluate the target destination
at runtime. Must evaluate to String, URI or SocketAddress.public UnicastSendingMessageHandler(Expression destinationExpression)
destinationExpression - the SpEL expression to evaluate the target destination
at runtime. Must evaluate to String, URI or SocketAddress.public UnicastSendingMessageHandler(String host, int port, boolean lengthCheck)
host - Destination Host.port - Destination Port.lengthCheck - If true, packets will contain a length.public UnicastSendingMessageHandler(String host, int port, boolean acknowledge, 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(String host, int port, boolean lengthCheck, boolean acknowledge, 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.public void setLengthCheck(boolean lengthCheck)
lengthCheck - if true, a four byte binary length header is added to the
packet, allowing the receiver to check for data truncation.public void setSocketCustomizer(SocketCustomizer socketCustomizer)
socketCustomizer - the customizer.protected final void setReliabilityAttributes(boolean lengthCheck,
boolean acknowledge,
String ackHost,
int ackPort,
int ackTimeout)
public void doStart()
doStart in class AbstractInternetProtocolSendingMessageHandlerprotected void doStop()
doStop in class AbstractInternetProtocolSendingMessageHandlerpublic void handleMessageInternal(Message<?> message)
handleMessageInternal in class AbstractMessageHandlerpublic void startAckThread()
protected void convertAndSend(Message<?> message) throws IOException, URISyntaxException
IOExceptionURISyntaxExceptionprotected void setSocket(DatagramSocket socket)
@Nullable protected DatagramSocket getTheSocket()
protected DatagramSocket getSocket() throws IOException
IOExceptionprotected void updateAckAddress()
public void setSoReceiveBufferSize(int size)
setSoReceiveBufferSize in interface CommonSocketOptionssetSoReceiveBufferSize in class AbstractInternetProtocolSendingMessageHandlersize - The receive buffer size.Socket.setReceiveBufferSize(int),
DatagramSocket.setReceiveBufferSize(int)public void setLocalAddress(String localAddress)
CommonSocketOptionssetLocalAddress in interface CommonSocketOptionslocalAddress - The local address.public void setTaskExecutor(Executor taskExecutor)
public void setAckCounter(int ackCounter)
ackCounter - the ackCounter to setpublic void setSocketExpression(Expression socketExpression)
socketExpression - the socket expression to determine the target socket at runtime.public void setSocketExpressionString(String socketExpression)
socketExpression - the socket SpEL expression to determine the target socket at runtime.public String getComponentType()
IntegrationObjectSupportgetComponentType in interface NamedComponentgetComponentType in class MessageHandlerSupportpublic boolean isAcknowledge()
public int getAckPort()
public int getSoReceiveBufferSize()
protected void onInit()
IntegrationObjectSupportonInit in class IntegrationObjectSupportprotected void setSocketAttributes(DatagramSocket socket) throws SocketException
SocketExceptionpublic void run()
public void restartAckThread()