public interface IoSession
IoSession
provides user-defined attributes. User-defined attributes are application-specific data which are
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.
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,WriteRequest)
to be executed
simultaneously, and therefore you have to make sure the IoFilter
implementations you're using are
thread-safe, too.
Modifier and Type | Interface and Description |
---|---|
static class |
IoSession.SessionState
State of a
IoSession |
Modifier and Type | Field and Description |
---|---|
static AttributeKey<SslHelper> |
SSL_HELPER
The SslHelper instance name, stored in the session's attributes
|
Modifier and Type | Method and Description |
---|---|
void |
changeState(IoSession.SessionState newState)
Changes the session's state from the current state to a new state.
|
IoFuture<Void> |
close(boolean immediately)
Closes this session immediately or after all queued write requests are flushed.
|
WriteRequest |
enqueueWriteRequest(WriteRequest writeRequest)
Internal method for enqueue write request after filter chain processing
|
<T> T |
getAttribute(AttributeKey<T> key)
Returns the value of the user-defined attribute for the given
key .If the there is no attribute with
the specified key null will be returned. |
<T> T |
getAttribute(AttributeKey<T> key,
T defaultValue)
Returns the value of the user-defined attribute for the given
key .If the there is no attribute with
the specified key the defaultValue will be returned. |
Set<AttributeKey<?>> |
getAttributeKeys()
|
IoSessionConfig |
getConfig()
Gets the session configuration, it where the idle timeout are set and other transport specific configuration.
|
long |
getCreationTime()
The session's creation time.
|
long |
getId()
The unique identifier of this session.
|
long |
getLastIoTime()
Returns the time in millisecond when I/O occurred lastly (either read or write).
|
long |
getLastReadTime()
Returns the time in millisecond when the last I/O read occurred.
|
long |
getLastWriteTime()
Returns the time in millisecond when the last I/O write occurred.
|
SocketAddress |
getLocalAddress()
Gets the local address of the local peer.
|
long |
getReadBytes()
Gets the total number of bytes read for this session since it was created.
|
SocketAddress |
getRemoteAddress()
Returns the socket address of remote peer.
|
IoService |
getService()
Gets the service this session is attached to.
|
long |
getWrittenBytes()
Gets the total number of bytes written for this session since it was created.
|
void |
initSecure(SSLContext sslContext)
Initializes the SSL/TLS environment for this session.
|
boolean |
isClosed()
Tells if the session is currently closed.
|
boolean |
isClosing()
Tells if the session is being closed.
|
boolean |
isConnected()
Tells if the session is currently connected and able to process incoming requests and to send outgoing responses.
|
boolean |
isConnectedSecured()
Tells if the session is using SSL/TLS.
|
boolean |
isCreated()
Tells if the session is created.
|
boolean |
isReadSuspended()
Is read operation is suspended for this session.
|
boolean |
isSecured()
Tells if the session is belonging to a secured connection.
|
boolean |
isSecuring()
Tells if the session is processing a SSL/TLS handshake.
|
boolean |
isWriteSuspended()
Is write operation is suspended for this session.
|
<T> T |
removeAttribute(AttributeKey<T> key)
Removes the specified Attribute from this container.
|
void |
resumeRead()
Resumes read operations for this session.
|
void |
resumeWrite()
Resumes write operations for this session.
|
<T> T |
setAttribute(AttributeKey<? extends T> key,
T value)
Sets a user-defined attribute.
|
void |
suspendRead()
Suspends read operations for this session.
|
void |
suspendWrite()
Suspends write operations for this session.
|
void |
write(Object message)
Enqueue a message for writing.
|
IoFuture<Void> |
writeWithFuture(Object message)
Same as
write(Object) , but provide a IoFuture for tracking the completion of this
write. |
static final AttributeKey<SslHelper> SSL_HELPER
long getId()
SocketAddress getRemoteAddress()
SocketAddress getLocalAddress()
IoService getService()
boolean isClosed()
true
if this session is disconnected with remote peer.boolean isClosing()
true
if this session is in the process of being closed.boolean isConnected()
true
if this session is connected with remote peer.boolean isCreated()
true
if this session is created.boolean isSecuring()
true if and only if this session is processing a SSL/TLS handshake.
boolean isSecured()
true if and only if this session is belonging a secured connection.
void changeState(IoSession.SessionState newState)
newState
- The final SessionStatevoid initSecure(SSLContext sslContext)
sslContext
- The SLLCOntext instance to use.boolean isConnectedSecured()
true if and only if this session is exchanging data over a SSL/TLS connection
IoFuture<Void> close(boolean immediately)
IoFuture
if you want to wait for the session actually closed. Once this method has
been called, no incoming request will be accepted.immediately
- true
to close this session immediately. false
to close this session after all
queued write requests are flushed.IoFuture
that will contains the session's statevoid suspendRead()
void suspendWrite()
void resumeRead()
void resumeWrite()
boolean isReadSuspended()
true
if suspendedboolean isWriteSuspended()
true
if suspendedlong getReadBytes()
long getWrittenBytes()
IoSessionConfig getConfig()
long getCreationTime()
long getLastIoTime()
long getLastReadTime()
long getLastWriteTime()
<T> T getAttribute(AttributeKey<T> key, T defaultValue)
key
.If the there is no attribute with
the specified key the defaultValue will be returned.key
- the attribute's key, must not be null
IllegalArgumentException
- if key==null
setAttribute(AttributeKey, Object)
<T> T getAttribute(AttributeKey<T> key)
key
.If the there is no attribute with
the specified key null
will be returned.key
- the attribute's key, must not be null
null
if there is no attribute with the specified keyIllegalArgumentException
- if key==null
setAttribute(AttributeKey, Object)
<T> T setAttribute(AttributeKey<? extends T> key, T value)
value
is null
the attribute will be removed from
this IoSession
.key
- the attribute's key, must not be null
value
- the attribute's value, null
to remove the attributenull
if there is no previous valueIllegalArgumentException
- key==null
value
is not null
and not an instance of type that is specified in by
the given key
(see AttributeKey.getType()
)
getAttribute(AttributeKey)
Set<AttributeKey<?>> getAttributeKeys()
Set
of all Keys of this IoSession
. If this IoSession
contains no
attributes an empty Set
will be returned.null
Collections.unmodifiableSet(Set)
<T> T removeAttribute(AttributeKey<T> key)
null
will be
rutrnen if there is no such attribute in this container.setAttribute(key,null)
.key
- of the attribute to be removed,must not be null
null
if this container doesn't contain the specified attributeIllegalArgumentException
- if key==null
void write(Object message)
SelectorLoop
IoFuture<Void> writeWithFuture(Object message)
write(Object)
, but provide a IoFuture
for tracking the completion of this
write.message
- the message to be processed and writtenIoFuture
for tracking this asynchronous operationWriteRequest enqueueWriteRequest(WriteRequest writeRequest)
writeRequest
- the message to put in the write requestCopyright © 2009–2013 Apache MINA Project. All rights reserved.