Class UdpChannelTransport

java.lang.Object
io.aeron.driver.media.UdpChannelTransport
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
ReceiveChannelEndpoint, ReceiveDestinationTransport, SendChannelEndpoint, UdpNameResolutionTransport

public abstract class UdpChannelTransport extends Object implements AutoCloseable
Base class for UDP channel transports which is specialised for send or receive endpoints.
  • Field Details

    • context

      protected final MediaDriver.Context context
      Context for configuration.
    • errorHandler

      protected final ErrorHandler errorHandler
      ErrorHandler for logging errors and progressing with throwing.
    • udpChannel

      protected final UdpChannel udpChannel
      Media configuration for the channel.
    • sendDatagramChannel

      protected DatagramChannel sendDatagramChannel
      Channel to be used for sending frames from the perspective of the endpoint.
    • receiveDatagramChannel

      protected DatagramChannel receiveDatagramChannel
      Channel to be used for receiving frames from the perspective of the endpoint.
    • connectAddress

      protected InetSocketAddress connectAddress
      Address to connect to if appropriate for sending.
  • Constructor Details

    • UdpChannelTransport

      protected UdpChannelTransport(UdpChannel udpChannel, InetSocketAddress endPointAddress, InetSocketAddress bindAddress, InetSocketAddress connectAddress, PortManager portManager, MediaDriver.Context context, int socketRcvbufLength, int socketSndbufLength)
      Construct transport for a given channel.
      Parameters:
      udpChannel - configuration for the media.
      endPointAddress - to which data will be sent.
      bindAddress - for listening on.
      connectAddress - for sending data to.
      context - for configuration.
      portManager - for port binding.
      socketRcvbufLength - set SO_RCVBUF for socket, 0 for OS default.
      socketSndbufLength - set SO_SNDBUF for socket, 0 for OS default.
    • UdpChannelTransport

      protected UdpChannelTransport(UdpChannel udpChannel, InetSocketAddress endPointAddress, InetSocketAddress bindAddress, InetSocketAddress connectAddress, PortManager portManager, MediaDriver.Context context)
      Construct transport for a given channel.
      Parameters:
      udpChannel - configuration for the media.
      endPointAddress - to which data will be sent.
      bindAddress - for listening on.
      connectAddress - for sending data to.
      portManager - for port binding.
      context - for configuration.
  • Method Details

    • sendError

      @Deprecated(forRemoval=true, since="1.46.6") public static void sendError(int bytesToSend, IOException ex, InetSocketAddress destination)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Throw a AeronException with a message for a send error.
      Parameters:
      bytesToSend - expected to be sent to the network.
      ex - experienced.
      destination - to which the send operation was addressed.
      See Also:
    • onSendError

      public static void onSendError(IOException ex, InetSocketAddress destination, ErrorHandler errorHandler)
      Report an AeronEvent with a message for a send error.
      Parameters:
      ex - experienced.
      destination - to which the send operation was addressed.
      errorHandler - to report error to.
    • openDatagramChannel

      public void openDatagramChannel(AtomicCounter statusIndicator)
      Open the underlying channel for reading and writing.
      Parameters:
      statusIndicator - to set for ChannelEndpointStatus which could be ChannelEndpointStatus.ERRORED.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • udpChannel

      public UdpChannel udpChannel()
      Return underlying UdpChannel.
      Returns:
      underlying channel.
    • receiveDatagramChannel

      public DatagramChannel receiveDatagramChannel()
      The DatagramChannel for this transport channel.
      Returns:
      DatagramChannel for this transport channel.
    • multicastTtl

      public int multicastTtl()
      Get the multicast TTL value for sending datagrams on the channel.
      Returns:
      the multicast TTL value for sending datagrams on the channel.
    • bindAddressAndPort

      public String bindAddressAndPort()
      Get the bind address and port in endpoint-style format (ip:port).

      Must be called after the channel is opened.

      Returns:
      the bind address and port in endpoint-style format (ip:port).
    • isMulticast

      public boolean isMulticast()
      Is transport representing a multicast media?
      Returns:
      true if transport is multicast media, otherwise false.
    • isValidFrame

      public boolean isValidFrame(UnsafeBuffer buffer, int length)
      Is the received frame valid. This method will do some basic checks on the header and can be overridden in a subclass for further validation.
      Parameters:
      buffer - containing the frame.
      length - of the frame.
      Returns:
      true if the frame is believed valid otherwise false.
    • sendHook

      public void sendHook(ByteBuffer buffer, InetSocketAddress address)
      Send packet hook that can be used for logging.
      Parameters:
      buffer - containing the packet.
      address - to which the packet will be sent.
    • receiveHook

      public void receiveHook(UnsafeBuffer buffer, int length, InetSocketAddress address)
      Receive packet hook that can be useful for logging.
      Parameters:
      buffer - containing the packet.
      length - length of the packet in bytes.
      address - from which the packet came.
    • resendHook

      public void resendHook(int sessionId, int streamId, int termId, int termOffset, int length)
      Useful hook for logging resend calls.
      Parameters:
      sessionId - to resend
      streamId - to resend
      termId - to resend
      termOffset - to resend
      length - to resend
    • receive

      public InetSocketAddress receive(ByteBuffer buffer)
      Receive a datagram from the media layer.
      Parameters:
      buffer - into which the datagram will be received.
      Returns:
      the source address of the datagram if one is available otherwise false.
    • updateEndpoint

      public void updateEndpoint(InetSocketAddress newAddress, AtomicCounter statusIndicator)
      Endpoint has moved to a new address. Handle this.
      Parameters:
      newAddress - to send data to.
      statusIndicator - for the channel
    • socketSndbufLength

      public int socketSndbufLength()
      Get the configured OS send socket buffer length (SO_SNDBUF) for the endpoint's socket.
      Returns:
      OS socket send buffer length or 0 if using OS default.
    • socketRcvbufLength

      public int socketRcvbufLength()
      Get the configured OS receive socket buffer length (SO_RCVBUF) for the endpoint's socket.
      Returns:
      OS socket receive buffer length or 0 if using OS default.