@Internal public interface IOSession extends ByteChannel, SocketModalCloseable, Identifiable
The channel associated with implementations of this interface can be used to read data from and write data to the session.
I/O sessions are not bound to an execution thread, therefore one cannot use the context of the thread to store a session's state. All details about a particular session must be stored within the session itself, usually using execution context associated with it.
Implementations of this interface are expected to be threading safe.
Modifier and Type | Interface and Description |
---|---|
static class |
IOSession.Status
This enum represents a set of states I/O session transitions through
during its life-span.
|
Modifier and Type | Method and Description |
---|---|
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 |
enqueue(Command command,
Command.Priority priority)
Inserts
Command at the end of the command queue. |
int |
getEventMask()
Returns mask of I/O evens this session declared interest in.
|
IOEventHandler |
getHandler()
Returns event handler associated with the session.
|
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.
|
SocketAddress |
getLocalAddress()
Returns local address.
|
Lock |
getLock()
Returns session lock that should be used by I/O event handlers
to synchronize access to the session.
|
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:
|
boolean |
hasCommands()
Tests if there enqueued commands pending execution.
|
Command |
poll()
Removes first
Command from the command queue if available. |
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 session
|
void |
setSocketTimeout(Timeout timeout)
Sets value of the socket timeout in milliseconds.
|
void |
updateReadTime()
Updates the timestamp of the last read event
|
void |
updateWriteTime()
Updates the timestamp of the last write event
|
void |
upgrade(IOEventHandler handler)
Upgrades event handler associated with the session.
|
read
write
close
getId
IOEventHandler getHandler()
void upgrade(IOEventHandler handler)
Lock getLock()
void enqueue(Command command, Command.Priority priority)
Command
at the end of the command queue.boolean hasCommands()
ByteChannel channel()
SocketAddress getRemoteAddress()
SocketAddress getLocalAddress()
int getEventMask()
void setEventMask(int ops)
ops
- new I/O event mask.void setEvent(int op)
op
- I/O event type.void clearEvent(int op)
op
- I/O event type.void close()
IOSession.Status getStatus()
IOSession.Status.ACTIVE
: session is active.
IOSession.Status.CLOSING
: session is being closed.
IOSession.Status.CLOSED
: session has been terminated.
Timeout getSocketTimeout()
0
signifies the session cannot time out.getSocketTimeout
in interface SocketModalCloseable
void setSocketTimeout(Timeout timeout)
0
signifies the session cannot time out.
Please note this operation may affect the last event time.
setSocketTimeout
in interface SocketModalCloseable
timeout
- socket timeout.getLastEventTime()
long getLastReadTime()
long getLastWriteTime()
long getLastEventTime()
getSocketTimeout()
void updateReadTime()
void updateWriteTime()
Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.