Class AbstractIoSession
- java.lang.Object
-
- org.apache.mina.core.session.AbstractIoSession
-
- All Implemented Interfaces:
IoSession
- Direct Known Subclasses:
AprSession
,DummySession
,NioSession
public abstract class AbstractIoSession extends Object implements IoSession
Base implementation ofIoSession
.- Author:
- Apache MINA Project
-
-
Field Summary
Fields Modifier and Type Field Description static WriteRequest
CLOSE_REQUEST
An internal write request object that triggers session close.protected IoSessionConfig
config
The session configstatic WriteRequest
MESSAGE_SENT_REQUEST
An internal write request object that triggers message sent events.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractIoSession(IoService service)
Create a Session for a service
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CloseFuture
close()
Closes this session after all queued write requests are flushed.CloseFuture
close(boolean rightNow)
Closes this session immediately or after all queued write requests are flushed.CloseFuture
closeNow()
Closes this session immediately.CloseFuture
closeOnFlush()
Closes this session after all queued write requests are flushed.boolean
containsAttribute(Object key)
void
decreaseReadBufferSize()
Decrease the ReadBuffer size (it will be divided by a factor 2)void
decreaseScheduledBytesAndMessages(WriteRequest request)
Decrease the counters of written messages and written bytes when a message has been writtenprotected void
destroy()
Destroy the sessionboolean
equals(Object o)
TODO This is a ridiculous implementation.Object
getAttachment()
Returns an attachment of this session.Object
getAttribute(Object key)
Returns the value of the user-defined attribute of this session.Object
getAttribute(Object key, Object defaultValue)
Returns the value of user defined attribute associated with the specified key.Set<Object>
getAttributeKeys()
IoSessionAttributeMap
getAttributeMap()
int
getBothIdleCount()
CloseFuture
getCloseFuture()
IoSessionConfig
getConfig()
long
getCreationTime()
Object
getCurrentWriteMessage()
Returns the message which is being written byIoService
.WriteRequest
getCurrentWriteRequest()
Returns theWriteRequest
which is being processed byIoService
.IoHandler
getHandler()
long
getId()
We use an AtomicLong to guarantee that the session ID are unique.int
getIdleCount(IdleStatus status)
long
getLastBothIdleTime()
long
getLastIdleTime(IdleStatus status)
long
getLastIoTime()
long
getLastReaderIdleTime()
long
getLastReadTime()
long
getLastWriterIdleTime()
long
getLastWriteTime()
abstract IoProcessor
getProcessor()
long
getReadBytes()
double
getReadBytesThroughput()
int
getReaderIdleCount()
long
getReadMessages()
double
getReadMessagesThroughput()
long
getScheduledWriteBytes()
int
getScheduledWriteMessages()
IoService
getService()
SocketAddress
getServiceAddress()
WriteRequestQueue
getWriteRequestQueue()
Get the queue that contains the message waiting for being written.int
getWriterIdleCount()
long
getWrittenBytes()
double
getWrittenBytesThroughput()
long
getWrittenMessages()
double
getWrittenMessagesThroughput()
int
hashCode()
void
increaseIdleCount(IdleStatus status, long currentTime)
Increase the count of the various Idle countervoid
increaseReadBufferSize()
Increase the ReadBuffer size (it will double)void
increaseReadBytes(long increment, long currentTime)
Increase the number of read bytesvoid
increaseReadMessages(long currentTime)
Increase the number of read messagesvoid
increaseScheduledWriteBytes(int increment)
Increase the number of scheduled write bytes for the sessionvoid
increaseScheduledWriteMessages()
Increase the number of scheduled message to writevoid
increaseWrittenBytes(int increment, long currentTime)
Increase the number of written bytesvoid
increaseWrittenMessages(WriteRequest request, long currentTime)
Increase the number of written messagesboolean
isActive()
boolean
isBothIdle()
boolean
isClosing()
boolean
isConnected()
boolean
isIdle(IdleStatus status)
boolean
isReaderIdle()
boolean
isReadSuspended()
Is read operation is suspended for this session.boolean
isScheduledForFlush()
Tells if the session is scheduled for flushedboolean
isSecured()
boolean
isWriterIdle()
boolean
isWriteSuspended()
Is write operation is suspended for this session.static void
notifyIdleness(Iterator<? extends IoSession> sessions, long currentTime)
Fires aIoEventType.SESSION_IDLE
event to any applicable sessions in the specified collection.static void
notifyIdleSession(IoSession session, long currentTime)
Fires aIoEventType.SESSION_IDLE
event if applicable for the specifiedsession
.void
offerClosedReadFuture()
Inform the ReadFuture that the session has been closedvoid
offerFailedReadFuture(Throwable exception)
Associates a failure to a ReadFuturevoid
offerReadFuture(Object message)
Associates a message to a ReadFutureReadFuture
read()
TODO This javadoc is wrong.Object
removeAttribute(Object key)
Removes a user-defined attribute with the specified key.boolean
removeAttribute(Object key, Object value)
Removes a user defined attribute with the specified key if the current attribute value is equal to the specified value.boolean
replaceAttribute(Object key, Object oldValue, Object newValue)
Replaces a user defined attribute with the specified key if the value of the attribute is equals to the specified old value.void
resumeRead()
Resumes read operations for this session.void
resumeWrite()
Resumes write operations for this session.void
scheduledForFlush()
Schedule the session for flushedObject
setAttachment(Object attachment)
Sets an attachment of this session.Object
setAttribute(Object key)
Sets a user defined attribute without a value.Object
setAttribute(Object key, Object value)
Sets a user-defined attribute.Object
setAttributeIfAbsent(Object key)
Sets a user defined attribute without a value if the attribute with the specified key is not set yet.Object
setAttributeIfAbsent(Object key, Object value)
Sets a user defined attribute if the attribute with the specified key is not set yet.void
setAttributeMap(IoSessionAttributeMap attributes)
Set the map of attributes associated with the sessionvoid
setCurrentWriteRequest(WriteRequest currentWriteRequest)
Associate the current write request with the sessionboolean
setScheduledForFlush(boolean schedule)
Set the scheduledForFLush flag.protected void
setScheduledWriteBytes(int byteCount)
Set the number of scheduled write bytesprotected void
setScheduledWriteMessages(int messages)
Set the number of scheduled write messagesvoid
setWriteRequestQueue(WriteRequestQueue writeRequestQueue)
Create a new close aware write queue, based on the given write queue.void
suspendRead()
Suspends read operations for this session.void
suspendWrite()
Suspends write operations for this session.String
toString()
void
unscheduledForFlush()
Change the session's status : it's not anymore scheduled for flushvoid
updateThroughput(long currentTime, boolean force)
Update all statistical properties related with throughput assuming the specified time is the current time.WriteFuture
write(Object message)
Writes the specifiedmessage
to remote peer.WriteFuture
write(Object message, SocketAddress remoteAddress)
(Optional) Writes the specified message to the specified destination.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.mina.core.session.IoSession
getFilterChain, getLocalAddress, getRemoteAddress, getTransportMetadata
-
-
-
-
Field Detail
-
config
protected IoSessionConfig config
The session config
-
CLOSE_REQUEST
public static final WriteRequest CLOSE_REQUEST
An internal write request object that triggers session close.
-
MESSAGE_SENT_REQUEST
public static final WriteRequest MESSAGE_SENT_REQUEST
An internal write request object that triggers message sent events.
-
-
Constructor Detail
-
AbstractIoSession
protected AbstractIoSession(IoService service)
Create a Session for a service- Parameters:
service
- the Service for this session
-
-
Method Detail
-
getId
public final long getId()
We use an AtomicLong to guarantee that the session ID are unique.- Specified by:
getId
in interfaceIoSession
- Returns:
- a unique identifier for this session. Every session has its own ID which is different from each other. TODO : The way it's implemented does not guarantee that the contract is respected. It uses the HashCode() method which don't guarantee the key unicity.
-
getProcessor
public abstract IoProcessor getProcessor()
- Returns:
- The associated IoProcessor for this session
-
isConnected
public final boolean isConnected()
- Specified by:
isConnected
in interfaceIoSession
- Returns:
- true if this session is connected with remote peer.
-
isActive
public boolean isActive()
-
isClosing
public final boolean isClosing()
-
isSecured
public boolean isSecured()
-
getCloseFuture
public final CloseFuture getCloseFuture()
- Specified by:
getCloseFuture
in interfaceIoSession
- Returns:
- the
CloseFuture
of this session. This method returns the same instance whenever user calls it.
-
isScheduledForFlush
public final boolean isScheduledForFlush()
Tells if the session is scheduled for flushed- Returns:
- true if the session is scheduled for flush
-
scheduledForFlush
public final void scheduledForFlush()
Schedule the session for flushed
-
unscheduledForFlush
public final void unscheduledForFlush()
Change the session's status : it's not anymore scheduled for flush
-
setScheduledForFlush
public final boolean setScheduledForFlush(boolean schedule)
Set the scheduledForFLush flag. As we may have concurrent access to this flag, we compare and set it in one call.- Parameters:
schedule
- the new value to set if not already set.- Returns:
- true if the session flag has been set, and if it wasn't set already.
-
close
public final CloseFuture close(boolean rightNow)
Closes this session immediately or after all queued write requests are flushed. This operation is asynchronous. Wait for the returnedCloseFuture
if you want to wait for the session actually closed.
-
close
public final CloseFuture close()
Closes this session after all queued write requests are flushed. This operation is asynchronous. Wait for the returnedCloseFuture
if you want to wait for the session actually closed.
-
closeOnFlush
public final CloseFuture closeOnFlush()
Closes this session after all queued write requests are flushed. This operation is asynchronous. Wait for the returnedCloseFuture
if you want to wait for the session actually closed.- Specified by:
closeOnFlush
in interfaceIoSession
- Returns:
- The associated CloseFuture
-
closeNow
public final CloseFuture closeNow()
Closes this session immediately. This operation is asynchronous, it returns aCloseFuture
.- Specified by:
closeNow
in interfaceIoSession
- Returns:
- The
CloseFuture
that can be use to wait for the completion of this operation
-
destroy
protected void destroy()
Destroy the session
-
getHandler
public IoHandler getHandler()
- Specified by:
getHandler
in interfaceIoSession
- Returns:
- the
IoHandler
which handles this session.
-
getConfig
public IoSessionConfig getConfig()
-
read
public final ReadFuture read()
TODO This javadoc is wrong. The return tag should be short.- Specified by:
read
in interfaceIoSession
- Returns:
- a
ReadFuture
which is notified when a new message is received, the connection is closed or an exception is caught. This operation is especially useful when you implement a client application. TODO : Describe here how we enable this feature. However, please note that this operation is disabled by default and throwIllegalStateException
because all received events must be queued somewhere to support this operation, possibly leading to memory leak. This means you have to keep callingIoSession.read()
once you enabled this operation. To enable this operation, please callIoSessionConfig.setUseReadOperation(boolean)
with true.
-
offerReadFuture
public final void offerReadFuture(Object message)
Associates a message to a ReadFuture- Parameters:
message
- the message to associate to the ReadFuture
-
offerFailedReadFuture
public final void offerFailedReadFuture(Throwable exception)
Associates a failure to a ReadFuture- Parameters:
exception
- the exception to associate to the ReadFuture
-
offerClosedReadFuture
public final void offerClosedReadFuture()
Inform the ReadFuture that the session has been closed
-
write
public WriteFuture write(Object message)
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
public WriteFuture write(Object message, SocketAddress remoteAddress)
(Optional) Writes the specified message to the specified destination. 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.When you implement a client that receives a broadcast message from a server such as DHCP server, the client might need to send a response message for the broadcast message the server sent. Because the remote address of the session is not the address of the server in case of broadcasting, there should be a way to specify the destination when you write the response message. This interface provides
IoSession.write(Object, SocketAddress)
method so you can specify the destination.
-
getAttachment
public final Object getAttachment()
Returns an attachment of this session. This method is identical with getAttribute( "" ).- Specified by:
getAttachment
in interfaceIoSession
- Returns:
- The attachment
-
setAttachment
public final Object setAttachment(Object attachment)
Sets an attachment of this session. This method is identical with setAttribute( "", attachment ).- Specified by:
setAttachment
in interfaceIoSession
- Parameters:
attachment
- The attachment- Returns:
- Old attachment. null if it is new.
-
getAttribute
public final Object getAttribute(Object key)
Returns the value of the 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
-
getAttribute
public final Object getAttribute(Object key, Object defaultValue)
Returns the value of user defined attribute associated with the specified key. If there's no such attribute, the specified default value is associated with the specified key, and the default value is returned. This method is same with the following code except that the operation is performed atomically.if (containsAttribute(key)) { return getAttribute(key); } else { setAttribute(key, defaultValue); return defaultValue; }
- Specified by:
getAttribute
in interfaceIoSession
- Parameters:
key
- the key of the attribute we want to retreivedefaultValue
- the default value of the attribute- Returns:
- The retrieved attribute or null if not found
-
setAttribute
public final Object setAttribute(Object key, Object value)
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
public final Object setAttribute(Object 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 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.
-
setAttributeIfAbsent
public final Object setAttributeIfAbsent(Object key, Object value)
Sets a user defined attribute if the attribute with the specified key is not set yet. This method is same with the following code except that the operation is performed atomically.if (containsAttribute(key)) { return getAttribute(key); } else { return setAttribute(key, value); }
- Specified by:
setAttributeIfAbsent
in interfaceIoSession
- Parameters:
key
- The key of the attribute we want to setvalue
- The value we want to set- Returns:
- The old value of the attribute. null if not found.
-
setAttributeIfAbsent
public final Object setAttributeIfAbsent(Object key)
Sets a user defined attribute without a value if the attribute with the specified key is not set yet. This is useful when you just want to put a 'mark' attribute. Its value is set toBoolean.TRUE
. This method is same with the following code except that the operation is performed atomically.if (containsAttribute(key)) { return getAttribute(key); // might not always be Boolean.TRUE. } else { return setAttribute(key); }
- Specified by:
setAttributeIfAbsent
in interfaceIoSession
- Parameters:
key
- The key of the attribute we want to set- Returns:
- The old value of the attribute. null if not found.
-
removeAttribute
public final Object removeAttribute(Object key)
Removes a user-defined attribute with the specified key.- Specified by:
removeAttribute
in interfaceIoSession
- Parameters:
key
- The key of the attribute we want to remove- Returns:
- The old value of the attribute. null if not found.
-
removeAttribute
public final boolean removeAttribute(Object key, Object value)
Removes a user defined attribute with the specified key if the current attribute value is equal to the specified value. This method is same with the following code except that the operation is performed atomically.if (containsAttribute(key) && getAttribute(key).equals(value)) { removeAttribute(key); return true; } else { return false; }
- Specified by:
removeAttribute
in interfaceIoSession
- Parameters:
key
- The key we want to removevalue
- The value we want to remove- Returns:
- true if the removal was successful
-
replaceAttribute
public final boolean replaceAttribute(Object key, Object oldValue, Object newValue)
Replaces a user defined attribute with the specified key if the value of the attribute is equals to the specified old value. This method is same with the following code except that the operation is performed atomically.if (containsAttribute(key) && getAttribute(key).equals(oldValue)) { setAttribute(key, newValue); return true; } else { return false; }
- Specified by:
replaceAttribute
in interfaceIoSession
- Parameters:
key
- The key we want to replaceoldValue
- The previous valuenewValue
- The new value- Returns:
- true if the replacement was successful
-
containsAttribute
public final boolean containsAttribute(Object key)
- Specified by:
containsAttribute
in interfaceIoSession
- Parameters:
key
- The key of the attribute we are looking for in the session- Returns:
- true if this session contains the attribute with the specified key.
-
getAttributeKeys
public final Set<Object> getAttributeKeys()
- Specified by:
getAttributeKeys
in interfaceIoSession
- Returns:
- the set of keys of all user-defined attributes.
-
getAttributeMap
public final IoSessionAttributeMap getAttributeMap()
- Returns:
- The map of attributes associated with the session
-
setAttributeMap
public final void setAttributeMap(IoSessionAttributeMap attributes)
Set the map of attributes associated with the session- Parameters:
attributes
- The Map of attributes
-
setWriteRequestQueue
public final void setWriteRequestQueue(WriteRequestQueue writeRequestQueue)
Create a new close aware write queue, based on the given write queue.- Parameters:
writeRequestQueue
- The write request queue
-
suspendRead
public final void suspendRead()
Suspends read operations for this session.- Specified by:
suspendRead
in interfaceIoSession
-
suspendWrite
public final void suspendWrite()
Suspends write operations for this session.- Specified by:
suspendWrite
in interfaceIoSession
-
resumeRead
public final void resumeRead()
Resumes read operations for this session.- Specified by:
resumeRead
in interfaceIoSession
-
resumeWrite
public final void resumeWrite()
Resumes write operations for this session.- Specified by:
resumeWrite
in interfaceIoSession
-
isReadSuspended
public boolean isReadSuspended()
Is read operation is suspended for this session.- Specified by:
isReadSuspended
in interfaceIoSession
- Returns:
- true if suspended
-
isWriteSuspended
public boolean isWriteSuspended()
Is write operation is suspended for this session.- Specified by:
isWriteSuspended
in interfaceIoSession
- Returns:
- true if suspended
-
getReadBytes
public final long getReadBytes()
- Specified by:
getReadBytes
in interfaceIoSession
- Returns:
- the total number of bytes which were read from this session.
-
getWrittenBytes
public final long getWrittenBytes()
- Specified by:
getWrittenBytes
in interfaceIoSession
- Returns:
- the total number of bytes which were written to this session.
-
getReadMessages
public final long getReadMessages()
- Specified by:
getReadMessages
in interfaceIoSession
- Returns:
- the total number of messages which were read and decoded from this session.
-
getWrittenMessages
public final long getWrittenMessages()
- Specified by:
getWrittenMessages
in interfaceIoSession
- Returns:
- the total number of messages which were written and encoded by this session.
-
getReadBytesThroughput
public final double getReadBytesThroughput()
- Specified by:
getReadBytesThroughput
in interfaceIoSession
- Returns:
- the number of read bytes per second.
-
getWrittenBytesThroughput
public final double getWrittenBytesThroughput()
- Specified by:
getWrittenBytesThroughput
in interfaceIoSession
- Returns:
- the number of written bytes per second.
-
getReadMessagesThroughput
public final double getReadMessagesThroughput()
- Specified by:
getReadMessagesThroughput
in interfaceIoSession
- Returns:
- the number of read messages per second.
-
getWrittenMessagesThroughput
public final double getWrittenMessagesThroughput()
- Specified by:
getWrittenMessagesThroughput
in interfaceIoSession
- Returns:
- the number of written messages per second.
-
updateThroughput
public final void updateThroughput(long currentTime, boolean force)
Update all statistical properties related with throughput assuming the specified time is the current time. By default this method returns silently without updating the throughput properties if they were calculated already within lastcalculation interval
. If, however, force is specified as true, this method updates the throughput properties immediately.- Specified by:
updateThroughput
in interfaceIoSession
- Parameters:
currentTime
- the current time in millisecondsforce
- Force the update if true
-
getScheduledWriteBytes
public final long getScheduledWriteBytes()
- Specified by:
getScheduledWriteBytes
in interfaceIoSession
- Returns:
- the number of bytes which are scheduled to be written to this session.
-
getScheduledWriteMessages
public final int getScheduledWriteMessages()
- Specified by:
getScheduledWriteMessages
in interfaceIoSession
- Returns:
- the number of messages which are scheduled to be written to this session.
-
setScheduledWriteBytes
protected void setScheduledWriteBytes(int byteCount)
Set the number of scheduled write bytes- Parameters:
byteCount
- The number of scheduled bytes for write
-
setScheduledWriteMessages
protected void setScheduledWriteMessages(int messages)
Set the number of scheduled write messages- Parameters:
messages
- The number of scheduled messages for write
-
increaseReadBytes
public final void increaseReadBytes(long increment, long currentTime)
Increase the number of read bytes- Parameters:
increment
- The number of read bytescurrentTime
- The current time
-
increaseReadMessages
public final void increaseReadMessages(long currentTime)
Increase the number of read messages- Parameters:
currentTime
- The current time
-
increaseWrittenBytes
public final void increaseWrittenBytes(int increment, long currentTime)
Increase the number of written bytes- Parameters:
increment
- The number of written bytescurrentTime
- The current time
-
increaseWrittenMessages
public final void increaseWrittenMessages(WriteRequest request, long currentTime)
Increase the number of written messages- Parameters:
request
- The written messagecurrentTime
- The current tile
-
increaseScheduledWriteBytes
public final void increaseScheduledWriteBytes(int increment)
Increase the number of scheduled write bytes for the session- Parameters:
increment
- The number of newly added bytes to write
-
increaseScheduledWriteMessages
public final void increaseScheduledWriteMessages()
Increase the number of scheduled message to write
-
decreaseScheduledBytesAndMessages
public final void decreaseScheduledBytesAndMessages(WriteRequest request)
Decrease the counters of written messages and written bytes when a message has been written- Parameters:
request
- The written message
-
getWriteRequestQueue
public final WriteRequestQueue getWriteRequestQueue()
Get the queue that contains the message waiting for being written. As the reader might not be ready, it's frequent that the messages aren't written completely, or that some older messages are waiting to be written when a new message arrives. This queue is used to manage the backlog of messages.- Specified by:
getWriteRequestQueue
in interfaceIoSession
- Returns:
- The queue containing the pending messages.
-
getCurrentWriteRequest
public final WriteRequest getCurrentWriteRequest()
Returns theWriteRequest
which is being processed byIoService
.- Specified by:
getCurrentWriteRequest
in interfaceIoSession
- Returns:
- null if and if only no message is being written
-
getCurrentWriteMessage
public final Object getCurrentWriteMessage()
Returns the message which is being written byIoService
.- Specified by:
getCurrentWriteMessage
in interfaceIoSession
- Returns:
- null if and if only no message is being written
-
setCurrentWriteRequest
public final void setCurrentWriteRequest(WriteRequest currentWriteRequest)
Associate the current write request with the session- Specified by:
setCurrentWriteRequest
in interfaceIoSession
- Parameters:
currentWriteRequest
- the current write request to associate
-
increaseReadBufferSize
public final void increaseReadBufferSize()
Increase the ReadBuffer size (it will double)
-
decreaseReadBufferSize
public final void decreaseReadBufferSize()
Decrease the ReadBuffer size (it will be divided by a factor 2)
-
getCreationTime
public final long getCreationTime()
- Specified by:
getCreationTime
in interfaceIoSession
- Returns:
- the session's creation time in milliseconds
-
getLastIoTime
public final long getLastIoTime()
- Specified by:
getLastIoTime
in interfaceIoSession
- Returns:
- the time in millis when I/O occurred lastly.
-
getLastReadTime
public final long getLastReadTime()
- Specified by:
getLastReadTime
in interfaceIoSession
- Returns:
- the time in millis when read operation occurred lastly.
-
getLastWriteTime
public final long getLastWriteTime()
- Specified by:
getLastWriteTime
in interfaceIoSession
- Returns:
- the time in millis when write operation occurred lastly.
-
isIdle
public final boolean isIdle(IdleStatus status)
- Specified by:
isIdle
in interfaceIoSession
- Parameters:
status
- The researched idle status- Returns:
- true if this session is idle for the specified
IdleStatus
.
-
isBothIdle
public final boolean isBothIdle()
- Specified by:
isBothIdle
in interfaceIoSession
- Returns:
- true if this session is
IdleStatus.BOTH_IDLE
. - See Also:
IoSession.isIdle(IdleStatus)
-
isReaderIdle
public final boolean isReaderIdle()
- Specified by:
isReaderIdle
in interfaceIoSession
- Returns:
- true if this session is
IdleStatus.READER_IDLE
. - See Also:
IoSession.isIdle(IdleStatus)
-
isWriterIdle
public final boolean isWriterIdle()
- Specified by:
isWriterIdle
in interfaceIoSession
- Returns:
- true if this session is
IdleStatus.WRITER_IDLE
. - See Also:
IoSession.isIdle(IdleStatus)
-
getIdleCount
public final int getIdleCount(IdleStatus status)
- Specified by:
getIdleCount
in interfaceIoSession
- Parameters:
status
- The researched idle 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.
-
getLastIdleTime
public final long getLastIdleTime(IdleStatus status)
- Specified by:
getLastIdleTime
in interfaceIoSession
- Parameters:
status
- The researched idle status- Returns:
- the time in milliseconds when the last sessionIdle event
is fired for the specified
IdleStatus
.
-
increaseIdleCount
public final void increaseIdleCount(IdleStatus status, long currentTime)
Increase the count of the various Idle counter- Parameters:
status
- The current statuscurrentTime
- The current time
-
getBothIdleCount
public final int getBothIdleCount()
- Specified by:
getBothIdleCount
in interfaceIoSession
- Returns:
- the number of the fired continuous sessionIdle events
for
IdleStatus.BOTH_IDLE
. - See Also:
IoSession.getIdleCount(IdleStatus)
-
getLastBothIdleTime
public final long getLastBothIdleTime()
- Specified by:
getLastBothIdleTime
in interfaceIoSession
- Returns:
- the time in milliseconds when the last sessionIdle event
is fired for
IdleStatus.BOTH_IDLE
. - See Also:
IoSession.getLastIdleTime(IdleStatus)
-
getLastReaderIdleTime
public final long getLastReaderIdleTime()
- Specified by:
getLastReaderIdleTime
in interfaceIoSession
- Returns:
- the time in milliseconds when the last sessionIdle event
is fired for
IdleStatus.READER_IDLE
. - See Also:
IoSession.getLastIdleTime(IdleStatus)
-
getLastWriterIdleTime
public final long getLastWriterIdleTime()
- Specified by:
getLastWriterIdleTime
in interfaceIoSession
- Returns:
- the time in milliseconds when the last sessionIdle event
is fired for
IdleStatus.WRITER_IDLE
. - See Also:
IoSession.getLastIdleTime(IdleStatus)
-
getReaderIdleCount
public final int getReaderIdleCount()
- Specified by:
getReaderIdleCount
in interfaceIoSession
- Returns:
- the number of the fired continuous sessionIdle events
for
IdleStatus.READER_IDLE
. - See Also:
IoSession.getIdleCount(IdleStatus)
-
getWriterIdleCount
public final int getWriterIdleCount()
- Specified by:
getWriterIdleCount
in interfaceIoSession
- Returns:
- the number of the fired continuous sessionIdle events
for
IdleStatus.WRITER_IDLE
. - See Also:
IoSession.getIdleCount(IdleStatus)
-
getServiceAddress
public SocketAddress getServiceAddress()
- Specified by:
getServiceAddress
in interfaceIoSession
- Returns:
- the socket address of the
IoService
listens to to manage this session. If this session is managed byIoAcceptor
, it returns theSocketAddress
which is specified as a parameter ofIoAcceptor.bind()
. If this session is managed byIoConnector
, this method returns the same address with that ofIoSession.getRemoteAddress()
.
-
equals
public final boolean equals(Object o)
TODO This is a ridiculous implementation. Need to be replaced.
-
getService
public IoService getService()
- Specified by:
getService
in interfaceIoSession
- Returns:
- the
IoService
which provides I/O service to this session.
-
notifyIdleness
public static void notifyIdleness(Iterator<? extends IoSession> sessions, long currentTime)
Fires aIoEventType.SESSION_IDLE
event to any applicable sessions in the specified collection.- Parameters:
sessions
- The sessions that are notifiedcurrentTime
- the current time (i.e.System.currentTimeMillis()
)
-
notifyIdleSession
public static void notifyIdleSession(IoSession session, long currentTime)
Fires aIoEventType.SESSION_IDLE
event if applicable for the specifiedsession
.- Parameters:
session
- The session that is notifiedcurrentTime
- the current time (i.e.System.currentTimeMillis()
)
-
-