A handle which represents connection between two endpoints regardless of
transport types.
IoSession
provides user-defined attributes. User-defined attributes
are application-specific data which is associated with a session.
It often contains objects that represents the state of a higher-level protocol
and becomes a way to exchange data between filters and handlers.
Adjusting Transport Type Specific Properties
You can simply downcast the session to an appropriate subclass.
Thread Safety
IoSession
is thread-safe. But please note that performing
more than one
write(Object)
calls at the same time will
cause the
IoFilter.filterWrite(IoFilter.NextFilter,IoSession,IoFilter.WriteRequest)
is executed simnutaneously, and therefore you have to make sure the
IoFilter
implementations you're using are thread-safe, too.
close
public CloseFuture close()
Closes this session immediately. This operation is asynthronous.
Wait for the returned
CloseFuture
if you want to wait for
the session actually closed.
containsAttribute
public boolean containsAttribute(String key)
Returns true if this session contains the attribute with
the specified key.
getAttachment
public Object getAttachment()
Returns an attachment of this session.
This method is identical with getAttribute( "" ).
getAttribute
public Object getAttribute(String key)
Returns the value of user-defined attribute of this session.
key
- the key of the attribute
- null if there is no attribute with the specified key
getAttributeKeys
public Set getAttributeKeys()
Returns the set of keys of all user-defined attributes.
getCloseFuture
public CloseFuture getCloseFuture()
Returns the
CloseFuture
of this session. This method returns
the same instance whenever user calls it.
getConfig
public IoSessionConfig getConfig()
Returns the configuration of this session.
getCreationTime
public long getCreationTime()
Returns the time in millis when this session is created.
getFilterChain
public IoFilterChain getFilterChain()
Returns the filter chain that only affects this session.
getIdleCount
public int getIdleCount(IdleStatus status)
Returns the number of the fired continuous
sessionIdle events
for the specified
IdleStatus
.
If
sessionIdle event is fired first after some time after I/O,
idleCount becomes
1.
idleCount resets to
0 if any I/O occurs again, otherwise it increases to
2 and so on if
sessionIdle event is fired again without
any I/O between two (or more)
sessionIdle events.
getIdleTime
public int getIdleTime(IdleStatus status)
Returns idle time for the specified type of idleness in seconds.
getIdleTimeInMillis
public long getIdleTimeInMillis(IdleStatus status)
Returns idle time for the specified type of idleness in milliseconds.
getLastIdleTime
public long getLastIdleTime(IdleStatus status)
Returns the time in millis when the last
sessionIdle event
is fired for the specified
IdleStatus
.
getLastIoTime
public long getLastIoTime()
Returns the time in millis when I/O occurred lastly.
getLastReadTime
public long getLastReadTime()
Returns the time in millis when read operation occurred lastly.
getLastWriteTime
public long getLastWriteTime()
Returns the time in millis when write operation occurred lastly.
getLocalAddress
public SocketAddress getLocalAddress()
Returns the socket address of local machine which is associated with this
session.
getReadBytes
public long getReadBytes()
Returns the total number of bytes which were read from this session.
getReadMessages
public long getReadMessages()
Returns the total number of messages which were read and decoded from this session.
getRemoteAddress
public SocketAddress getRemoteAddress()
Returns the socket address of remote peer.
getScheduledWriteBytes
public int getScheduledWriteBytes()
Returns the number of bytes which are scheduled to be written to this
session.
getScheduledWriteRequests
public int getScheduledWriteRequests()
Returns the number of write requests which are scheduled to be written
to this session.
getService
public IoService getService()
Returns the
IoService
which provides I/O service to this session.
getServiceAddress
public SocketAddress getServiceAddress()
getTransportType
public TransportType getTransportType()
Returns transport type of this session.
getWriteTimeout
public int getWriteTimeout()
Returns write timeout in seconds.
getWriteTimeoutInMillis
public long getWriteTimeoutInMillis()
Returns write timeout in milliseconds.
getWrittenBytes
public long getWrittenBytes()
Returns the total number of bytes which were written to this session.
getWrittenMessages
public long getWrittenMessages()
Returns the total number of messages which were written and encoded by this session.
getWrittenWriteRequests
public long getWrittenWriteRequests()
Returns the total number of write requests which were written to this session.
isClosing
public boolean isClosing()
Returns true if and only if this session is being closed
(but not disconnected yet) or is closed.
isConnected
public boolean isConnected()
Returns true
if this session is connected with remote peer.
isIdle
public boolean isIdle(IdleStatus status)
Returns
true
if this session is idle for the specified
IdleStatus
.
removeAttribute
public Object removeAttribute(String key)
Removes a user-defined attribute with the specified key.
- The old value of the attribute. null if not found.
resumeRead
public void resumeRead()
resumeWrite
public void resumeWrite()
setAttachment
public Object setAttachment(Object attachment)
Sets an attachment of this session.
This method is identical with setAttribute( "", attachment ).
- Old attachment. null if it is new.
setAttribute
public Object setAttribute(String key)
Sets a user defined attribute without a value. This is useful when
you just want to put a 'mark' attribute. Its value is set to
Boolean.TRUE
.
key
- the key of the attribute
- The old value of the attribute. null if it is new.
setAttribute
public Object setAttribute(String key,
Object value)
Sets a user-defined attribute.
key
- the key of the attributevalue
- the value of the attribute
- The old value of the attribute. null if it is new.
setIdleTime
public void setIdleTime(IdleStatus status,
int idleTime)
Sets idle time for the specified type of idleness in seconds.
setTrafficMask
public void setTrafficMask(TrafficMask trafficMask)
Sets the
TrafficMask
of this session which will result
the parent
IoService
to start to control the traffic
of this session immediately.
setWriteTimeout
public void setWriteTimeout(int writeTimeout)
Sets write timeout in seconds.
suspendRead
public void suspendRead()
suspendWrite
public void suspendWrite()
write
public WriteFuture write(Object message)
Writes the specified
message
to remote peer. This
operation is asynchronous;
IoHandler.messageSent(IoSession,Object)
will be invoked when the message is actually sent to remote peer.
You can also wait for the returned
WriteFuture
if you want
to wait for the message actually written.