Class UnicastReceivingChannelAdapter
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.ip.AbstractInternetProtocolReceivingChannelAdapter
org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter
- 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.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.beans.factory.SmartInitializingSingleton,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle,org.springframework.integration.context.ExpressionCapable,org.springframework.integration.core.MessageProducer,org.springframework.integration.IntegrationPattern,CommonSocketOptions,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.ManageableLifecycle,org.springframework.integration.support.management.ManageableSmartLifecycle,org.springframework.integration.support.management.TrackableComponent,org.springframework.scheduling.SchedulingAwareRunnable
- Direct Known Subclasses:
MulticastReceivingChannelAdapter
public class UnicastReceivingChannelAdapter extends AbstractInternetProtocolReceivingChannelAdapter
A channel adapter to receive incoming UDP packets. Packets can optionally be preceded by a
4 byte length field, used to validate that all data was received. Packets may also contain
information indicating an acknowledgment needs to be sent.
- Since:
- 2.0
-
Field Summary
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock -
Constructor Summary
Constructors Constructor Description UnicastReceivingChannelAdapter(int port)Constructs a UnicastReceivingChannelAdapter that listens on the specified port.UnicastReceivingChannelAdapter(int port, boolean lengthCheck)Constructs a UnicastReceivingChannelAdapter that listens for packets on the specified port. -
Method Summary
Modifier and Type Method Description protected booleanasyncSendMessage(java.net.DatagramPacket packet)protected voiddoSend(java.net.DatagramPacket packet)protected voiddoStop()java.lang.StringgetComponentType()intgetPort()java.net.DatagramSocketgetSocket()protected java.net.DatagramSocketgetTheSocket()booleanisLongLived()protected voidonInit()protected java.net.DatagramPacketreceive()voidrun()protected voidsendAck(org.springframework.messaging.Message<byte[]> message)voidsetLengthCheck(boolean lengthCheck)voidsetLookupHost(boolean lookupHost)voidsetSocket(java.net.DatagramSocket socket)protected voidsetSocketAttributes(java.net.DatagramSocket socket)Sets timeout and receive buffer size; calls the socket customizer.voidsetSocketCustomizer(SocketCustomizer socketCustomizer)Set a customizer to further configure the socket after creation.voidsetSoSendBufferSize(int soSendBufferSize)Methods inherited from class org.springframework.integration.ip.AbstractInternetProtocolReceivingChannelAdapter
checkTaskExecutor, doStart, getApplicationEventPublisher, getLocalAddress, getReceiveBufferSize, getSoReceiveBufferSize, getSoTimeout, getTaskExecutor, isListening, setApplicationEventPublisher, setListening, setLocalAddress, setPoolSize, setReceiveBufferSize, setSoReceiveBufferSize, setSoTimeout, setTaskExecutorMethods inherited from class org.springframework.integration.endpoint.MessageProducerSupport
afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisherMethods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
destroy, doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stopMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, 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, toString
-
Constructor Details
-
UnicastReceivingChannelAdapter
public UnicastReceivingChannelAdapter(int port)Constructs a UnicastReceivingChannelAdapter that listens on the specified port.- Parameters:
port- The port.
-
UnicastReceivingChannelAdapter
public UnicastReceivingChannelAdapter(int port, boolean lengthCheck)Constructs a UnicastReceivingChannelAdapter that listens for packets on the specified port. Enables setting the lengthCheck option, which expects a length to precede the incoming packets.- Parameters:
port- The port.lengthCheck- If true, enables the lengthCheck Option.
-
-
Method Details
-
setLengthCheck
public void setLengthCheck(boolean lengthCheck)- Parameters:
lengthCheck- if true, the incoming packet is expected to have a four byte binary length header.- Since:
- 5.0
-
setSocketCustomizer
Set a customizer to further configure the socket after creation.- Parameters:
socketCustomizer- the customizer.- Since:
- 5.3.3
-
isLongLived
public boolean isLongLived() -
getPort
public int getPort()- Overrides:
getPortin classAbstractInternetProtocolReceivingChannelAdapter- Returns:
- The port on which this receiver is listening.
-
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.endpoint.MessageProducerSupport
-
run
public void run() -
sendAck
protected void sendAck(org.springframework.messaging.Message<byte[]> message) -
asyncSendMessage
protected boolean asyncSendMessage(java.net.DatagramPacket packet) -
doSend
protected void doSend(java.net.DatagramPacket packet) -
receive
protected java.net.DatagramPacket receive() throws java.io.IOException- Throws:
java.io.IOException
-
setSocket
public void setSocket(java.net.DatagramSocket socket)- Parameters:
socket- the socket to set
-
getTheSocket
@Nullable protected java.net.DatagramSocket getTheSocket() -
getSocket
public java.net.DatagramSocket getSocket() -
setSocketAttributes
protected void setSocketAttributes(java.net.DatagramSocket socket) throws java.net.SocketExceptionSets timeout and receive buffer size; calls the socket customizer.- Parameters:
socket- The socket.- Throws:
java.net.SocketException- Any socket exception.
-
doStop
protected void doStop()- Overrides:
doStopin classAbstractInternetProtocolReceivingChannelAdapter
-
setSoSendBufferSize
public void setSoSendBufferSize(int soSendBufferSize)- Parameters:
soSendBufferSize- The send buffer size.- See Also:
Socket.setSendBufferSize(int),DatagramSocket.setSendBufferSize(int)
-
setLookupHost
public void setLookupHost(boolean lookupHost) -
getComponentType
public java.lang.String getComponentType()- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.context.IntegrationObjectSupport
-