Class UnicastSendingMessageHandler
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
org.springframework.integration.ip.udp.UnicastSendingMessageHandler
- All Implemented Interfaces:
- Runnable,- org.reactivestreams.Subscriber<Message<?>>,- Aware,- BeanFactoryAware,- BeanNameAware,- DisposableBean,- InitializingBean,- ApplicationContextAware,- Lifecycle,- Ordered,- ExpressionCapable,- Orderable,- IntegrationPattern,- CommonSocketOptions,- NamedComponent,- IntegrationManagement,- ManageableLifecycle,- TrackableComponent,- MessageHandler,- reactor.core.CoreSubscriber<Message<?>>
- Direct Known Subclasses:
- MulticastSendingMessageHandler
public class UnicastSendingMessageHandler
extends AbstractInternetProtocolSendingMessageHandler
implements 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, Marcin Pilaczynski, Artem Bilan, Christian Tzolov
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagementIntegrationManagement.ManagementOverrides
- 
Field SummaryFieldsFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagementMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructorsConstructorDescriptionUnicastSendingMessageHandler(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.UnicastSendingMessageHandler(Expression destinationExpression) Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidconvertAndSend(Message<?> message) voiddoStart()protected voiddoStop()intSubclasses may implement this method to provide component type information.protected DatagramSocketintprotected DatagramSocketvoidhandleMessageInternal(Message<?> message) booleanprotected voidonInit()Subclasses may implement this for initialization logic.voidIf exposed as an MBean, can be used to restart the ack thread if a fatal (bind) error occurred, without bouncing the JVM.voidrun()Process acknowledgments, if requested.voidsetAckCounter(int ackCounter) voidsetLengthCheck(boolean lengthCheck) voidsetLocalAddress(String localAddress) On a multi-homed system, specifies the ip address of the network interface used to communicate.protected final voidsetReliabilityAttributes(boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) protected voidsetSocket(DatagramSocket socket) protected voidsetSocketAttributes(DatagramSocket socket) voidsetSocketCustomizer(SocketCustomizer socketCustomizer) Set a customizer to further configure the socket after creation.voidsetSocketExpression(Expression socketExpression) voidsetSocketExpressionString(String socketExpression) voidsetSoReceiveBufferSize(int size) voidsetTaskExecutor(Executor taskExecutor) voidprotected voidMethods inherited from class org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandlergetDestinationAddress, getHost, getPort, getSoSendBufferSize, getSoTimeout, isRunning, setSoSendBufferSize, setSoTimeout, start, stopMethods inherited from class org.springframework.integration.handler.AbstractMessageHandlerhandleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupportbuildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscribercurrentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagementgetThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponentgetBeanName, getComponentName
- 
Field Details- 
lock
 
- 
- 
Constructor Details- 
UnicastSendingMessageHandlerBasic constructor; no reliability; no acknowledgment.- Parameters:
- host- Destination host.
- port- Destination port.
 
- 
UnicastSendingMessageHandlerConstruct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.- Parameters:
- destinationExpression- the SpEL expression to evaluate the target destination at runtime. Must evaluate to- String,- URIor- SocketAddress.
- Since:
- 4.3
 
- 
UnicastSendingMessageHandlerConstruct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.- Parameters:
- destinationExpression- the SpEL expression to evaluate the target destination at runtime. Must evaluate to- String,- URIor- SocketAddress.
- Since:
- 4.3
 
- 
UnicastSendingMessageHandlerCan 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.
 
- 
UnicastSendingMessageHandlerpublic UnicastSendingMessageHandler(String host, int port, boolean acknowledge, 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.
 
- 
UnicastSendingMessageHandlerpublic UnicastSendingMessageHandler(String host, int port, boolean lengthCheck, boolean acknowledge, 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 Details- 
setLengthCheckpublic void setLengthCheck(boolean lengthCheck) - Parameters:
- lengthCheck- if true, a four byte binary length header is added to the packet, allowing the receiver to check for data truncation.
- Since:
- 5.0
 
- 
setSocketCustomizerSet a customizer to further configure the socket after creation.- Parameters:
- socketCustomizer- the customizer.
- Since:
- 5.3.3
 
- 
setReliabilityAttributesprotected final void setReliabilityAttributes(boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) 
- 
doStartpublic void doStart()- Specified by:
- doStartin class- AbstractInternetProtocolSendingMessageHandler
 
- 
doStopprotected void doStop()- Specified by:
- doStopin class- AbstractInternetProtocolSendingMessageHandler
 
- 
handleMessageInternal- Specified by:
- handleMessageInternalin class- AbstractMessageHandler
 
- 
startAckThreadpublic void startAckThread()
- 
convertAndSend- Throws:
- IOException
- URISyntaxException
 
- 
setSocket
- 
getTheSocket
- 
getSocket- Throws:
- IOException
 
- 
updateAckAddressprotected void updateAckAddress()
- 
setSoReceiveBufferSizepublic void setSoReceiveBufferSize(int size) - Specified by:
- setSoReceiveBufferSizein interface- CommonSocketOptions
- Overrides:
- setSoReceiveBufferSizein class- AbstractInternetProtocolSendingMessageHandler
- Parameters:
- size- The receive buffer size.
- See Also:
 
- 
setLocalAddressDescription copied from interface:CommonSocketOptionsOn 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:
- setLocalAddressin interface- CommonSocketOptions
- Parameters:
- localAddress- The local address.
 
- 
setTaskExecutor
- 
setAckCounterpublic void setAckCounter(int ackCounter) - Parameters:
- ackCounter- the ackCounter to set
 
- 
setSocketExpression- Parameters:
- socketExpression- the socket expression to determine the target socket at runtime.
- Since:
- 4.3
 
- 
setSocketExpressionString- Parameters:
- socketExpression- the socket SpEL expression to determine the target socket at runtime.
- Since:
- 4.3
 
- 
getComponentTypeDescription copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
- getComponentTypein interface- NamedComponent
- Overrides:
- getComponentTypein class- MessageHandlerSupport
 
- 
isAcknowledgepublic boolean isAcknowledge()- Returns:
- the acknowledge
 
- 
getAckPortpublic int getAckPort()- Returns:
- the ackPort
 
- 
getSoReceiveBufferSizepublic int getSoReceiveBufferSize()- Returns:
- the soReceiveBufferSize
 
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- IntegrationObjectSupport
 
- 
setSocketAttributes- Throws:
- SocketException
 
- 
run
- 
restartAckThreadpublic 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.
 
-