Package org.apache.hc.core5.reactor
Class InternalDataChannel
- java.lang.Object
-
- org.apache.hc.core5.reactor.InternalChannel
-
- org.apache.hc.core5.reactor.InternalDataChannel
-
- 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
,ProtocolIOSession
,TransportSecurityLayer
,Identifiable
final class InternalDataChannel extends InternalChannel implements ProtocolIOSession
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.hc.core5.reactor.IOSession
IOSession.Status
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
closed
private java.util.Queue<InternalDataChannel>
closedSessions
private java.util.concurrent.atomic.AtomicReference<IOSession>
currentSessionRef
private java.util.concurrent.atomic.AtomicReference<IOEventHandler>
eventHandlerRef
private NamedEndpoint
initialEndpoint
private IOSession
ioSession
private Decorator<IOSession>
ioSessionDecorator
private java.util.concurrent.ConcurrentMap<java.lang.String,ProtocolUpgradeHandler>
protocolUpgradeHandlerMap
private IOSessionListener
sessionListener
private java.util.concurrent.atomic.AtomicReference<SSLIOSession>
tlsSessionRef
-
Constructor Summary
Constructors Constructor Description InternalDataChannel(IOSession ioSession, NamedEndpoint initialEndpoint, Decorator<IOSession> ioSessionDecorator, IOSessionListener sessionListener, java.util.Queue<InternalDataChannel> closedSessions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.channels.ByteChannel
channel()
Returns the underlying I/O channel associated with this session.void
clearEvent(int op)
Clears interest in a particular I/O event type by updating the event mask associated with the session.void
close()
Terminates the session gracefully and closes the underlying I/O channel.void
close(CloseMode closeMode)
Closes this process or endpoint and releases any system resources associated with it.(package private) void
disconnected()
void
enqueue(Command command, Command.Priority priority)
InsertsCommand
at the end of the command queue.private IOEventHandler
ensureHandler(IOSession session)
int
getEventMask()
Returns mask of I/O evens this session declared interest in.IOEventHandler
getHandler()
Returns event handler associated with the session.java.lang.String
getId()
NamedEndpoint
getInitialEndpoint()
long
getLastEventTime()
Returns timestamp of the last I/O event including socket timeout reset.long
getLastReadTime()
Returns timestamp of the last read event.long
getLastWriteTime()
Returns timestamp of the last write event.java.net.SocketAddress
getLocalAddress()
Returns local address.java.util.concurrent.locks.Lock
getLock()
Returns session lock that should be used by I/O event handlers to synchronize access to the session.java.net.SocketAddress
getRemoteAddress()
Returns address of the remote peer.Timeout
getSocketTimeout()
Returns value of the socket timeout in milliseconds.IOSession.Status
getStatus()
Returns status of the session:(package private) Timeout
getTimeout()
TlsDetails
getTlsDetails()
Returns details of a fully established TLS session.boolean
hasCommands()
Tests if there enqueued commands pending execution.boolean
isOpen()
(package private) void
onException(java.lang.Exception cause)
(package private) void
onIOEvent(int readyOps)
(package private) void
onTimeout(Timeout timeout)
(package private) void
onTLSSessionEnd(SSLIOSession sslSession)
(package private) void
onTLSSessionStart(SSLIOSession sslSession)
Command
poll()
Removes firstCommand
from the command queue if available.int
read(java.nio.ByteBuffer dst)
void
registerProtocol(java.lang.String protocolId, ProtocolUpgradeHandler upgradeHandler)
Registers protocol upgrade handler with the given application protocol ID.void
setEvent(int op)
Declares interest in a particular I/O event type by updating the event mask associated with the session.void
setEventMask(int ops)
Declares interest in I/O event notifications by setting the event mask associated with the sessionvoid
setSocketTimeout(Timeout timeout)
Sets value of the socket timeout in milliseconds.void
startTls(javax.net.ssl.SSLContext sslContext, NamedEndpoint endpoint, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Timeout handshakeTimeout)
Starts TLS session over an existing network connection with the given SSL context.void
startTls(javax.net.ssl.SSLContext sslContext, NamedEndpoint endpoint, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Timeout handshakeTimeout, FutureCallback<TransportSecurityLayer> callback)
Starts TLS session over an existing network connection with the given SSL context.void
switchProtocol(java.lang.String protocolId, FutureCallback<ProtocolIOSession> callback)
Switches this I/O session to the application protocol with the given ID.java.lang.String
toString()
void
updateReadTime()
Updates the timestamp of the last read eventvoid
updateWriteTime()
Updates the timestamp of the last write eventvoid
upgrade(IOEventHandler handler)
Upgrades event handler associated with the session.int
write(java.nio.ByteBuffer src)
-
Methods inherited from class org.apache.hc.core5.reactor.InternalChannel
checkTimeout, handleIOEvent
-
-
-
-
Field Detail
-
ioSession
private final IOSession ioSession
-
initialEndpoint
private final NamedEndpoint initialEndpoint
-
sessionListener
private final IOSessionListener sessionListener
-
closedSessions
private final java.util.Queue<InternalDataChannel> closedSessions
-
tlsSessionRef
private final java.util.concurrent.atomic.AtomicReference<SSLIOSession> tlsSessionRef
-
currentSessionRef
private final java.util.concurrent.atomic.AtomicReference<IOSession> currentSessionRef
-
eventHandlerRef
private final java.util.concurrent.atomic.AtomicReference<IOEventHandler> eventHandlerRef
-
protocolUpgradeHandlerMap
private final java.util.concurrent.ConcurrentMap<java.lang.String,ProtocolUpgradeHandler> protocolUpgradeHandlerMap
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
-
Constructor Detail
-
InternalDataChannel
InternalDataChannel(IOSession ioSession, NamedEndpoint initialEndpoint, Decorator<IOSession> ioSessionDecorator, IOSessionListener sessionListener, java.util.Queue<InternalDataChannel> closedSessions)
-
-
Method Detail
-
getId
public java.lang.String getId()
- Specified by:
getId
in interfaceIdentifiable
-
getInitialEndpoint
public NamedEndpoint getInitialEndpoint()
- Specified by:
getInitialEndpoint
in interfaceProtocolIOSession
-
getHandler
public IOEventHandler getHandler()
Description copied from interface:IOSession
Returns event handler associated with the session.- Specified by:
getHandler
in interfaceIOSession
-
upgrade
public void upgrade(IOEventHandler handler)
Description copied from interface:IOSession
Upgrades event handler associated with the session.
-
ensureHandler
private IOEventHandler ensureHandler(IOSession session)
-
onIOEvent
void onIOEvent(int readyOps) throws java.io.IOException
- Specified by:
onIOEvent
in classInternalChannel
- Throws:
java.io.IOException
-
getTimeout
Timeout getTimeout()
- Specified by:
getTimeout
in classInternalChannel
-
onTimeout
void onTimeout(Timeout timeout) throws java.io.IOException
- Specified by:
onTimeout
in classInternalChannel
- Throws:
java.io.IOException
-
onException
void onException(java.lang.Exception cause)
- Specified by:
onException
in classInternalChannel
-
onTLSSessionStart
void onTLSSessionStart(SSLIOSession sslSession)
-
onTLSSessionEnd
void onTLSSessionEnd(SSLIOSession sslSession)
-
disconnected
void disconnected()
-
startTls
public void startTls(javax.net.ssl.SSLContext sslContext, NamedEndpoint endpoint, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Timeout handshakeTimeout)
Description copied from interface:TransportSecurityLayer
Starts TLS session over an existing network connection with the given SSL context.NamedEndpoint
details are applicable for client side connections and are used for host name verification, when supported by the SSL engine.- Specified by:
startTls
in interfaceTransportSecurityLayer
- Parameters:
sslContext
- SSL context to be used for this session.endpoint
- optional endpoint details for outgoing client side connections.sslBufferMode
- SSL buffer management mode.initializer
- SSL session initialization callback.verifier
- SSL session verification callback.handshakeTimeout
- the timeout to use while performing the TLS handshake; may benull
.
-
startTls
public void startTls(javax.net.ssl.SSLContext sslContext, NamedEndpoint endpoint, SSLBufferMode sslBufferMode, SSLSessionInitializer initializer, SSLSessionVerifier verifier, Timeout handshakeTimeout, FutureCallback<TransportSecurityLayer> callback)
Description copied from interface:TransportSecurityLayer
Starts TLS session over an existing network connection with the given SSL context.NamedEndpoint
details are applicable for client side connections and are used for host name verification, when supported by the SSL engine.- Specified by:
startTls
in interfaceTransportSecurityLayer
- Parameters:
sslContext
- SSL context to be used for this session.endpoint
- optional endpoint details for outgoing client side connections.sslBufferMode
- SSL buffer management mode.initializer
- SSL session initialization callback.verifier
- SSL session verification callback.handshakeTimeout
- the timeout to use while performing the TLS handshake; may benull
.
-
getTlsDetails
public TlsDetails getTlsDetails()
Description copied from interface:TransportSecurityLayer
Returns details of a fully established TLS session.- Specified by:
getTlsDetails
in interfaceTransportSecurityLayer
- Returns:
- TLS session details.
-
getLock
public java.util.concurrent.locks.Lock getLock()
Description copied from interface:IOSession
Returns session lock that should be used by I/O event handlers to synchronize access to the session.
-
close
public void close()
Description copied from interface:IOSession
Terminates 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:ModalCloseable
Closes 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:
close
in interfaceModalCloseable
- Parameters:
closeMode
- How to close the receiver.
-
getStatus
public IOSession.Status getStatus()
Description copied from interface:IOSession
Returns status of the session:IOSession.Status.ACTIVE
: session is active.IOSession.Status.CLOSING
: session is being closed.IOSession.Status.CLOSED
: session has been terminated.
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
enqueue
public void enqueue(Command command, Command.Priority priority)
Description copied from interface:IOSession
InsertsCommand
at the end of the command queue.
-
hasCommands
public boolean hasCommands()
Description copied from interface:IOSession
Tests if there enqueued commands pending execution.- Specified by:
hasCommands
in interfaceIOSession
-
poll
public Command poll()
Description copied from interface:IOSession
Removes firstCommand
from the command queue if available.
-
channel
public java.nio.channels.ByteChannel channel()
Description copied from interface:IOSession
Returns the underlying I/O channel associated with this session.
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress()
Description copied from interface:IOSession
Returns address of the remote peer.- Specified by:
getRemoteAddress
in interfaceIOSession
- Returns:
- socket address.
-
getLocalAddress
public java.net.SocketAddress getLocalAddress()
Description copied from interface:IOSession
Returns local address.- Specified by:
getLocalAddress
in interfaceIOSession
- Returns:
- socket address.
-
getEventMask
public int getEventMask()
Description copied from interface:IOSession
Returns mask of I/O evens this session declared interest in.- Specified by:
getEventMask
in interfaceIOSession
- Returns:
- I/O event mask.
-
setEventMask
public void setEventMask(int ops)
Description copied from interface:IOSession
Declares interest in I/O event notifications by setting the event mask associated with the session- Specified by:
setEventMask
in interfaceIOSession
- Parameters:
ops
- new I/O event mask.
-
setEvent
public void setEvent(int op)
Description copied from interface:IOSession
Declares 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:IOSession
Clears interest in a particular I/O event type by updating the event mask associated with the session.- Specified by:
clearEvent
in interfaceIOSession
- Parameters:
op
- I/O event type.
-
getSocketTimeout
public Timeout getSocketTimeout()
Description copied from interface:IOSession
Returns value of the socket timeout in milliseconds. The value of0
signifies the session cannot time out.- Specified by:
getSocketTimeout
in interfaceIOSession
- Specified by:
getSocketTimeout
in interfaceSocketModalCloseable
- Returns:
- socket timeout.
-
setSocketTimeout
public void setSocketTimeout(Timeout timeout)
Description copied from interface:IOSession
Sets value of the socket timeout in milliseconds. The value of0
signifies the session cannot time out.Please note this operation may affect the last event time.
- Specified by:
setSocketTimeout
in interfaceIOSession
- Specified by:
setSocketTimeout
in interfaceSocketModalCloseable
- Parameters:
timeout
- socket timeout.- See Also:
IOSession.getLastEventTime()
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Throws:
java.io.IOException
-
updateReadTime
public void updateReadTime()
Description copied from interface:IOSession
Updates the timestamp of the last read event- Specified by:
updateReadTime
in interfaceIOSession
-
updateWriteTime
public void updateWriteTime()
Description copied from interface:IOSession
Updates the timestamp of the last write event- Specified by:
updateWriteTime
in interfaceIOSession
-
getLastReadTime
public long getLastReadTime()
Description copied from interface:IOSession
Returns timestamp of the last read event.- Specified by:
getLastReadTime
in interfaceIOSession
- Returns:
- timestamp.
-
getLastWriteTime
public long getLastWriteTime()
Description copied from interface:IOSession
Returns timestamp of the last write event.- Specified by:
getLastWriteTime
in interfaceIOSession
- Returns:
- timestamp.
-
getLastEventTime
public long getLastEventTime()
Description copied from interface:IOSession
Returns timestamp of the last I/O event including socket timeout reset.- Specified by:
getLastEventTime
in interfaceIOSession
- Specified by:
getLastEventTime
in classInternalChannel
- Returns:
- timestamp.
- See Also:
IOSession.getSocketTimeout()
-
switchProtocol
public void switchProtocol(java.lang.String protocolId, FutureCallback<ProtocolIOSession> callback)
Description copied from interface:ProtocolIOSession
Switches this I/O session to the application protocol with the given ID.- Specified by:
switchProtocol
in interfaceProtocolIOSession
- Parameters:
protocolId
- the application protocol IDcallback
- the result callback
-
registerProtocol
public void registerProtocol(java.lang.String protocolId, ProtocolUpgradeHandler upgradeHandler)
Description copied from interface:ProtocolIOSession
Registers protocol upgrade handler with the given application protocol ID.- Specified by:
registerProtocol
in interfaceProtocolIOSession
- Parameters:
protocolId
- the application protocol IDupgradeHandler
- the upgrade handler.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-