Package io.aeron.driver.media
Class UdpChannelTransport
java.lang.Object
io.aeron.driver.media.UdpChannelTransport
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ReceiveChannelEndpoint,ReceiveDestinationTransport,SendChannelEndpoint,UdpNameResolutionTransport
Base class for UDP channel transports which is specialised for send or receive endpoints.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InetSocketAddressAddress to connect to if appropriate for sending.protected final MediaDriver.ContextContext for configuration.protected final ErrorHandlerErrorHandlerfor logging errors and progressing with throwing.protected DatagramChannelChannel to be used for receiving frames from the perspective of the endpoint.protected DatagramChannelChannel to be used for sending frames from the perspective of the endpoint.protected final UdpChannelMedia configuration for the channel. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedUdpChannelTransport(UdpChannel udpChannel, InetSocketAddress endPointAddress, InetSocketAddress bindAddress, InetSocketAddress connectAddress, PortManager portManager, MediaDriver.Context context) Construct transport for a given channel.protectedUdpChannelTransport(UdpChannel udpChannel, InetSocketAddress endPointAddress, InetSocketAddress bindAddress, InetSocketAddress connectAddress, PortManager portManager, MediaDriver.Context context, int socketRcvbufLength, int socketSndbufLength) Construct transport for a given channel. -
Method Summary
Modifier and TypeMethodDescriptionGet the bind address and port in endpoint-style format (ip:port).voidclose()booleanIs transport representing a multicast media?booleanisValidFrame(UnsafeBuffer buffer, int length) Is the received frame valid.intGet the multicast TTL value for sending datagrams on the channel.static voidonSendError(IOException ex, InetSocketAddress destination, ErrorHandler errorHandler) Report anAeronEventwith a message for a send error.voidopenDatagramChannel(AtomicCounter statusIndicator) Open the underlying channel for reading and writing.receive(ByteBuffer buffer) Receive a datagram from the media layer.TheDatagramChannelfor this transport channel.voidreceiveHook(UnsafeBuffer buffer, int length, InetSocketAddress address) Receive packet hook that can be useful for logging.voidresendHook(int sessionId, int streamId, int termId, int termOffset, int length) Useful hook for logging resend calls.static voidsendError(int bytesToSend, IOException ex, InetSocketAddress destination) Deprecated, for removal: This API element is subject to removal in a future version.voidsendHook(ByteBuffer buffer, InetSocketAddress address) Send packet hook that can be used for logging.intGet the configured OS receive socket buffer length (SO_RCVBUF) for the endpoint's socket.intGet the configured OS send socket buffer length (SO_SNDBUF) for the endpoint's socket.Return underlyingUdpChannel.voidupdateEndpoint(InetSocketAddress newAddress, AtomicCounter statusIndicator) Endpoint has moved to a new address.
-
Field Details
-
context
Context for configuration. -
errorHandler
ErrorHandlerfor logging errors and progressing with throwing. -
udpChannel
Media configuration for the channel. -
sendDatagramChannel
Channel to be used for sending frames from the perspective of the endpoint. -
receiveDatagramChannel
Channel to be used for receiving frames from the perspective of the endpoint. -
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.onSendError(IOException, InetSocketAddress, ErrorHandler)is used instead.Throw aAeronExceptionwith 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 anAeronEventwith a message for a send error.- Parameters:
ex- experienced.destination- to which the send operation was addressed.errorHandler- to report error to.
-
openDatagramChannel
Open the underlying channel for reading and writing.- Parameters:
statusIndicator- to set forChannelEndpointStatuswhich could beChannelEndpointStatus.ERRORED.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
udpChannel
Return underlyingUdpChannel.- Returns:
- underlying channel.
-
receiveDatagramChannel
TheDatagramChannelfor this transport channel.- Returns:
DatagramChannelfor 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
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
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
Send packet hook that can be used for logging.- Parameters:
buffer- containing the packet.address- to which the packet will be sent.
-
receiveHook
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 resendstreamId- to resendtermId- to resendtermOffset- to resendlength- to resend
-
receive
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
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.
-
onSendError(IOException, InetSocketAddress, ErrorHandler)is used instead.