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:
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
  • 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

      public void setSocketCustomizer(SocketCustomizer socketCustomizer)
      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:
      getPort in class AbstractInternetProtocolReceivingChannelAdapter
      Returns:
      The port on which this receiver is listening.
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.endpoint.MessageProducerSupport
    • run

      public void run()
    • sendAck

      protected void sendAck(org.springframework.messaging.Message<byte[]> message)
    • asyncSendMessage

      protected boolean asyncSendMessage(DatagramPacket packet)
    • doSend

      protected void doSend(DatagramPacket packet)
    • receive

      protected DatagramPacket receive() throws IOException
      Throws:
      IOException
    • setSocket

      public void setSocket(DatagramSocket socket)
      Parameters:
      socket - the socket to set
    • getTheSocket

      @Nullable protected DatagramSocket getTheSocket()
    • getSocket

      public DatagramSocket getSocket()
    • setSocketAttributes

      protected void setSocketAttributes(DatagramSocket socket) throws SocketException
      Sets timeout and receive buffer size; calls the socket customizer.
      Parameters:
      socket - The socket.
      Throws:
      SocketException - Any socket exception.
    • doStop

      protected void doStop()
      Overrides:
      doStop in class AbstractInternetProtocolReceivingChannelAdapter
    • setSoSendBufferSize

      public void setSoSendBufferSize(int soSendBufferSize)
      Parameters:
      soSendBufferSize - The send buffer size.
      See Also:
    • setLookupHost

      public void setLookupHost(boolean lookupHost)
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.context.IntegrationObjectSupport