Class UnicastReceivingChannelAdapter

All Implemented Interfaces:
Runnable, Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, SmartInitializingSingleton, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, Phased, SmartLifecycle, ComponentSourceAware, ExpressionCapable, MessageProducer, IntegrationPattern, CommonSocketOptions, NamedComponent, IntegrationInboundManagement, IntegrationManagement, ManageableLifecycle, ManageableSmartLifecycle, TrackableComponent, 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
Author:
Gary Russell, Artem Bilan, Christian Tzolov, Glenn Renfro
  • Field Details

    • lock

      protected final Lock lock
  • Constructor Details

    • UnicastReceivingChannelAdapter

      public UnicastReceivingChannelAdapter(int port)
      Construct a UnicastReceivingChannelAdapter that listens on the specified port.
      Parameters:
      port - The port.
    • UnicastReceivingChannelAdapter

      public UnicastReceivingChannelAdapter(int port, boolean lengthCheck)
      Construct 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
    • setTrustedAckAddresses

      public void setTrustedAckAddresses(String... trustedAckAddresses)
      Set patterns for trusted acknowledgment addresses. Only packets whose IpHeaders.ACK_ADDRESS header matches one of these patterns will trigger an acknowledgment. Patterns support * wildcards via PatternMatchUtils.simpleMatch(String, String). The address format is host:port, matching the format set by UnicastSendingMessageHandler. By default, no patterns are set. Setting trustedAckAddresses implies acknowledgments will be sent. Packets from non-matching addresses will not receive an acknowledgment, and a MessagingException is thrown.
      Parameters:
      trustedAckAddresses - the patterns to trust.
      Since:
      5.5.22
    • 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()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class MessageProducerSupport
    • run

      public void run()
    • sendAck

      protected void sendAck(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

      protected @Nullable DatagramSocket getTheSocket()
    • getSocket

      public DatagramSocket getSocket()
    • setSocketAttributes

      protected void setSocketAttributes(DatagramSocket socket) throws SocketException
      Set timeout and receive buffer size; calls the socket customizer.
      Parameters:
      socket - The socket.
      Throws:
      SocketException - Any socket exception.
    • 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 NamedComponent
      Overrides:
      getComponentType in class MessageProducerSupport
    • doStop

      protected void doStop()
      Description copied from class: MessageProducerSupport
      Take no action by default. Subclasses may override this if they need lifecycle-managed behavior.
      Overrides:
      doStop in class AbstractInternetProtocolReceivingChannelAdapter