Package org.apache.mina.common.support
Class BaseIoSession
java.lang.Object
org.apache.mina.common.support.BaseIoSession
- All Implemented Interfaces:
IoSession
- Direct Known Subclasses:
VmPipeSessionImpl
Base implementation of
IoSession
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclose()
Closes this session immediately.protected void
close0()
Implement this method to perform real close operation.boolean
containsAttribute
(String key) Returns true if this session contains the attribute with the specified key.Returns an attachment of this session.getAttribute
(String key) Returns the value of user-defined attribute of this session.Returns the set of keys of all user-defined attributes.Returns theCloseFuture
of this session.long
Returns the time in millis when this session is created.int
getIdleCount
(IdleStatus status) Returns the number of the fired continuous sessionIdle events for the specifiedIdleStatus
.int
getIdleTime
(IdleStatus status) Returns idle time for the specified type of idleness in seconds.long
getIdleTimeInMillis
(IdleStatus status) Returns idle time for the specified type of idleness in milliseconds.long
getLastIdleTime
(IdleStatus status) Returns the time in millis when the last sessionIdle event is fired for the specifiedIdleStatus
.long
Returns the time in millis when I/O occurred lastly.long
Returns the time in millis when read operation occurred lastly.long
Returns the time in millis when write operation occurred lastly.long
Returns the total number of bytes which were read from this session.long
Returns the total number of messages which were read and decoded from this session.int
Returns the number of bytes which are scheduled to be written to this session.int
Returns the number of write requests which are scheduled to be written to this session.Returns the currentTrafficMask
of this session.int
Returns write timeout in seconds.long
Returns write timeout in milliseconds.long
Returns the total number of bytes which were written to this session.long
Returns the total number of messages which were written and encoded by this session.long
Returns the total number of write requests which were written to this session.void
increaseIdleCount
(IdleStatus status) void
increaseReadBytes
(int increment) void
void
increaseScheduledWriteBytes
(int increment) void
void
increaseWrittenBytes
(int increment) void
boolean
Returnstrue if and only if this session is being closed (but not disconnected yet) or is closed.
boolean
Returnstrue
if this session is connected with remote peer.boolean
isIdle
(IdleStatus status) Returnstrue
if this session is idle for the specifiedIdleStatus
.boolean
removeAttribute
(String key) Removes a user-defined attribute with the specified key.void
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that resumes read operations for this session.void
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that resumes write operations for this session.setAttachment
(Object attachment) Sets an attachment of this session.setAttribute
(String key) Sets a user defined attribute without a value.setAttribute
(String key, Object value) Sets a user-defined attribute.void
setIdleTime
(IdleStatus status, int idleTime) Sets idle time for the specified type of idleness in seconds.boolean
setScheduledForFlush
(boolean flag) void
setTrafficMask
(TrafficMask trafficMask) Sets theTrafficMask
of this session which will result the parentIoService
to start to control the traffic of this session immediately.void
setWriteTimeout
(int writeTimeout) Sets write timeout in seconds.void
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that suspends read operations for this session.void
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that suspends write operations for this session.toString()
protected abstract void
Signals theIoService
that theTrafficMask
of this session has been changed.Writes the specifiedmessage
to remote peer.write
(Object message, SocketAddress remoteAddress) protected void
write0
(IoFilter.WriteRequest writeRequest) Implement this method to perform real write operation with the specifiedwriteRequest
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.mina.common.IoSession
getConfig, getFilterChain, getHandler, getLocalAddress, getRemoteAddress, getService, getServiceAddress, getServiceConfig, getTransportType
-
Constructor Details
-
BaseIoSession
protected BaseIoSession()
-
-
Method Details
-
isConnected
public boolean isConnected()Description copied from interface:IoSession
Returnstrue
if this session is connected with remote peer.- Specified by:
isConnected
in interfaceIoSession
-
isClosing
public boolean isClosing()Description copied from interface:IoSession
Returnstrue if and only if this session is being closed (but not disconnected yet) or is closed.
-
getCloseFuture
Description copied from interface:IoSession
Returns theCloseFuture
of this session. This method returns the same instance whenever user calls it.- Specified by:
getCloseFuture
in interfaceIoSession
-
isScheduledForFlush
public boolean isScheduledForFlush() -
setScheduledForFlush
public boolean setScheduledForFlush(boolean flag) -
close
Description copied from interface:IoSession
Closes this session immediately. This operation is asynthronous. Wait for the returnedCloseFuture
if you want to wait for the session actually closed. -
close0
protected void close0()Implement this method to perform real close operation. By default, this method is implemented to set the future to 'closed' immediately. -
write
Description copied from interface:IoSession
Writes the specifiedmessage
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 returnedWriteFuture
if you want to wait for the message actually written. -
write
-
write0
Implement this method to perform real write operation with the specifiedwriteRequest
. By default, this method is implemented to set the future to 'not written' immediately.- Parameters:
writeRequest
- Write request to make
-
getAttachment
Description copied from interface:IoSession
Returns an attachment of this session. This method is identical with getAttribute( "" ).- Specified by:
getAttachment
in interfaceIoSession
-
setAttachment
Description copied from interface:IoSession
Sets an attachment of this session. This method is identical with setAttribute( "", attachment ).- Specified by:
setAttachment
in interfaceIoSession
- Returns:
- Old attachment. null if it is new.
-
getAttribute
Description copied from interface:IoSession
Returns the value of user-defined attribute of this session.- Specified by:
getAttribute
in interfaceIoSession
- Parameters:
key
- the key of the attribute- Returns:
- null if there is no attribute with the specified key
-
setAttribute
Description copied from interface:IoSession
Sets a user-defined attribute.- Specified by:
setAttribute
in interfaceIoSession
- Parameters:
key
- the key of the attributevalue
- the value of the attribute- Returns:
- The old value of the attribute. null if it is new.
-
setAttribute
Description copied from interface:IoSession
Sets a user defined attribute without a value. This is useful when you just want to put a 'mark' attribute. Its value is set toBoolean.TRUE
.- Specified by:
setAttribute
in interfaceIoSession
- Parameters:
key
- the key of the attribute- Returns:
- The old value of the attribute. null if it is new.
-
removeAttribute
Description copied from interface:IoSession
Removes a user-defined attribute with the specified key.- Specified by:
removeAttribute
in interfaceIoSession
- Returns:
- The old value of the attribute. null if not found.
-
containsAttribute
Description copied from interface:IoSession
Returns true if this session contains the attribute with the specified key.- Specified by:
containsAttribute
in interfaceIoSession
-
getAttributeKeys
Description copied from interface:IoSession
Returns the set of keys of all user-defined attributes.- Specified by:
getAttributeKeys
in interfaceIoSession
-
getIdleTime
Description copied from interface:IoSession
Returns idle time for the specified type of idleness in seconds.- Specified by:
getIdleTime
in interfaceIoSession
-
getIdleTimeInMillis
Description copied from interface:IoSession
Returns idle time for the specified type of idleness in milliseconds.- Specified by:
getIdleTimeInMillis
in interfaceIoSession
-
setIdleTime
Description copied from interface:IoSession
Sets idle time for the specified type of idleness in seconds.- Specified by:
setIdleTime
in interfaceIoSession
-
getWriteTimeout
public int getWriteTimeout()Description copied from interface:IoSession
Returns write timeout in seconds.- Specified by:
getWriteTimeout
in interfaceIoSession
-
getWriteTimeoutInMillis
public long getWriteTimeoutInMillis()Description copied from interface:IoSession
Returns write timeout in milliseconds.- Specified by:
getWriteTimeoutInMillis
in interfaceIoSession
-
setWriteTimeout
public void setWriteTimeout(int writeTimeout) Description copied from interface:IoSession
Sets write timeout in seconds.- Specified by:
setWriteTimeout
in interfaceIoSession
-
getTrafficMask
Description copied from interface:IoSession
Returns the currentTrafficMask
of this session.- Specified by:
getTrafficMask
in interfaceIoSession
-
setTrafficMask
Description copied from interface:IoSession
Sets theTrafficMask
of this session which will result the parentIoService
to start to control the traffic of this session immediately.- Specified by:
setTrafficMask
in interfaceIoSession
-
suspendRead
public void suspendRead()Description copied from interface:IoSession
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that suspends read operations for this session.- Specified by:
suspendRead
in interfaceIoSession
-
suspendWrite
public void suspendWrite()Description copied from interface:IoSession
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that suspends write operations for this session.- Specified by:
suspendWrite
in interfaceIoSession
-
resumeRead
public void resumeRead()Description copied from interface:IoSession
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that resumes read operations for this session.- Specified by:
resumeRead
in interfaceIoSession
-
resumeWrite
public void resumeWrite()Description copied from interface:IoSession
A shortcut method forIoSession.setTrafficMask(TrafficMask)
that resumes write operations for this session.- Specified by:
resumeWrite
in interfaceIoSession
-
updateTrafficMask
protected abstract void updateTrafficMask()Signals theIoService
that theTrafficMask
of this session has been changed. -
getReadBytes
public long getReadBytes()Description copied from interface:IoSession
Returns the total number of bytes which were read from this session.- Specified by:
getReadBytes
in interfaceIoSession
-
getWrittenBytes
public long getWrittenBytes()Description copied from interface:IoSession
Returns the total number of bytes which were written to this session.- Specified by:
getWrittenBytes
in interfaceIoSession
-
getWrittenWriteRequests
public long getWrittenWriteRequests()Description copied from interface:IoSession
Returns the total number of write requests which were written to this session.- Specified by:
getWrittenWriteRequests
in interfaceIoSession
-
getReadMessages
public long getReadMessages()Description copied from interface:IoSession
Returns the total number of messages which were read and decoded from this session.- Specified by:
getReadMessages
in interfaceIoSession
-
getWrittenMessages
public long getWrittenMessages()Description copied from interface:IoSession
Returns the total number of messages which were written and encoded by this session.- Specified by:
getWrittenMessages
in interfaceIoSession
-
getScheduledWriteBytes
public int getScheduledWriteBytes()Description copied from interface:IoSession
Returns the number of bytes which are scheduled to be written to this session.- Specified by:
getScheduledWriteBytes
in interfaceIoSession
-
getScheduledWriteRequests
public int getScheduledWriteRequests()Description copied from interface:IoSession
Returns the number of write requests which are scheduled to be written to this session.- Specified by:
getScheduledWriteRequests
in interfaceIoSession
-
increaseReadBytes
public void increaseReadBytes(int increment) -
increaseWrittenBytes
public void increaseWrittenBytes(int increment) -
increaseReadMessages
public void increaseReadMessages() -
increaseWrittenMessages
public void increaseWrittenMessages() -
increaseScheduledWriteBytes
public void increaseScheduledWriteBytes(int increment) -
increaseScheduledWriteRequests
public void increaseScheduledWriteRequests() -
getCreationTime
public long getCreationTime()Description copied from interface:IoSession
Returns the time in millis when this session is created.- Specified by:
getCreationTime
in interfaceIoSession
-
getLastIoTime
public long getLastIoTime()Description copied from interface:IoSession
Returns the time in millis when I/O occurred lastly.- Specified by:
getLastIoTime
in interfaceIoSession
-
getLastReadTime
public long getLastReadTime()Description copied from interface:IoSession
Returns the time in millis when read operation occurred lastly.- Specified by:
getLastReadTime
in interfaceIoSession
-
getLastWriteTime
public long getLastWriteTime()Description copied from interface:IoSession
Returns the time in millis when write operation occurred lastly.- Specified by:
getLastWriteTime
in interfaceIoSession
-
isIdle
Description copied from interface:IoSession
Returnstrue
if this session is idle for the specifiedIdleStatus
. -
getIdleCount
Description copied from interface:IoSession
Returns the number of the fired continuous sessionIdle events for the specifiedIdleStatus
.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.
- Specified by:
getIdleCount
in interfaceIoSession
-
getLastIdleTime
Description copied from interface:IoSession
Returns the time in millis when the last sessionIdle event is fired for the specifiedIdleStatus
.- Specified by:
getLastIdleTime
in interfaceIoSession
-
increaseIdleCount
-
toString
-