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 Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
FieldsFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionUnicastSendingMessageHandler(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 Summary
Modifier 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.AbstractInternetProtocolSendingMessageHandler
getDestinationAddress, getHost, getPort, getSoSendBufferSize, getSoTimeout, isRunning, setSoSendBufferSize, setSoTimeout, start, stopMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, 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.IntegrationObjectSupport
afterPropertiesSet, 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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
lock
-
-
Constructor Details
-
UnicastSendingMessageHandler
Basic constructor; no reliability; no acknowledgment.- Parameters:
host- Destination host.port- Destination port.
-
UnicastSendingMessageHandler
Construct 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 toString,URIorSocketAddress.- Since:
- 4.3
-
UnicastSendingMessageHandler
Construct 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 toString,URIorSocketAddress.- Since:
- 4.3
-
UnicastSendingMessageHandler
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(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.
-
UnicastSendingMessageHandler
public 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
-
setLengthCheck
public 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
-
setSocketCustomizer
Set a customizer to further configure the socket after creation.- Parameters:
socketCustomizer- the customizer.- Since:
- 5.3.3
-
setReliabilityAttributes
protected final void setReliabilityAttributes(boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) -
doStart
public void doStart()- Specified by:
doStartin classAbstractInternetProtocolSendingMessageHandler
-
doStop
protected void doStop()- Specified by:
doStopin classAbstractInternetProtocolSendingMessageHandler
-
handleMessageInternal
- Specified by:
handleMessageInternalin classAbstractMessageHandler
-
startAckThread
public void startAckThread() -
convertAndSend
- Throws:
IOExceptionURISyntaxException
-
setSocket
-
getTheSocket
-
getSocket
- Throws:
IOException
-
updateAckAddress
protected void updateAckAddress() -
setSoReceiveBufferSize
public void setSoReceiveBufferSize(int size) - Specified by:
setSoReceiveBufferSizein interfaceCommonSocketOptions- Overrides:
setSoReceiveBufferSizein classAbstractInternetProtocolSendingMessageHandler- Parameters:
size- The receive buffer size.- See Also:
-
setLocalAddress
Description 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 interfaceCommonSocketOptions- Parameters:
localAddress- The local address.
-
setTaskExecutor
-
setAckCounter
public 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
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
isAcknowledge
public boolean isAcknowledge()- Returns:
- the acknowledge
-
getAckPort
public int getAckPort()- Returns:
- the ackPort
-
getSoReceiveBufferSize
public int getSoReceiveBufferSize()- Returns:
- the soReceiveBufferSize
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
setSocketAttributes
- Throws:
SocketException
-
run
-
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.
-