Package io.aeron.driver.media
Class ReceiveChannelEndpoint
java.lang.Object
io.aeron.driver.media.UdpChannelTransport
io.aeron.driver.media.ReceiveChannelEndpoint
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DebugReceiveChannelEndpoint
Aggregator of multiple subscriptions onto a single transport channel for the receiving of data and setup frames
plus sending status and NAK frames.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicCounterCounter for the number of errors frames send back by this channel endpoint.Fields inherited from class io.aeron.driver.media.UdpChannelTransport
connectAddress, context, errorHandler, receiveDatagramChannel, sendDatagramChannel, udpChannel -
Constructor Summary
ConstructorsConstructorDescriptionReceiveChannelEndpoint(UdpChannel udpChannel, DataPacketDispatcher dispatcher, AtomicCounter statusIndicator, MediaDriver.Context context) Construct the receiver end for data streams. -
Method Summary
Modifier and TypeMethodDescriptionintaddDestination(ReceiveDestinationTransport transport) Add a destination to the channel to receive on.voidclose()voidCalled from theDriverConductorto decrement image ref count for this channel endpoint.intdecRefToStream(int streamId) Called from theDriverConductorto decrement the reference count for a given stream id.longdecRefToStreamAndSession(int streamId, int sessionId) Called from theDriverConductorto decrement the reference count for a given stream id and session id.intdecResponseRefToStream(int streamId) Called from theDriverConductorto decrement the reference count for a given stream id for a response subscription while it is waiting to be connected.destination(int transportIndex) Get the transport destination for a given index.intdestination(UdpChannel udpChannel) Get the transport index for a given channel.Dispatcher for the channel.intTotal count of distinct subscriptions to streams.Does the channel have an explicit control address as used with multi-destination-cast or not?booleanhasDestination(int transportIndex) Does the channel have a destination for a given index value.booleanHas the channel got control of destinations for MDS.booleanDoes the channel have an explicit control address as used with multi-destination-cast or not?booleanhasTag()Has the channel been tagged?voidCalled from theDriverConductorto increment image ref count for this channel endpoint.intincRefToStream(int streamId) Called from theDriverConductorto increment the reference count for a given stream id.longincRefToStreamAndSession(int streamId, int sessionId) Called from theDriverConductorto increment the reference count for a given stream id and session id.intincResponseRefToStream(int streamId) Called from theDriverConductorto increment the reference count for a given stream id for a response subscription while it is waiting to be connected.voidIndicate that the channel as active after successfully opening it.voidIndicate that the channel is closing and should not be used for new subscriptions.booleanIs the primary transport multicast?booleanisMulticast(int transportIndex) Is a given transport index multicast?voidlocalSocketAddressIndicator(AtomicCounter counter) Set a channel binding status counter, if required (not used by control-mode=manual).booleanmatchesTag(UdpChannel udpChannel) Does the channel have a matching tag?intGet the multicast TTL for the primary transport.intmulticastTtl(int transportIndex) Get the multicast TTL for the transport index.intonDataPacket(DataHeaderFlyweight header, UnsafeBuffer buffer, int length, InetSocketAddress srcAddress, int transportIndex) Callback to handle a received data packet.voidonRttMeasurement(RttMeasurementFlyweight header, UnsafeBuffer buffer, int length, InetSocketAddress srcAddress, int transportIndex) Callback to handle a received RTT Measurement frame.voidonSetupMessage(SetupFlyweight header, UnsafeBuffer buffer, int length, InetSocketAddress srcAddress, int transportIndex) Callback to handle a received setup frame.voidOpen the underlying sockets for the channel.The original URI String used when a subscription was added.voidIncrement theSystemCounterDescriptor.POSSIBLE_TTL_ASYMMETRYcounter.voidremoveDestination(int transportIndex) Remove transport by index from the channel.protected voidsend(ByteBuffer buffer, int length, int transportIndex, InetSocketAddress remoteAddress) Send a frame to a source.protected voidsend(ByteBuffer buffer, int length, ImageConnection[] imageConnections) Send a frame to the image connections.voidsendErrorFrame(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.voidsendNakMessage(ImageConnection[] controlAddresses, int sessionId, int streamId, int termId, int termOffset, int length) Send a NAK message back to the sources.voidsendResponseSetup(ImageConnection[] controlAddresses, int sessionId, int streamId, int responseSessionId) Send a response setup message.voidsendRttMeasurement(int transportIndex, InetSocketAddress controlAddress, int sessionId, int streamId, long echoTimestampNs, long receptionDelta, boolean isReply) Send RTT Measurement frame to a source.voidsendRttMeasurement(ImageConnection[] controlAddresses, int sessionId, int streamId, long echoTimestampNs, long receptionDelta, boolean isReply) Send RTT Measurement frame to the sources.voidsendSetupElicitingStatusMessage(int transportIndex, InetSocketAddress controlAddress, int sessionId, int streamId) Send a Setup Eliciting Status Message to a source.voidsendStatusMessage(ImageConnection[] controlAddresses, int sessionId, int streamId, int termId, int termOffset, int windowLength, short flags) Send a Status Message back to a sources.intsendTo(ByteBuffer buffer, InetSocketAddress remoteAddress) Send contents ofByteBufferto the remote address.booleanCalled from theDriverConductorto determine if the channel should be closed for cleanup.longstatus()TheChannelEndpointStatusvalue for the channel.Counter which indicates the status of the channel.Return theUdpChannelfor the Subscription channel.longtag()The tag identity for the channel.toString()Get theUdpChannelfor the primary transport.udpChannel(int transportIndex) Get theUdpChannelfor the transport index.voidupdateControlAddress(int transportIndex, InetSocketAddress newAddress) Update the control address for a channel transport when re-resolution occurs.voidValidate that the channel allows destination control.Methods inherited from class io.aeron.driver.media.UdpChannelTransport
bindAddressAndPort, isValidFrame, onSendError, openDatagramChannel, receive, receiveDatagramChannel, receiveHook, resendHook, sendError, sendHook, socketRcvbufLength, socketSndbufLength, updateEndpoint
-
Field Details
-
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
Set a channel binding status counter, if required (not used by control-mode=manual).- Parameters:
counter- to be set.
-
sendTo
Send contents ofByteBufferto the remote address.- Parameters:
buffer- to send containing the payload.remoteAddress- to send the payload to.- Returns:
- number of bytes sent.
-
originalUriString
The original URI String used when a subscription was added.- Returns:
- the original URI String used when a subscription was added.
-
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()TheChannelEndpointStatusvalue for the channel.Must not be called after calling
close(), as it accesses a counter.- Returns:
- the
ChannelEndpointStatusvalue for the channel.
-
openChannel
public void openChannel()Open the underlying sockets for the channel. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classUdpChannelTransport
-
possibleTtlAsymmetryEncountered
public void possibleTtlAsymmetryEncountered()Increment theSystemCounterDescriptor.POSSIBLE_TTL_ASYMMETRYcounter. -
incRefToStream
public int incRefToStream(int streamId) Called from theDriverConductorto 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 theDriverConductorto 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 theDriverConductorto 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 theDriverConductorto 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 theDriverConductorto 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 theDriverConductorto 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 theDriverConductorto 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
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
ControlProtocolExceptionwill be thrown. -
isMulticast
public boolean isMulticast()Is the primary transport multicast?- Overrides:
isMulticastin classUdpChannelTransport- 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
Return theUdpChannelfor the Subscription channel.- Returns:
UdpChannelfor the Subscription channel.
-
udpChannel
Get theUdpChannelfor the primary transport.- Overrides:
udpChannelin classUdpChannelTransport- Returns:
- the
UdpChannelfor the primary transport.
-
udpChannel
Get theUdpChannelfor the transport index.- Parameters:
transportIndex- to theUdpChannel.- Returns:
- the
UdpChannelfor 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
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:
multicastTtlin classUdpChannelTransport- 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
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
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
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
Dispatcher for the channel.- Returns:
- dispatcher for the channel.
-
updateControlAddress
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
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 theDriverConductorto increment image ref count for this channel endpoint. -
decRefImages
public void decRefImages()Called from theDriverConductorto decrement image ref count for this channel endpoint. -
toString
-