EndPoint is the abstraction for an I/O channel that transports bytes.
Asynchronous Methods
The asynchronous scheduling methods of EndPoint
has been influenced by NIO.2 Futures and Completion
handlers, but does not use those actual interfaces because they have
some inefficiencies.
This class will frequently be used in conjunction with some of the utility
implementations of Callback, such as FutureCallback and
IteratingCallback.
Reads
A FutureCallback can be used to block until an endpoint is ready
to fill bytes - the notification will be emitted by the NIO subsystem:
FutureCallback callback = new FutureCallback(); endPoint.fillInterested(callback); // Blocks until read to fill bytes. callback.get(); // Now bytes can be filled in a ByteBuffer. int filled = endPoint.fill(byteBuffer);
Asynchronous Reads
A Callback can be used to read asynchronously in its own dispatched
thread:
endPoint.fillInterested(new Callback()
{
public void onSucceeded()
{
executor.execute(() ->
{
// Fill bytes in a different thread.
int filled = endPoint.fill(byteBuffer);
});
}
public void onFailed(Throwable failure)
{
endPoint.close();
}
});
Blocking Writes
The write contract is that the callback is completed when all the bytes have been written or there is a failure. Blocking writes look like this:
FutureCallback callback = new FutureCallback(); endpoint.write(callback, headerBuffer, contentBuffer); // Blocks until the write succeeds or fails. future.get();
Note also that multiple buffers may be passed in write(Callback, ByteBuffer.
so that gather writes can be performed for efficiency.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | EndPoint.
Interface representing bundle of SSLSession associated data. |
| public static interface | EndPoint.
Marks an |
| Modifier and Type | Method and Description |
|---|---|
| public default void | |
| public void | |
| public default int | Returns: anint value indicating the number of bytes
filled or -1 if EOF is read or the input is shutdown.The buffer to fill. The position and limit are modified during the fill. After the
operation, the position is unchanged and the limit is increased to reflect the new data filled. buffer)Fill the passed buffer with data from this endpoint. |
| public void | fillInterested(Callback
the callback to call when an error occurs or we are readable. The callback may implement the callback)Invocable interface to
self declare its blocking status. Non-blocking callbacks may be called more efficiently without dispatch delays.Requests callback methods to be invoked when a call to |
| public default boolean | Returns: True IFF all the buffers have been consumed and the endpoint has flushed the data to its destination (ie is not buffering any data).the buffers to flush buffer)Flush data from the passed header/buffer to this endpoint. |
| public Connection | |
| public long | |
| public long | Returns: the max idle time in ms or if ms <= 0 implies an infinite timeoutGet the max idle time in ms. |
| public InetSocketAddress | getLocalAddress()
Deprecated
use
getLocalSocketAddress() instead
Returns: The local InetSocketAddress to which this |
| public default SocketAddress | getLocalSocketAddress()
Returns: the local SocketAddress to which this |
| public InetSocketAddress | getRemoteAddress()
Deprecated
use
getRemoteSocketAddress() instead.
Returns: The remote InetSocketAddress to which this |
| public default SocketAddress | getRemoteSocketAddress()
Returns: The remote SocketAddress to which this |
| public default EndPoint. | |
| public Object | |
| public boolean | isFillInterested()
Returns: whether |
| public boolean | Returns: True if the input is shutdown or the endpoint is closed.Test if the input is shutdown. |
| public boolean | |
| public boolean | Returns: true if the output is shutdown or the endpoint is closed.Test if output is shutdown. |
| public default boolean | |
| public void | |
| public void | |
| public void | |
| public void | setIdleTimeout(long
the idle timeout in MS. Timeout <= 0 implies an infinite timeout idleTimeout)Set the idle timeout. |
| public void | |
| public boolean | Returns: true if setthe callback to call when an error occurs or we are readable. The callback may implement the callback)Invocable interface to
self declare its blocking status. Non-blocking callbacks may be called more efficiently without dispatch delays.Requests callback methods to be invoked when a call to |
| public void | upgrade(Connection
the connection to upgrade to newConnection)Upgrades this EndPoint from the current connection to the given new connection. |
| public default void | write(Callback
the callback to call when an error occurs or the write completed. The callback may implement the callback, ByteBuffer... Invocable interface to
self declare its blocking status. Non-blocking callbacks may be called more efficiently without dispatch delays.one or more buffers)ByteBuffers that will be flushed.Writes the given buffers via |
| close | back to summary |
|---|---|
| public default void close() Implements java. Close any backing stream associated with the endpoint
| |
| close | back to summary |
|---|---|
| public void close(Throwable cause) Close any backing stream associated with the endpoint, passing a cause
| |
| fill | back to summary |
|---|---|
| public default int fill(ByteBuffer buffer) throws IOException Fill the passed buffer with data from this endpoint. The bytes are appended to any data already in the buffer by writing from the buffers limit up to it's capacity. The limit is updated to include the filled bytes.
| |
| fillInterested | back to summary |
|---|---|
| public void fillInterested(Callback callback) throws ReadPendingException Requests callback methods to be invoked when a call to
| |
| flush | back to summary |
|---|---|
| public default boolean flush(ByteBuffer... buffer) throws IOException Flush data from the passed header/buffer to this endpoint. As many bytes as can be consumed are taken from the header/buffer position up until the buffer limit. The header/buffers position is updated to indicate how many bytes have been consumed.
| |
| getConnection | back to summary |
|---|---|
public Connection getConnection()
| |
| getCreatedTimeStamp | back to summary |
|---|---|
public long getCreatedTimeStamp()
| |
| getIdleTimeout | back to summary |
|---|---|
| public long getIdleTimeout() Get the max idle time in ms. The max idle time is the time the endpoint can be idle before extraordinary handling takes place.
| |
| getLocalAddress | back to summary |
|---|---|
| public InetSocketAddress getLocalAddress()
Deprecated use
| |
| getLocalSocketAddress | back to summary |
|---|---|
public default SocketAddress getLocalSocketAddress()
| |
| getRemoteAddress | back to summary |
|---|---|
| public InetSocketAddress getRemoteAddress()
Deprecated use
| |
| getRemoteSocketAddress | back to summary |
|---|---|
public default SocketAddress getRemoteSocketAddress()
| |
| getSslSessionData | back to summary |
|---|---|
| public default EndPoint. Get the SslSessionData of a secure end point.
| |
| getTransport | back to summary |
|---|---|
public Object getTransport()
| |
| isFillInterested | back to summary |
|---|---|
public boolean isFillInterested()
| |
| isInputShutdown | back to summary |
|---|---|
| public boolean isInputShutdown() Test if the input is shutdown.
The input is shutdown if an EOF has been read while doing
a
| |
| isOpen | back to summary |
|---|---|
public boolean isOpen()
| |
| isOutputShutdown | back to summary |
|---|---|
| public boolean isOutputShutdown() Test if output is shutdown.
The output is shutdown by a call to
| |
| isSecure | back to summary |
|---|---|
public default boolean isSecure()
| |
| onClose | back to summary |
|---|---|
| public void onClose(Throwable cause) Callback method invoked when this | |
| onOpen | back to summary |
|---|---|
| public void onOpen() Callback method invoked when this EndPoint is opened.
| |
| setConnection | back to summary |
|---|---|
public void setConnection(Connection connection)
| |
| setIdleTimeout | back to summary |
|---|---|
| public void setIdleTimeout(long idleTimeout) Set the idle timeout.
| |
| shutdownOutput | back to summary |
|---|---|
| public void shutdownOutput() Shutdown the output. This call indicates that no more data will be sent on this endpoint that that the remote end should read an EOF once all previously sent data has been consumed. Shutdown may be done either at the TCP/IP level, as a protocol exchange (Eg TLS close handshake) or both.
If the endpoint has | |
| tryFillInterested | back to summary |
|---|---|
| public boolean tryFillInterested(Callback callback) Requests callback methods to be invoked when a call to | |
| upgrade | back to summary |
|---|---|
| public void upgrade(Connection newConnection) Upgrades this EndPoint from the current connection to the given new connection. Closes the current connection, links this EndPoint to the new connection and then opens the new connection. If the current connection is an instance of
| |
| write | back to summary |
|---|---|
| public default void write(Callback callback, ByteBuffer... buffers) throws WritePendingException Writes the given buffers via
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | ATTRIBUTE
The name at which an |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public static EndPoint. | from(SSLSession sslSession, String sslSessionId, String cipherSuite, X509Certificate[] peerCertificates)
|
| public default int | |
| public X509Certificate[] | peerCertificates()
Returns: The |
| public SSLSession | |
| public String | |
| public static EndPoint. | |
| public static EndPoint. |
| ATTRIBUTE | back to summary |
|---|---|
| public static final String ATTRIBUTE The name at which an | |
| cipherSuite | back to summary |
|---|---|
public String cipherSuite()
| |
| from | back to summary |
|---|---|
| public static EndPoint. | |
| keySize | back to summary |
|---|---|
| public default int keySize() Calculates the key size based on the cipher suite.
| |
| peerCertificates | back to summary |
|---|---|
public X509Certificate[] peerCertificates()
| |
| sslSession | back to summary |
|---|---|
public SSLSession sslSession()
| |
| sslSessionId | back to summary |
|---|---|
public String sslSessionId()
| |
| withCipherSuite | back to summary |
|---|---|
| public static EndPoint. | |
| withSslSessionId | back to summary |
|---|---|
| public static EndPoint. | |
EndPoint that wraps another EndPoint.
| Modifier and Type | Method and Description |
|---|---|
| public EndPoint |
| unwrap | back to summary |
|---|---|
public EndPoint unwrap()
| |