public interface ISession
The implementations provided by the API are thread-safe.
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
allocate(int capacity)
Allocates a byte buffer by using the allocator associated with this session.
|
void |
close()
Gently closes this session after all pending data waiting for writing are fully flushed.
|
void |
dirtyClose()
Quickly closes this session without flushing any pending data and without following
close procedure of an application layer (e.g.
|
IFuture<Void> |
execute(Runnable task)
Executes a task in the selector-loop's thread this session is registered
with.
|
void |
executenf(Runnable task)
Executes a task in the selector-loop's thread this session is registered
with.
|
ConcurrentMap<Object,Object> |
getAttributes()
Returns the thread safe map of the user-defined attributes associated with this session.
|
IFuture<Void> |
getCloseFuture()
Gets the future that can be use to wait for the completion of the closing
phase.
|
ICodecPipeline |
getCodecPipeline()
Gets the codec pipeline that is associated with this session.
|
ISessionConfig |
getConfig()
Gets the configuration of this session.
|
IFuture<Void> |
getCreateFuture()
Gets the future that can be use to wait for the completion of the
creation phase.
|
long |
getCreationTime()
Gets the session's creation time in milliseconds.
|
IFuture<Void> |
getEndFuture()
Gets the future that can be use to wait for the completion of the ending
phase.
|
IHandler |
getHandler()
Gets the handler associated with this session
|
long |
getId()
Gets a unique identifier for this session
|
long |
getLastIoTime()
Gets the time in milliseconds when I/O operation occurred lastly.
|
long |
getLastReadTime()
Gets the time in milliseconds when read operation occurred lastly.
|
long |
getLastWriteTime()
Gets the time in milliseconds when write operation occurred lastly.
|
SocketAddress |
getLocalAddress()
Return the local address this session is bound to.
|
String |
getName()
Gets the name for this session
|
IFuture<Void> |
getOpenFuture()
Gets the future that can be use to wait for the completion of the opening
phase.
|
ISession |
getParent()
Gets the parent session.
|
long |
getReadBytes()
Gets the total number of bytes which were read from this session.
|
double |
getReadBytesThroughput()
Gets the number of read bytes per second.
|
IFuture<Void> |
getReadyFuture()
Gets the future that can be use to wait for the completion of the ready
phase.
|
SocketAddress |
getRemoteAddress()
Returns the remote address to which this session is connected.
|
SessionState |
getState()
Gets the current state of this session.
|
ISessionTimer |
getTimer()
Gets the session timer associated with this session.
|
long |
getWrittenBytes()
Gets the total number of bytes which were written to this session.
|
double |
getWrittenBytesThroughput()
Gets the number of written bytes per second.
|
boolean |
isDataCopyingOptimized()
Tells if the processing of data is optimized to reduce data copying between
byte buffers.
|
boolean |
isOpen()
Tells if this session is open.
|
boolean |
isReadSuspended()
Tells if read operations are suspended for this session.
|
boolean |
isWriteSuspended()
Tells if write operations are suspended for this session.
|
void |
quickClose()
Quickly closes this session without flushing any pending data.
|
void |
release(ByteBuffer buffer)
Release given byte buffer by the allocator associated with this session.
|
void |
resumeRead()
Resumes read operations for this session.
|
void |
resumeWrite()
Resumes write operations for this session.
|
void |
suspendRead()
Suspends read operations for this session.
|
void |
suspendWrite()
Suspends write operations for this session.
|
long getId()
String getName()
IHandler getHandler()
ISessionConfig getConfig()
ICodecPipeline getCodecPipeline()
null
if the session does not
support itSessionState getState()
boolean isOpen()
It is equal to:
return getState() == SessionState.OPEN
true
if the session is open.void close()
After returning from this method any consecutive writes will be simply discarded.
void quickClose()
After returning from this method any consecutive writes will be simply discarded.
void dirtyClose()
ConcurrentMap<Object,Object> getAttributes()
SocketAddress getLocalAddress()
null
if this session is not
bound yetSocket
SocketAddress getRemoteAddress()
null
if this session is not
connected yetSocket
void suspendRead()
IllegalSessionStateException
- if this session is not openvoid suspendWrite()
IllegalSessionStateException
- if this session is not openvoid resumeRead()
IllegalSessionStateException
- if this session is not openvoid resumeWrite()
IllegalSessionStateException
- if this session is not openboolean isReadSuspended()
true
if suspendedboolean isWriteSuspended()
true
if suspendedlong getReadBytes()
long getWrittenBytes()
double getReadBytesThroughput()
double getWrittenBytesThroughput()
long getCreationTime()
long getLastIoTime()
long getLastReadTime()
long getLastWriteTime()
IFuture<Void> getCreateFuture()
IFuture<Void> getOpenFuture()
IFuture<Void> getReadyFuture()
IFuture<Void> getCloseFuture()
IFuture<Void> getEndFuture()
ISession getParent()
Some sessions may not implement its own I/O functionalities and use their parent's ones instead.
null
if it does not exist.ISessionTimer getTimer()
boolean isDataCopyingOptimized()
Checking this flag can be helpful in determining if a buffer allocated by the
allocate(int)
method need to be released after passing it to the
session's write/send methods. For example, if the returned value is
true
the buffer will be released automatically and so it should not
be released by a user's implementation.
true
if the processing of data is optimizedISessionConfig.optimizeDataCopying()
ByteBuffer allocate(int capacity)
capacity
- minimal required capacityvoid release(ByteBuffer buffer)
buffer
- the byte buffer being releasedIFuture<Void> execute(Runnable task)
task
- task to be executed in the selector-loop's threadSelectorLoopStoppingException
- if selector loop is in the process of
stoppingIllegalArgumentException
- if task
is nullIllegalStateException
- if the session is not associated with
a selector loopvoid executenf(Runnable task)
This method should be used whenever there will be no need to synchronize on a future associated with the specified task. This will save some resources and may improve performance.
task
- task to be executed in the selector-loop's threadSelectorLoopStoppingException
- if selector loop is in the process of
stoppingIllegalArgumentException
- if task
is nullIllegalStateException
- if the session is not associated with
a selector loopCopyright © 2017–2022 SNF4J.ORG. All rights reserved.