public class SSLDataChannel extends AbstractDataChannel
DataChannel.CloseAsyncStatus, DataChannel.FlushStatusconfiguredBlocking, socketChannel| Constructor and Description |
|---|
SSLDataChannel(SocketChannel socketChannel,
SSLEngine sslEngine,
String targetHost,
HostnameVerifier hostVerifier,
SSLAuthenticator authenticator,
InstanceLogger logger)
Construct an SSLDataChannel given a SocketChannel and an SSLEngine
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this channel, which should be a blocking channel.
|
DataChannel.CloseAsyncStatus |
closeAsync()
Closes this channel, which should be a non-blocking channel.
|
void |
closeForcefully()
Closes this channel forcefully.
|
void |
configureBlocking(boolean block)
Configures the channel to be blocking.
|
DataChannel.FlushStatus |
flush()
Attempt to flush any pending writes to the underlying socket buffer.
|
boolean |
isOpen() |
boolean |
isSecure()
Is the channel encrypted?
|
boolean |
isTrustCapable()
Is the channel capable of determining peer trust?
In this case, we are capable only if the application has configured an
SSL authenticator
|
boolean |
isTrusted()
Is the channel peer trusted?
A channel is trusted if the peer should be treated as authenticated.
|
int |
read(ByteBuffer toFill)
Read data into the toFill data buffer.
|
long |
read(ByteBuffer[] toFill) |
long |
read(ByteBuffer[] toFill,
int offset,
int length)
Reads a sequence of bytes from this channel into a subsequence of the
given buffers.
|
int |
write(ByteBuffer toSend) |
long |
write(ByteBuffer[] toSend) |
long |
write(ByteBuffer[] toSend,
int offset,
int length)
Writes a sequence of bytes to this channel from a subsequence of the
given buffers.
|
ensureCloseAsyncForNonBlocking, ensureCloseForBlocking, getRemoteAddress, getSocketChannel, isBlocking, isConnected, socketpublic SSLDataChannel(SocketChannel socketChannel, SSLEngine sslEngine, String targetHost, HostnameVerifier hostVerifier, SSLAuthenticator authenticator, InstanceLogger logger)
socketChannel - a SocketChannel over which SSL communcation will
occur. This should generally be connected, but that is not
absolutely required until the first read/write operation.sslEngine - an SSLEngine instance that will control the SSL
interaction with the peer.public void configureBlocking(boolean block)
throws IOException
configureBlocking in interface DataChannelconfigureBlocking in class AbstractDataChannelIOExceptionpublic boolean isSecure()
public boolean isTrustCapable()
public boolean isTrusted()
public int read(ByteBuffer toFill) throws IOException, SSLException
toFill - the data buffer into which data will be read. This buffer
is expected to be ready for a put. It need not be empty.IOExceptionSSLExceptionpublic long read(ByteBuffer[] toFill) throws IOException, SSLException
IOExceptionSSLExceptionpublic long read(ByteBuffer[] toFill, int offset, int length) throws IOException, SSLException
DataChannelThe method throws ClosedChannelException after channel is
closed. The channel is closed if any of the DataChannel.close(), DataChannel.closeForcefully() or DataChannel.closeAsync() was called (regardless of
the return value or exception thrown). The method may throw AsynchronousCloseException when another thread is closing the channel
concurrently.
The method should not block any of the close methods.
IOExceptionSSLExceptionpublic int write(ByteBuffer toSend) throws IOException, SSLException
IOExceptionSSLExceptionpublic long write(ByteBuffer[] toSend) throws IOException, SSLException
IOExceptionSSLExceptionpublic long write(ByteBuffer[] toSend, int offset, int length) throws IOException, SSLException
DataChannelThe behavior w.r.t the DataChannel.flush() method:
The behavior w.r.t the channel-close methods:
ClosedChannelException after channel is
closed. The channel is closed if any of the DataChannel.close(), DataChannel.closeForcefully() or DataChannel.closeAsync() was called and exited
(regardless of the return value or exception thrown). The method may
throw AsynchronousCloseException when another thread is closing
the channel concurrently.IOExceptionSSLExceptionpublic DataChannel.FlushStatus flush() throws IOException
IOExceptionpublic void close()
throws IOException,
SSLException
DataChannelIt is considered a coding error to call this method if the channel is
configured as non-blocking: use DataChannel.closeAsync() or DataChannel.closeForcefully() instead. If called for a non-blocking channel, this
method closes the channel forcefully and throws IllegalStateException.
The method cleanly closes the channel, blocking if necessary. The
method should only be blocked for its own connection operations (i.e.,
not by concurrent DataChannel.read(java.nio.ByteBuffer[], int, int),DataChannel.write(java.nio.ByteBuffer[], int, int), DataChannel.flush() methods
or lock acquisitions, etc). The method throws IOException if the
connection is unresponsive and timed out.
If the method detects a concurrent DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) or
DataChannel.flush() method being called, the method throws IOException.
Implementations of this method should flush written data before closing the channel.
If an error occurs, the method attempts to forcefully close the channel, before throwing the exception. Only the first encountered exception is thrown.
The channel is closed (i.e., isOpen returns false)
after this method returns, even if an exception is thrown. The DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) and DataChannel.flush() methods will throw ClosedChannelException when the channel is closed. These methods may
throw AsynchronousCloseException if called concurrently with
this method.
IOException - if an error occursSSLExceptionpublic DataChannel.CloseAsyncStatus closeAsync() throws IOException
DataChannelIt is considered a coding error to call this method if the channel is
configured as blocking: use DataChannel.close() or DataChannel.closeForcefully()
instead. If called for a blocking channel, this method closes the
channel forcefully and throws IllegalStateException.
The method cleanly closes the channel in a non-blocking manner. The
channel is closed (i.e., isOpen returns false) once the
method is called (regardless of return value or exception thrown). The
caller, however, should keep calling this method until it returns true or throws exception. The channel is cleanly closed if the method
returns true or forcefully closed if the method throws
exception.
Implementations of this method should flush written data before closing the channel.
If the method detects a concurrent DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) or
DataChannel.flush() method being called, the method throws IOException.
If an error occurs, the method attempts to forcefully close the channel, before throwing the exception. Only the first encountered exception is thrown.
The DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) and DataChannel.flush() methods will
throw ClosedChannelException when the channel is closed. These
methods may throw AsynchronousCloseException if called
concurrently with this method.
true if the channel is cleanly closedIOException - if there is an errorpublic void closeForcefully()
throws IOException
DataChannelThe method returns immediately, i.e., it should not be blocked by
concurrent DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) or DataChannel.flush() methods, nor
should it be blocked by socket operations.
The method does not guarantee to flush written data before closing the channel, nor does it guarantee to do any procedure required for a clean close.
The channel is closed (i.e., isOpen returns false)
after this method returns. The DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) and DataChannel.flush() methods will throw ClosedChannelException when the
channel is closed. These methods may throw AsynchronousCloseException if called concurrently with this method.
IOException - if an error occurspublic boolean isOpen()
Copyright © 2024. All rights reserved.