Package org.apache.hc.core5.reactor
Class IOSessionImpl
java.lang.Object
org.apache.hc.core5.reactor.IOSessionImpl
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,ReadableByteChannel
,WritableByteChannel
,SocketModalCloseable
,ModalCloseable
,IOSession
,Identifiable
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hc.core5.reactor.IOSession
IOSession.Status
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SocketChannel
private static final AtomicLong
Counts instances created.private final AtomicReference
<IOEventHandler> private final String
private final SelectionKey
private long
private long
private long
private final Lock
private Timeout
private final AtomicReference
<IOSession.Status> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchannel()
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
Closes this process or endpoint and releases any system resources associated with it.void
enqueue
(Command command, Command.Priority priority) InsertsCommand
at the end of the command queue.private static void
formatOps
(StringBuilder buffer, int ops) int
Returns mask of I/O evens this session declared interest in.Returns event handler associated with the session.getId()
long
Returns timestamp of the last I/O event including socket timeout reset.long
Returns timestamp of the last read event.long
Returns timestamp of the last write event.Returns local address.getLock()
Returns session lock that should be used by I/O event handlers to synchronize access to the session.Returns address of the remote peer.Returns value of the socket timeout in milliseconds.Returns status of the session:boolean
Tests if there enqueued commands pending execution.boolean
isOpen()
private boolean
poll()
Removes firstCommand
from the command queue if available.int
read
(ByteBuffer dst) 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 newValue) 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.toString()
void
Updates the timestamp of the last read eventvoid
Updates the timestamp of the last write eventvoid
upgrade
(IOEventHandler handler) Upgrades event handler associated with the session.int
write
(ByteBuffer src)
-
Field Details
-
COUNT
Counts instances created. -
key
-
channel
-
commandQueue
-
lock
-
id
-
handlerRef
-
status
-
socketTimeout
-
lastReadTime
private volatile long lastReadTime -
lastWriteTime
private volatile long lastWriteTime -
lastEventTime
private volatile long lastEventTime
-
-
Constructor Details
-
IOSessionImpl
-
-
Method Details
-
getId
- Specified by:
getId
in interfaceIdentifiable
-
getHandler
Description copied from interface:IOSession
Returns event handler associated with the session.- Specified by:
getHandler
in interfaceIOSession
-
upgrade
Description copied from interface:IOSession
Upgrades event handler associated with the session. -
getLock
Description copied from interface:IOSession
Returns session lock that should be used by I/O event handlers to synchronize access to the session. -
enqueue
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
Description copied from interface:IOSession
Removes firstCommand
from the command queue if available. -
channel
Description copied from interface:IOSession
Returns the underlying I/O channel associated with this session. -
getLocalAddress
Description copied from interface:IOSession
Returns local address.- Specified by:
getLocalAddress
in interfaceIOSession
- Returns:
- socket address.
-
getRemoteAddress
Description copied from interface:IOSession
Returns address of the remote peer.- Specified by:
getRemoteAddress
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 newValue) 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:
newValue
- 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
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
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:
-
read
- Specified by:
read
in interfaceReadableByteChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
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
- Returns:
- timestamp.
- See Also:
-
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. -
isStatusClosed
private boolean isStatusClosed() -
isOpen
public boolean isOpen() -
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
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.
-
formatOps
-
toString
-