Class AsynchronousTlsChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,AsynchronousByteChannel,AsynchronousChannel,Channel,ExtendedAsynchronousByteChannel
AsynchronousByteChannel that works using TlsChannels.-
Constructor Summary
ConstructorsConstructorDescriptionAsynchronousTlsChannel(AsynchronousTlsChannelGroup channelGroup, TlsChannel tlsChannel, SocketChannel socketChannel) Initializes a new instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this channel.booleanisOpen()Tells whether or not this channel is open.read(ByteBuffer dst) <A> voidread(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attach, CompletionHandler<Long, ? super A> handler) Reads a sequence of bytes from this channel into a subsequence of the given buffers.<A> voidread(ByteBuffer dst, long timeout, TimeUnit unit, A attach, CompletionHandler<Integer, ? super A> handler) Reads a sequence of bytes from this channel into the given buffer.<A> voidread(ByteBuffer dst, A attach, CompletionHandler<Integer, ? super A> handler) write(ByteBuffer src) <A> voidwrite(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attach, CompletionHandler<Long, ? super A> handler) Writes a sequence of bytes to this channel from a subsequence of the given buffers.<A> voidwrite(ByteBuffer src, long timeout, TimeUnit unit, A attach, CompletionHandler<Integer, ? super A> handler) Writes a sequence of bytes to this channel from the given buffer.<A> voidwrite(ByteBuffer src, A attach, CompletionHandler<Integer, ? super A> handler)
-
Constructor Details
-
AsynchronousTlsChannel
public AsynchronousTlsChannel(AsynchronousTlsChannelGroup channelGroup, TlsChannel tlsChannel, SocketChannel socketChannel) throws ClosedChannelException, IllegalArgumentException Initializes a new instance of this class.- Parameters:
channelGroup- group to associate new new channel totlsChannel- existing TLS channel to be used asynchronouslysocketChannel- underlying socket- Throws:
ClosedChannelException- if any of the underlying channels are closed.IllegalArgumentException- is the socket is in blocking mode
-
-
Method Details
-
read
- Specified by:
readin interfaceAsynchronousByteChannel
-
read
public <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attach, CompletionHandler<Integer, ? super A> handler) Description copied from interface:ExtendedAsynchronousByteChannelReads a sequence of bytes from this channel into the given buffer.This method initiates an asynchronous read operation to read a sequence of bytes from this channel into the given buffer. The
handlerparameter is a completion handler that is invoked when the read operation completes (or fails). The result passed to the completion handler is the number of bytes read or-1if no bytes could be read because the channel has reached end-of-stream.If a timeout is specified and the timeout elapses before the operation completes then the operation completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been read, or will not be read from the channel into the given buffer, then further attempts to read from the channel will cause an unspecific runtime exception to be thrown.Otherwise this method works in the same manner as the
AsynchronousByteChannel.read(ByteBuffer,Object,CompletionHandler)method.- Specified by:
readin interfaceExtendedAsynchronousByteChannel- Type Parameters:
A- The type for the object to the attached to the operation- Parameters:
dst- The buffer into which bytes are to be transferredtimeout- The maximum time for the I/O operation to completeunit- The time unit of thetimeoutargumentattach- The object to attach to the I/O operation; can benullhandler- The handler for consuming the result
-
read
public <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attach, CompletionHandler<Long, ? super A> handler) Description copied from interface:ExtendedAsynchronousByteChannelReads a sequence of bytes from this channel into a subsequence of the given buffers. This operation, sometimes called a scattering read, is often useful when implementing network protocols that group data into segments consisting of one or more fixed-length headers followed by a variable-length body. Thehandlerparameter is a completion handler that is invoked when the read operation completes (or fails). The result passed to the completion handler is the number of bytes read or-1if no bytes could be read because the channel has reached end-of-stream.This method initiates a read of up to r bytes from this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,
at the moment that the read is attempted.dsts[offset].remaining() + dsts[offset+1].remaining() + ... + dsts[offset+length-1].remaining()Suppose that a byte sequence of length n is read, where
0<n<=r. Up to the firstdsts[offset].remaining()bytes of this sequence are transferred into bufferdsts[offset], up to the nextdsts[offset+1].remaining()bytes are transferred into bufferdsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been read, or will not be read from the channel into the given buffers, then further attempts to read from the channel will cause an unspecific runtime exception to be thrown.- Specified by:
readin interfaceExtendedAsynchronousByteChannel- Type Parameters:
A- The type for the object to the attached to the operation- Parameters:
dsts- The buffers into which bytes are to be transferredoffset- The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger thandsts.lengthlength- The maximum number of buffers to be accessed; must be non-negative and no larger thandsts.length - offsettimeout- The maximum time for the I/O operation to completeunit- The time unit of thetimeoutargumentattach- The object to attach to the I/O operation; can benullhandler- The handler for consuming the result
-
read
- Specified by:
readin interfaceAsynchronousByteChannel
-
write
- Specified by:
writein interfaceAsynchronousByteChannel
-
write
public <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attach, CompletionHandler<Integer, ? super A> handler) Description copied from interface:ExtendedAsynchronousByteChannelWrites a sequence of bytes to this channel from the given buffer.This method initiates an asynchronous write operation to write a sequence of bytes to this channel from the given buffer. The
handlerparameter is a completion handler that is invoked when the write operation completes (or fails). The result passed to the completion handler is the number of bytes written.If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been written, or will not be written to the channel from the given buffer, then further attempts to write to the channel will cause an unspecific runtime exception to be thrown.Otherwise this method works in the same manner as the
AsynchronousByteChannel.write(ByteBuffer,Object,CompletionHandler)method.- Specified by:
writein interfaceExtendedAsynchronousByteChannel- Type Parameters:
A- The type for the object to the attached to the operation- Parameters:
src- The buffer from which bytes are to be retrievedtimeout- The maximum time for the I/O operation to completeunit- The time unit of thetimeoutargumentattach- The object to attach to the I/O operation; can benullhandler- The handler for consuming the result
-
write
public <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attach, CompletionHandler<Long, ? super A> handler) Description copied from interface:ExtendedAsynchronousByteChannelWrites a sequence of bytes to this channel from a subsequence of the given buffers. This operation, sometimes called a gathering write, is often useful when implementing network protocols that group data into segments consisting of one or more fixed-length headers followed by a variable-length body. Thehandlerparameter is a completion handler that is invoked when the write operation completes (or fails). The result passed to the completion handler is the number of bytes written.This method initiates a write of up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,
at the moment that the write is attempted.srcs[offset].remaining() + srcs[offset+1].remaining() + ... + srcs[offset+length-1].remaining()Suppose that a byte sequence of length n is written, where
0<n<=r. Up to the firstsrcs[offset].remaining()bytes of this sequence are written from buffersrcs[offset], up to the nextsrcs[offset+1].remaining()bytes are written from buffersrcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been written, or will not be written to the channel from the given buffers, then further attempts to write to the channel will cause an unspecific runtime exception to be thrown.- Specified by:
writein interfaceExtendedAsynchronousByteChannel- Type Parameters:
A- The type for the object to the attached to the operation- Parameters:
srcs- The buffers from which bytes are to be retrievedoffset- The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger thansrcs.lengthlength- The maximum number of buffers to be accessed; must be non-negative and no larger thansrcs.length - offsettimeout- The maximum time for the I/O operation to completeunit- The time unit of thetimeoutargumentattach- The object to attach to the I/O operation; can benullhandler- The handler for consuming the result
-
write
- Specified by:
writein interfaceAsynchronousByteChannel
-
isOpen
public boolean isOpen()Tells whether or not this channel is open. -
close
Closes this channel.This method will close the underlying
TlsChanneland also deregister it from its group.- Specified by:
closein interfaceAsynchronousChannel- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- If an I/O error occurs
-