Package org.omegazero.net.nio.socket
Class NioTLSConnection
java.lang.Object
org.omegazero.common.util.SimpleAttachmentContainer
org.omegazero.net.socket.AbstractSocketConnection
org.omegazero.net.nio.socket.ChannelConnection
org.omegazero.net.nio.socket.NioTLSConnection
- All Implemented Interfaces:
Closeable,AutoCloseable,org.omegazero.common.util.AttachmentContainer,SocketConnection,TLSConnection
A
ChannelConnection with TLS encryption. This implementation uses an SSLEngine from a given SSLContext for TLS support.- API Note:
- Before version 2.1.0, this class was in package
org.omegazero.net.socket.impland calledTLSConnection.
-
Field Summary
FieldsFields inherited from class org.omegazero.net.nio.socket.ChannelConnection
readBuf, writeBufFields inherited from class org.omegazero.net.socket.AbstractSocketConnection
EV_CLOSE, EV_CONNECT, EV_DATA, EV_ERROR, EV_TIMEOUT, EV_WRITABLE, eventEmitter, readLock, writeLockFields inherited from class org.omegazero.common.util.SimpleAttachmentContainer
attachments -
Constructor Summary
ConstructorsConstructorDescriptionNioTLSConnection(SelectionKey selectionKey, ChannelProvider provider, SocketAddress remote, SSLContext sslContext, boolean client, String[] alpnNames, String[] requestedServerNames) NioTLSConnection(SelectionKey selectionKey, ChannelProvider provider, SSLContext sslContext, boolean client, String[] alpnNames) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclose0()Forcibly closes this connection.protected voidMust be called by subclass constructors.voidbooleanflush()Attempts to flush any queued data after a call toSocketConnection.writeQueue(byte[])or data that could not be written previously because the socket was busy.Returns the application layer protocol name negotiated using a mechanism such as Application-Layer Protocol Negotiation (ALPN).Returns the name of the TLS cipher suite used for this connection.Returns the name of the protocol used for this connection.booleanReturnstrueif this socket is connected.booleanReturnstrueif the underlying socket is connected.byte[]read()Reads data received from the peer host on this connection.voidwrite(byte[] data, int offset, int length) Writes data to this connection for delivery to the peer host.voidwriteQueue(byte[] data, int offset, int length) Similar toSocketConnection.write(byte[], int, int), except that no attempt will be made to immediately flush the data to the socket, if supported by the implementation.Methods inherited from class org.omegazero.net.nio.socket.ChannelConnection
close, connect, destroy, flushWriteBacklog, getLastIOTime, getLocalAddress, getProvider, getRemoteAddress, isWritable, readFromSocket, setReadBlock, writeBuffered, writeToSocketMethods inherited from class org.omegazero.net.socket.AbstractSocketConnection
getApparentRemoteAddress, getReadLock, getWorker, getWriteLock, handleClose, handleConnect, handleData, handleError, handleTimeout, handleWritable, hasConnected, localClose, localConnect, off, on, once, queueWrite, runAsync, runAsync, setApparentRemoteAddress, setDefaultErrorListener, setOnLocalClose, setOnLocalConnect, setWorkerMethods inherited from class org.omegazero.common.util.SimpleAttachmentContainer
getAttachment, hasAttachment, removeAttachment, setAttachmentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.omegazero.common.util.AttachmentContainer
requireAttachmentMethods inherited from interface org.omegazero.net.socket.SocketConnection
close, connect, destroy, getApparentRemoteAddress, getLastIOTime, getLocalAddress, getRemoteAddress, hasConnected, hasDisconnected, isWritable, off, on, on, on, once, setApparentRemoteAddress, setOnClose, setOnConnect, setOnData, setOnError, setOnTimeout, setOnWritable, setReadBlock, write, write, writeQueue
-
Field Details
-
readBufUnwrapped
-
writeBufUnwrapped
-
-
Constructor Details
-
NioTLSConnection
public NioTLSConnection(SelectionKey selectionKey, ChannelProvider provider, SSLContext sslContext, boolean client, String[] alpnNames) throws IOException - Throws:
IOException
-
NioTLSConnection
public NioTLSConnection(SelectionKey selectionKey, ChannelProvider provider, SocketAddress remote, SSLContext sslContext, boolean client, String[] alpnNames, String[] requestedServerNames) throws IOException - Throws:
IOException
-
-
Method Details
-
createBuffers
protected void createBuffers()Description copied from class:ChannelConnectionMust be called by subclass constructors. This method creates theChannelConnection.readBufandChannelConnection.writeBufbuffers and any additional buffers required.- Specified by:
createBuffersin classChannelConnection
-
read
public byte[] read()Description copied from interface:SocketConnectionReads data received from the peer host on this connection.Whether this method is blocking is implementation-defined. If no data was available,
nullis returned, or the method blocks until data is available.- Specified by:
readin interfaceSocketConnection- Returns:
- The read data or
nullif no data is available.
-
write
public void write(byte[] data, int offset, int length) Description copied from interface:SocketConnectionWrites data to this connection for delivery to the peer host.Whether this method is blocking is implementation-defined. A call to this method may store data in a temporary write buffer if the underlying socket is busy. An application should try to respect the value of
SocketConnection.isWritable()to reduce memory consumption by such write buffer if a lot of data is being written (see also:writableevent).If this method is called before the
connectevent, the data is queued in a temporary buffer and written out when the socket connects.- Specified by:
writein interfaceSocketConnection- Parameters:
data- The data to writeoffset- The start index of the data to write in the data byte arraylength- The total number of bytes to write from the data byte array, starting at offset- See Also:
-
writeQueue
public void writeQueue(byte[] data, int offset, int length) Description copied from interface:SocketConnectionSimilar toSocketConnection.write(byte[], int, int), except that no attempt will be made to immediately flush the data to the socket, if supported by the implementation.- Specified by:
writeQueuein interfaceSocketConnection- Parameters:
data- The data to writeoffset- The start index of the data to write in the data byte arraylength- The total number of bytes to write from the data byte array, starting at offset- See Also:
-
flush
public boolean flush()Description copied from class:ChannelConnectionAttempts to flush any queued data after a call toSocketConnection.writeQueue(byte[])or data that could not be written previously because the socket was busy.Whether this method is blocking is implementation-defined.
- Specified by:
flushin interfaceSocketConnection- Overrides:
flushin classChannelConnection- Returns:
trueif all data could be written to the socket- See Also:
-
close0
protected void close0()Description copied from class:ChannelConnectionForcibly closes this connection.- Overrides:
close0in classChannelConnection
-
isConnected
public boolean isConnected()Description copied from class:ChannelConnectionReturnstrueif this socket is connected.- Specified by:
isConnectedin interfaceSocketConnection- Specified by:
isConnectedin interfaceTLSConnection- Overrides:
isConnectedin classChannelConnection- Returns:
trueif this socket is open and available for reading or writing- See Also:
-
isSocketConnected
public boolean isSocketConnected()Description copied from interface:TLSConnectionReturnstrueif the underlying socket is connected.- Specified by:
isSocketConnectedin interfaceTLSConnection- Returns:
trueif this socket is connected- See Also:
-
getProtocol
Description copied from interface:TLSConnectionReturns the name of the protocol used for this connection.- Specified by:
getProtocolin interfaceTLSConnection- Returns:
- The protocol name
-
getCipher
Description copied from interface:TLSConnectionReturns the name of the TLS cipher suite used for this connection.- Specified by:
getCipherin interfaceTLSConnection- Returns:
- The TLS cipher name
-
getApplicationProtocol
Description copied from interface:TLSConnectionReturns the application layer protocol name negotiated using a mechanism such as Application-Layer Protocol Negotiation (ALPN). If no such negotiation occurred or is not supported by the protocol or implementation,nullis returned.- Specified by:
getApplicationProtocolin interfaceTLSConnection- Returns:
- The application layer protocol name, or
nullif no negotiation occurred
-
doTLSHandshake
- Throws:
IOException
-