public abstract class AbstractIoSession extends Object implements IoSession, ReadFilterChainController, WriteFilterChainController
IoSession
shared with all the different transports.IoSession.SessionState
Modifier and Type | Field and Description |
---|---|
protected IoSessionConfig |
config
The session config
|
protected IdleChecker |
idleChecker
the
IdleChecker in charge of detecting idle event for this session |
protected boolean |
secured
Tells if the session is secured or not
|
protected IoSession.SessionState |
state
The session's state : one of CREATED, CONNECTED, CLOSING, CLOSED, SECURING, CONNECTED_SECURED
|
SSL_HELPER
Constructor and Description |
---|
AbstractIoSession(IoService service,
IdleChecker idleChecker)
|
Modifier and Type | Method and Description |
---|---|
void |
callReadNextFilter(Object message) |
void |
callWriteNextFilter(WriteRequest message)
process session message received event using the filter chain.
|
void |
changeState(IoSession.SessionState to)
Changes the session's state from the current state to a new state.
|
<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()
|
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.
|
long |
getReadBytes()
Gets the total number of bytes read for this session since it was created.
|
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 |
incrementWrittenBytes(int bytesCount)
To be called by the internal plumber when some bytes are written on the socket
|
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 |
isSecured()
Tells if the session is belonging to a secured connection.
|
boolean |
isSecuring()
Tells if the session is processing a SSL/TLS handshake.
|
protected void |
processException(Exception t)
send a caught exception to the
IoHandler (if any) |
void |
processMessageReceived(ByteBuffer message)
process session message received event using the filter chain.
|
void |
processMessageSent(Object highLevelMessage) |
void |
processMessageWriting(WriteRequest writeRequest,
IoFuture<Void> future)
process session message writing event using the filter chain.
|
void |
processSessionClosed()
process session closed event using the filter chain.
|
void |
processSessionIdle(IdleStatus status)
process session idle event using the filter chain.
|
void |
processSessionOpen()
process session open event using the filter chain.
|
<T> T |
removeAttribute(AttributeKey<T> key)
Removes the specified Attribute from this container.
|
<T> T |
setAttribute(AttributeKey<? extends T> key,
T value)
Sets a user-defined attribute.
|
void |
setSecured(boolean secured) |
String |
toString() |
void |
write(Object message)
Enqueue a message for writing.
|
IoFuture<Void> |
writeWithFuture(Object message)
Same as
IoSession.write(Object) , but provide a IoFuture for tracking the completion of this
write. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, enqueueWriteRequest, getConfig, getLocalAddress, getRemoteAddress, isReadSuspended, isWriteSuspended, resumeRead, resumeWrite, suspendRead, suspendWrite
protected final IdleChecker idleChecker
IdleChecker
in charge of detecting idle event for this sessionprotected IoSessionConfig config
protected volatile IoSession.SessionState state
protected volatile boolean secured
public AbstractIoSession(IoService service, IdleChecker idleChecker)
service
- the service this session is associated withidleChecker
- the checker for idle sessionpublic boolean isClosed()
public boolean isClosing()
public boolean isConnected()
isConnected
in interface IoSession
true
if this session is connected with remote peer.public boolean isCreated()
public boolean isSecuring()
isSecuring
in interface IoSession
true if and only if this session is processing a SSL/TLS handshake.
public boolean isConnectedSecured()
isConnectedSecured
in interface IoSession
true if and only if this session is exchanging data over a SSL/TLS connection
public void changeState(IoSession.SessionState to)
changeState
in interface IoSession
to
- The final SessionStatepublic boolean isSecured()
public void setSecured(boolean secured)
public void initSecure(SSLContext sslContext)
initSecure
in interface IoSession
sslContext
- The SLLCOntext instance to use.public long getId()
public long getCreationTime()
getCreationTime
in interface IoSession
public long getReadBytes()
getReadBytes
in interface IoSession
public void incrementWrittenBytes(int bytesCount)
bytesCount
- number of extra bytes writtenpublic long getWrittenBytes()
getWrittenBytes
in interface IoSession
public long getLastReadTime()
getLastReadTime
in interface IoSession
public long getLastWriteTime()
getLastWriteTime
in interface IoSession
public final long getLastIoTime()
getLastIoTime
in interface IoSession
public IoService getService()
getService
in interface IoSession
IoService
which provides IoSession
to this session.public final <T> T getAttribute(AttributeKey<T> key, T defaultValue)
key
.If the there is no attribute with
the specified key the defaultValue will be returned.getAttribute
in interface IoSession
key
- the attribute's key, must not be null
IllegalArgumentException
- if key==null
setAttribute(AttributeKey, Object)
public final <T> T getAttribute(AttributeKey<T> key)
key
.If the there is no attribute with
the specified key null
will be returned.getAttribute
in interface IoSession
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)
public final <T> T setAttribute(AttributeKey<? extends T> key, T value)
value
is null
the attribute will be removed from
this IoSession
.setAttribute
in interface 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)
public Set<AttributeKey<?>> getAttributeKeys()
Set
of all Keys of this IoSession
. If this IoSession
contains no
attributes an empty Set
will be returned.getAttributeKeys
in interface IoSession
null
Collections.unmodifiableSet(Set)
public <T> T removeAttribute(AttributeKey<T> key)
null
will be
rutrnen if there is no such attribute in this container.setAttribute(key,null)
.removeAttribute
in interface IoSession
key
- of the attribute to be removed,must not be null
null
if this container doesn't contain the specified attributeIllegalArgumentException
- if key==null
public void write(Object message)
SelectorLoop
public IoFuture<Void> writeWithFuture(Object message)
IoSession.write(Object)
, but provide a IoFuture
for tracking the completion of this
write.writeWithFuture
in interface IoSession
message
- the message to be processed and writtenIoFuture
for tracking this asynchronous operationprotected void processException(Exception t)
IoHandler
(if any)public void processSessionOpen()
SelectorLoop
.public void processSessionClosed()
SelectorLoop
.public void processSessionIdle(IdleStatus status)
SelectorLoop
.public void processMessageReceived(ByteBuffer message)
SelectorLoop
.message
- the received messagepublic void processMessageWriting(WriteRequest writeRequest, IoFuture<Void> future)
SelectorLoop
.message
- the wrote message, should be transformed into ByteBuffer at the end of the filter chainpublic void processMessageSent(Object highLevelMessage)
public void callWriteNextFilter(WriteRequest message)
SelectorLoop
.callWriteNextFilter
in interface WriteFilterChainController
message
- the received messagepublic void callReadNextFilter(Object message)
callReadNextFilter
in interface ReadFilterChainController
Copyright © 2009–2013 Apache MINA Project. All rights reserved.