Package org.apache.hc.core5.reactor.ssl
Class SSLIOSession
- java.lang.Object
-
- org.apache.hc.core5.reactor.ssl.SSLIOSession
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.ByteChannel,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,java.nio.channels.WritableByteChannel,SocketModalCloseable,ModalCloseable,IOSession,Identifiable
@Contract(threading=SAFE_CONDITIONAL) @Internal public class SSLIOSession extends java.lang.Object implements IOSession
SSLIOSessionis a decorator class intended to transparently extend anIOSessionwith transport layer security capabilities based on the SSL/TLS protocol.- Since:
- 4.2
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.hc.core5.reactor.IOSession
IOSession.Status
-
-
Constructor Summary
Constructors Constructor Description SSLIOSession(NamedEndpoint targetEndpoint, IOSession session, SSLMode sslMode, javax.net.ssl.SSLContext sslContext, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Callback<SSLIOSession> sessionStartCallback, Callback<SSLIOSession> sessionEndCallback, Timeout connectTimeout)Creates new instance ofSSLIOSessionclass.SSLIOSession(NamedEndpoint targetEndpoint, IOSession session, SSLMode sslMode, javax.net.ssl.SSLContext sslContext, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Timeout handshakeTimeout, Callback<SSLIOSession> sessionStartCallback, Callback<SSLIOSession> sessionEndCallback, FutureCallback<javax.net.ssl.SSLSession> resultCallback)Creates new instance ofSSLIOSessionclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginHandshake(IOSession protocolSession)java.nio.channels.ByteChannelchannel()Returns the underlying I/O channel associated with this session.voidclearEvent(int op)Clears interest in a particular I/O event type by updating the event mask associated with the session.voidclose()Terminates the session gracefully and closes the underlying I/O channel.voidclose(CloseMode closeMode)Closes this process or endpoint and releases any system resources associated with it.voidenqueue(Command command, Command.Priority priority)InsertsCommandat the end of the command queue.intgetEventMask()Returns mask of I/O evens this session declared interest in.IOEventHandlergetHandler()Returns event handler associated with the session.java.lang.StringgetId()longgetInitiationTime()Returns the absolute millisecond timestamp of the session initiation.longgetLastEventTime()Returns the absolute millisecond timestamp of the last I/O event including socket timeout reset.longgetLastReadTime()Returns the absolute millisecond timestamp of the last read event.longgetLastWriteTime()Returns the absolute millisecond timestamp of the last write event.java.net.SocketAddressgetLocalAddress()Returns local address.java.util.concurrent.locks.LockgetLock()Returns session lock that should be used by I/O event handlers to synchronize access to the session.intgetPendingCommandCount()Returns the number of pending commands enqueued for execution, or-1if unknown.java.net.SocketAddressgetRemoteAddress()Returns address of the remote peer.TimeoutgetSocketTimeout()Returns value of the socket timeout in milliseconds.IOSession.StatusgetStatus()Returns status of the session:TlsDetailsgetTlsDetails()booleanhasCommands()Tests if there enqueued commands pending execution.booleanisOpen()Commandpoll()Removes firstCommandfrom the command queue if available.intread(java.nio.ByteBuffer dst)voidsetEvent(int op)Declares interest in a particular I/O event type by updating the event mask associated with the session.voidsetEventMask(int ops)Declares interest in I/O event notifications by setting the event mask associated with the sessionvoidsetSocketTimeout(Timeout timeout)Sets value of the socket timeout in milliseconds.java.lang.StringtoString()voidupdateReadTime()Updates the timestamp of the last read eventvoidupdateWriteTime()Updates the timestamp of the last write eventvoidupgrade(IOEventHandler handler)Upgrades event handler associated with the session.intwrite(java.nio.ByteBuffer src)
-
-
-
Constructor Detail
-
SSLIOSession
public SSLIOSession(NamedEndpoint targetEndpoint, IOSession session, SSLMode sslMode, javax.net.ssl.SSLContext sslContext, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Callback<SSLIOSession> sessionStartCallback, Callback<SSLIOSession> sessionEndCallback, Timeout connectTimeout)
Creates new instance ofSSLIOSessionclass.- Parameters:
session- I/O session to be decorated with the TLS/SSL capabilities.sslMode- SSL mode (client or server)targetEndpoint- target endpoint (applicable in client mode only). May benull.sslContext- SSL context to use for this I/O session.sslBufferMode- buffer management modeinitializer- optional SSL session initializer. May benull.verifier- optional SSL session verifier. May benull.connectTimeout- timeout to apply for the TLS/SSL handshake. May benull.- Since:
- 5.0
-
SSLIOSession
public SSLIOSession(NamedEndpoint targetEndpoint, IOSession session, SSLMode sslMode, javax.net.ssl.SSLContext sslContext, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Timeout handshakeTimeout, Callback<SSLIOSession> sessionStartCallback, Callback<SSLIOSession> sessionEndCallback, FutureCallback<javax.net.ssl.SSLSession> resultCallback)
Creates new instance ofSSLIOSessionclass.- Parameters:
session- I/O session to be decorated with the TLS/SSL capabilities.sslMode- SSL mode (client or server)targetEndpoint- target endpoint (applicable in client mode only). May benull.sslContext- SSL context to use for this I/O session.sslBufferMode- buffer management modeinitializer- optional SSL session initializer. May benull.verifier- optional SSL session verifier. May benull.handshakeTimeout- timeout to apply for the TLS/SSL handshake. May benull.resultCallback- result callback. May benull.- Since:
- 5.2
-
-
Method Detail
-
getHandler
public IOEventHandler getHandler()
Description copied from interface:IOSessionReturns event handler associated with the session.- Specified by:
getHandlerin interfaceIOSession- Returns:
- the event handler, or
nullif no handler is associated with the session.
-
beginHandshake
public void beginHandshake(IOSession protocolSession) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst)
- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel
-
getId
public java.lang.String getId()
- Specified by:
getIdin interfaceIdentifiable
-
getLock
public java.util.concurrent.locks.Lock getLock()
Description copied from interface:IOSessionReturns session lock that should be used by I/O event handlers to synchronize access to the session.
-
upgrade
public void upgrade(IOEventHandler handler)
Description copied from interface:IOSessionUpgrades event handler associated with the session.
-
getTlsDetails
public TlsDetails getTlsDetails()
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
close
public void close()
Description copied from interface:IOSessionTerminates the session gracefully and closes the underlying I/O channel. This method ensures that session termination handshake, such as the one used by the SSL/TLS protocol, is correctly carried out.
-
close
public void close(CloseMode closeMode)
Description copied from interface:ModalCloseableCloses this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.- Specified by:
closein interfaceModalCloseable- Parameters:
closeMode- How to close the receiver.
-
getStatus
public IOSession.Status getStatus()
Description copied from interface:IOSessionReturns status of the session:IOSession.Status.ACTIVE: session is active.IOSession.Status.CLOSING: session is being closed.IOSession.Status.CLOSED: session has been terminated.
-
enqueue
public void enqueue(Command command, Command.Priority priority)
Description copied from interface:IOSessionInsertsCommandat the end of the command queue.
-
hasCommands
public boolean hasCommands()
Description copied from interface:IOSessionTests if there enqueued commands pending execution.- Specified by:
hasCommandsin interfaceIOSession
-
poll
public Command poll()
Description copied from interface:IOSessionRemoves firstCommandfrom the command queue if available.
-
channel
public java.nio.channels.ByteChannel channel()
Description copied from interface:IOSessionReturns the underlying I/O channel associated with this session.
-
getLocalAddress
public java.net.SocketAddress getLocalAddress()
Description copied from interface:IOSessionReturns local address.- Specified by:
getLocalAddressin interfaceIOSession- Returns:
- socket address, or
nullif unavailable.
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress()
Description copied from interface:IOSessionReturns address of the remote peer.- Specified by:
getRemoteAddressin interfaceIOSession- Returns:
- socket address, or
nullif unavailable.
-
getEventMask
public int getEventMask()
Description copied from interface:IOSessionReturns mask of I/O evens this session declared interest in.- Specified by:
getEventMaskin interfaceIOSession- Returns:
- I/O event mask.
-
setEventMask
public void setEventMask(int ops)
Description copied from interface:IOSessionDeclares interest in I/O event notifications by setting the event mask associated with the session- Specified by:
setEventMaskin interfaceIOSession- Parameters:
ops- new I/O event mask.
-
setEvent
public void setEvent(int op)
Description copied from interface:IOSessionDeclares interest in a particular I/O event type by updating the event mask associated with the session.
-
clearEvent
public void clearEvent(int op)
Description copied from interface:IOSessionClears interest in a particular I/O event type by updating the event mask associated with the session.- Specified by:
clearEventin interfaceIOSession- Parameters:
op- I/O event type.
-
getSocketTimeout
public Timeout getSocketTimeout()
Description copied from interface:IOSessionReturns value of the socket timeout in milliseconds. The value of0signifies the session cannot time out.- Specified by:
getSocketTimeoutin interfaceIOSession- Specified by:
getSocketTimeoutin interfaceSocketModalCloseable- Returns:
- socket timeout.
-
setSocketTimeout
public void setSocketTimeout(Timeout timeout)
Description copied from interface:IOSessionSets value of the socket timeout in milliseconds. The value of0signifies the session cannot time out.Please note this operation may affect the last event time.
- Specified by:
setSocketTimeoutin interfaceIOSession- Specified by:
setSocketTimeoutin interfaceSocketModalCloseable- Parameters:
timeout- socket timeout.- See Also:
IOSession.getLastEventTime()
-
getInitiationTime
public long getInitiationTime()
Description copied from interface:IOSessionReturns the absolute millisecond timestamp of the session initiation.- Specified by:
getInitiationTimein interfaceIOSession
-
updateReadTime
public void updateReadTime()
Description copied from interface:IOSessionUpdates the timestamp of the last read event- Specified by:
updateReadTimein interfaceIOSession
-
updateWriteTime
public void updateWriteTime()
Description copied from interface:IOSessionUpdates the timestamp of the last write event- Specified by:
updateWriteTimein interfaceIOSession
-
getLastReadTime
public long getLastReadTime()
Description copied from interface:IOSessionReturns the absolute millisecond timestamp of the last read event.- Specified by:
getLastReadTimein interfaceIOSession- Returns:
- timestamp in milliseconds, compatible with
System.currentTimeMillis().
-
getLastWriteTime
public long getLastWriteTime()
Description copied from interface:IOSessionReturns the absolute millisecond timestamp of the last write event.- Specified by:
getLastWriteTimein interfaceIOSession- Returns:
- timestamp in milliseconds, compatible with
System.currentTimeMillis().
-
getLastEventTime
public long getLastEventTime()
Description copied from interface:IOSessionReturns the absolute millisecond timestamp of the last I/O event including socket timeout reset.- Specified by:
getLastEventTimein interfaceIOSession- Returns:
- timestamp in milliseconds, compatible with
System.currentTimeMillis(). - See Also:
IOSession.getSocketTimeout()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getPendingCommandCount
public int getPendingCommandCount()
Description copied from interface:IOSessionReturns the number of pending commands enqueued for execution, or-1if unknown.- Specified by:
getPendingCommandCountin interfaceIOSession
-
-