Class ReceiveChannelEndpoint

java.lang.Object
io.aeron.driver.media.UdpChannelTransport
io.aeron.driver.media.ReceiveChannelEndpoint
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
DebugReceiveChannelEndpoint

public class ReceiveChannelEndpoint extends UdpChannelTransport
Aggregator of multiple subscriptions onto a single transport channel for the receiving of data and setup frames plus sending status and NAK frames.
  • Field Details

    • errorFramesSent

      protected final AtomicCounter errorFramesSent
      Counter for the number of errors frames send back by this channel endpoint.
  • Constructor Details

    • ReceiveChannelEndpoint

      public ReceiveChannelEndpoint(UdpChannel udpChannel, DataPacketDispatcher dispatcher, AtomicCounter statusIndicator, MediaDriver.Context context)
      Construct the receiver end for data streams.
      Parameters:
      udpChannel - configuration for the media.
      dispatcher - for forwarding packets.
      statusIndicator - to indicate the status of the channel endpoint.
      context - for configuration.
  • Method Details

    • localSocketAddressIndicator

      public void localSocketAddressIndicator(AtomicCounter counter)
      Set a channel binding status counter, if required (not used by control-mode=manual).
      Parameters:
      counter - to be set.
    • sendTo

      public int sendTo(ByteBuffer buffer, InetSocketAddress remoteAddress)
      Send contents of ByteBuffer to the remote address.
      Parameters:
      buffer - to send containing the payload.
      remoteAddress - to send the payload to.
      Returns:
      number of bytes sent.
    • originalUriString

      public String originalUriString()
      The original URI String used when a subscription was added.
      Returns:
      the original URI String used when a subscription was added.
    • statusIndicatorCounter

      public AtomicCounter statusIndicatorCounter()
      Counter which indicates the status of the channel.
      Returns:
      counter which indicates the status of the channel.
    • indicateActive

      public void indicateActive()
      Indicate that the channel as active after successfully opening it.
    • indicateClosing

      public void indicateClosing()
      Indicate that the channel is closing and should not be used for new subscriptions.
    • status

      public long status()
      The ChannelEndpointStatus value for the channel.

      Must not be called after calling close(), as it accesses a counter.

      Returns:
      the ChannelEndpointStatus value for the channel.
    • openChannel

      public void openChannel()
      Open the underlying sockets for the channel.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class UdpChannelTransport
    • possibleTtlAsymmetryEncountered

      public void possibleTtlAsymmetryEncountered()
    • incRefToStream

      public int incRefToStream(int streamId)
      Called from the DriverConductor to increment the reference count for a given stream id.
      Parameters:
      streamId - to increment the reference for.
      Returns:
      current reference count after the increment.
    • decRefToStream

      public int decRefToStream(int streamId)
      Called from the DriverConductor to decrement the reference count for a given stream id.
      Parameters:
      streamId - to decrement the reference for.
      Returns:
      current reference count after the decrement.
    • incRefToStreamAndSession

      public long incRefToStreamAndSession(int streamId, int sessionId)
      Called from the DriverConductor to increment the reference count for a given stream id and session id.
      Parameters:
      streamId - to increment the reference for.
      sessionId - to increment the reference for.
      Returns:
      current reference count after the increment.
    • decRefToStreamAndSession

      public long decRefToStreamAndSession(int streamId, int sessionId)
      Called from the DriverConductor to decrement the reference count for a given stream id and session id.
      Parameters:
      streamId - to increment the reference for.
      sessionId - to increment the reference for.
      Returns:
      current reference count after the decrement.
    • incResponseRefToStream

      public int incResponseRefToStream(int streamId)
      Called from the DriverConductor to increment the reference count for a given stream id for a response subscription while it is waiting to be connected.
      Parameters:
      streamId - to increment the reference for.
      Returns:
      current reference count after the increment.
    • decResponseRefToStream

      public int decResponseRefToStream(int streamId)
      Called from the DriverConductor to decrement the reference count for a given stream id for a response subscription while it is waiting to be connected.
      Parameters:
      streamId - to decrement the reference for.
      Returns:
      current reference count after the decrement.
    • distinctSubscriptionCount

      public int distinctSubscriptionCount()
      Total count of distinct subscriptions to streams.
      Returns:
      total count of distinct subscriptions to streams.
    • shouldBeClosed

      public boolean shouldBeClosed()
      Called from the DriverConductor to determine if the channel should be closed for cleanup.
      Returns:
      true if the channel should be closed for cleanup.
    • hasExplicitControl

      public boolean hasExplicitControl()
      Does the channel have an explicit control address as used with multi-destination-cast or not?
      Returns:
      does channel have an explicit control address or not?
    • explicitControlAddress

      public InetSocketAddress explicitControlAddress()
      Does the channel have an explicit control address as used with multi-destination-cast or not?
      Returns:
      does channel have an explicit control address or not?
    • hasDestinationControl

      public boolean hasDestinationControl()
      Has the channel got control of destinations for MDS.
      Returns:
      true if the channel got control of destinations for MDS.
    • validateAllowsDestinationControl

      public void validateAllowsDestinationControl()
      Validate that the channel allows destination control.

      If not then a ControlProtocolException will be thrown.

    • isMulticast

      public boolean isMulticast()
      Is the primary transport multicast?
      Overrides:
      isMulticast in class UdpChannelTransport
      Returns:
      true if the primary transport is multicast.
    • isMulticast

      public boolean isMulticast(int transportIndex)
      Is a given transport index multicast?
      Parameters:
      transportIndex - to check for multicast.
      Returns:
      true if the transport index is multicast.
    • subscriptionUdpChannel

      public UdpChannel subscriptionUdpChannel()
      Return the UdpChannel for the Subscription channel.
      Returns:
      UdpChannel for the Subscription channel.
    • udpChannel

      public UdpChannel udpChannel()
      Get the UdpChannel for the primary transport.
      Overrides:
      udpChannel in class UdpChannelTransport
      Returns:
      the UdpChannel for the primary transport.
    • udpChannel

      public UdpChannel udpChannel(int transportIndex)
      Get the UdpChannel for the transport index.
      Parameters:
      transportIndex - to the UdpChannel.
      Returns:
      the UdpChannel for the transport index.
    • hasTag

      public boolean hasTag()
      Has the channel been tagged?
      Returns:
      true if the channel has a tag identity.
    • tag

      public long tag()
      The tag identity for the channel.
      Returns:
      the tag identity for the channel.
    • matchesTag

      public boolean matchesTag(UdpChannel udpChannel)
      Does the channel have a matching tag?
      Parameters:
      udpChannel - with tag to match against.
      Returns:
      true if the channel matches on tag identity.
    • multicastTtl

      public int multicastTtl()
      Get the multicast TTL for the primary transport.
      Overrides:
      multicastTtl in class UdpChannelTransport
      Returns:
      the multicast TTL for the primary transport.
    • multicastTtl

      public int multicastTtl(int transportIndex)
      Get the multicast TTL for the transport index.
      Parameters:
      transportIndex - to get the multicast TTL for.
      Returns:
      the multicast TTL for the transport index.
    • addDestination

      public int addDestination(ReceiveDestinationTransport transport)
      Add a destination to the channel to receive on.
      Parameters:
      transport - to add for the destination.
      Returns:
      index for the transport.
    • removeDestination

      public void removeDestination(int transportIndex)
      Remove transport by index from the channel.
      Parameters:
      transportIndex - to be removed.
    • destination

      public int destination(UdpChannel udpChannel)
      Get the transport index for a given channel.
      Parameters:
      udpChannel - to look up the transport index for.
      Returns:
      the transport index if found otherwise ArrayUtil.UNKNOWN_INDEX.
    • destination

      public ReceiveDestinationTransport destination(int transportIndex)
      Get the transport destination for a given index.
      Parameters:
      transportIndex - to get.
      Returns:
      the transport destination for a given index.
    • hasDestination

      public boolean hasDestination(int transportIndex)
      Does the channel have a destination for a given index value.
      Parameters:
      transportIndex - to check if a destination exists for.
      Returns:
      true if the channel has a given transport index.
    • onDataPacket

      public int onDataPacket(DataHeaderFlyweight header, UnsafeBuffer buffer, int length, InetSocketAddress srcAddress, int transportIndex)
      Callback to handle a received data packet.
      Parameters:
      header - of the data first frame.
      buffer - containing the data packet.
      length - of the data packet.
      srcAddress - from which the data packet was received.
      transportIndex - on which the packet was received.
      Returns:
      number of bytes applied as a result of this action.
    • onSetupMessage

      public void onSetupMessage(SetupFlyweight header, UnsafeBuffer buffer, int length, InetSocketAddress srcAddress, int transportIndex)
      Callback to handle a received setup frame.
      Parameters:
      header - of the setup frame.
      buffer - containing the setup frame.
      length - of the setup frame.
      srcAddress - the message came from.
      transportIndex - on which the message was received.
    • onRttMeasurement

      public void onRttMeasurement(RttMeasurementFlyweight header, UnsafeBuffer buffer, int length, InetSocketAddress srcAddress, int transportIndex)
      Callback to handle a received RTT Measurement frame.
      Parameters:
      header - of the RTT Measurement frame.
      buffer - containing the RTT Measurement frame.
      length - of the RTT Measurement frame.
      srcAddress - the message came from.
      transportIndex - on which the message was received.
    • sendSetupElicitingStatusMessage

      public void sendSetupElicitingStatusMessage(int transportIndex, InetSocketAddress controlAddress, int sessionId, int streamId)
      Send a Setup Eliciting Status Message to a source.
      Parameters:
      transportIndex - for the source.
      controlAddress - for the source.
      sessionId - for the image.
      streamId - for the image.
    • sendRttMeasurement

      public void sendRttMeasurement(int transportIndex, InetSocketAddress controlAddress, int sessionId, int streamId, long echoTimestampNs, long receptionDelta, boolean isReply)
      Send RTT Measurement frame to a source.
      Parameters:
      transportIndex - for the source.
      controlAddress - for the source.
      sessionId - for the image.
      streamId - for the image.
      echoTimestampNs - timestamp to echo in a reply.
      receptionDelta - time in nanoseconds between receiving original request and sending Reply RTT Measurement.
      isReply - true if a reply.
    • sendStatusMessage

      public void sendStatusMessage(ImageConnection[] controlAddresses, int sessionId, int streamId, int termId, int termOffset, int windowLength, short flags)
      Send a Status Message back to a sources.
      Parameters:
      controlAddresses - of the sources.
      sessionId - of the image.
      streamId - of the image.
      termId - of the image to indicate position.
      termOffset - of the image to indicate position.
      windowLength - for available buffer from the position.
      flags - for the header.
    • sendNakMessage

      public void sendNakMessage(ImageConnection[] controlAddresses, int sessionId, int streamId, int termId, int termOffset, int length)
      Send a NAK message back to the sources.
      Parameters:
      controlAddresses - of the sources.
      sessionId - of the image.
      streamId - of the image.
      termId - of the image to indicate position.
      termOffset - of the image to indicate position.
      length - of the range to be re-transmitted.
    • sendRttMeasurement

      public void sendRttMeasurement(ImageConnection[] controlAddresses, int sessionId, int streamId, long echoTimestampNs, long receptionDelta, boolean isReply)
      Send RTT Measurement frame to the sources.
      Parameters:
      controlAddresses - of the sources.
      sessionId - for the image.
      streamId - for the image.
      echoTimestampNs - timestamp to echo in a reply.
      receptionDelta - time in nanoseconds between receiving original request and sending Reply RTT Measurement.
      isReply - true if a reply.
    • sendResponseSetup

      public void sendResponseSetup(ImageConnection[] controlAddresses, int sessionId, int streamId, int responseSessionId)
      Send a response setup message.
      Parameters:
      controlAddresses - of the sources.
      sessionId - for the image.
      streamId - for the image.
      responseSessionId - to be used by the remote subscription to listen for responses.
    • sendErrorFrame

      public void sendErrorFrame(ImageConnection[] controlAddresses, int sessionId, int streamId, int errorCode, String errorMessage)
      Send an error frame back to the source publications to indicate this image has errored.
      Parameters:
      controlAddresses - of the sources.
      sessionId - for the image.
      streamId - for the image.
      errorCode - for the error being sent.
      errorMessage - to be sent back to the publication.
    • dispatcher

      public DataPacketDispatcher dispatcher()
      Dispatcher for the channel.
      Returns:
      dispatcher for the channel.
    • updateControlAddress

      public void updateControlAddress(int transportIndex, InetSocketAddress newAddress)
      Update the control address for a channel transport when re-resolution occurs.
      Parameters:
      transportIndex - to update the control address for.
      newAddress - for the control of the transport.
    • send

      protected void send(ByteBuffer buffer, int length, ImageConnection[] imageConnections)
      Send a frame to the image connections.
      Parameters:
      buffer - containing the frame.
      length - of the frame in the buffer.
      imageConnections - to send the frame to.
    • send

      protected void send(ByteBuffer buffer, int length, int transportIndex, InetSocketAddress remoteAddress)
      Send a frame to a source.
      Parameters:
      buffer - containing the frame.
      length - of the frame in the buffer.
      transportIndex - to send the frame on.
      remoteAddress - to send the frame to.
    • incRefImages

      public void incRefImages()
      Called from the DriverConductor to increment image ref count for this channel endpoint.
    • decRefImages

      public void decRefImages()
      Called from the DriverConductor to decrement image ref count for this channel endpoint.
    • toString

      public String toString()
      Overrides:
      toString in class Object