Interface EndPoint

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
AbstractEndPoint, ByteArrayEndPoint, DatagramChannelEndPoint, NetworkTrafficSocketChannelEndPoint, SelectableChannelEndPoint, SocketChannelEndPoint, SslConnection.SslEndPoint

public interface EndPoint extends Closeable

EndPoint is the abstraction for I/O communication using bytes.

All the I/O methods are non-blocking; reads may return 0 bytes read, and flushes/writes may write 0 bytes.

Applications are notified of read readiness by registering a Callback via fillInterested(Callback), and then using fill(ByteBuffer) to read the available bytes.

Application may use flush(ByteBuffer...) to transmit bytes; if the flush does not transmit all the bytes, applications must arrange to resume flushing when it will be possible to transmit more bytes. Alternatively, applications may use write(Callback, ByteBuffer...) and be notified via the Callback when the write completes (i.e. all the buffers have been flushed), either successfully or with a failure.

Connection-less reads are performed using receive(ByteBuffer). Similarly, connection-less flushes are performed using send(SocketAddress, ByteBuffer...) and connection-less writes using write(Callback, SocketAddress, ByteBuffer...).

While all the I/O methods are non-blocking, they can be easily converted to blocking using either Blocker or Callback.Completable:


 EndPoint endPoint = ...;

 // Block until read ready with Blocker.
 try (Blocker.Callback blocker = Blocker.callback())
 {
     endPoint.fillInterested(blocker);
     blocker.block();
 }

 // Block until write complete with Callback.Completable.
 Callback.Completable completable = new Callback.Completable();
 endPoint.write(completable, byteBuffer);
 completable.get();