Class AbstractIoSession
- java.lang.Object
-
- org.apache.mina.core.session.AbstractIoSession
-
- All Implemented Interfaces:
IoSession
- Direct Known Subclasses:
DummySession,NioSession,VmPipeSession
public abstract class AbstractIoSession extends Object implements IoSession
Base implementation ofIoSession.- Author:
- Apache MINA Project
-
-
Field Summary
Fields Modifier and Type Field Description static WriteRequestCLOSE_REQUESTAn internal write request object that triggers session close.protected IoSessionConfigconfigThe session configstatic WriteRequestMESSAGE_SENT_REQUESTAn internal write request object that triggers message sent events.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIoSession(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 CloseFutureclose()Closes this session after all queued write requests are flushed.CloseFutureclose(boolean rightNow)Closes this session immediately or after all queued write requests are flushed.CloseFuturecloseNow()Closes this session immediately.CloseFuturecloseOnFlush()Closes this session after all queued write requests are flushed.booleancontainsAttribute(Object key)voiddecreaseReadBufferSize()Decrease the ReadBuffer size (it will be divided by a factor 2)voiddecreaseScheduledBytesAndMessages(WriteRequest request)Decrease the counters of written messages and written bytes when a message has been writtenprotected voiddestroy()Destroy the sessionbooleanequals(Object o)TODO This is a ridiculous implementation.ObjectgetAttachment()Returns an attachment of this session.ObjectgetAttribute(Object key)Returns the value of the user-defined attribute of this session.ObjectgetAttribute(Object key, Object defaultValue)Returns the value of user defined attribute associated with the specified key.Set<Object>getAttributeKeys()IoSessionAttributeMapgetAttributeMap()intgetBothIdleCount()CloseFuturegetCloseFuture()IoSessionConfiggetConfig()longgetCreationTime()ObjectgetCurrentWriteMessage()Returns the message which is being written byIoService.WriteRequestgetCurrentWriteRequest()Returns theWriteRequestwhich is being processed byIoService.IoHandlergetHandler()longgetId()We use an AtomicLong to guarantee that the session ID are unique.intgetIdleCount(IdleStatus status)longgetLastBothIdleTime()longgetLastIdleTime(IdleStatus status)longgetLastIoTime()longgetLastReaderIdleTime()longgetLastReadTime()longgetLastWriterIdleTime()longgetLastWriteTime()abstract IoProcessorgetProcessor()longgetReadBytes()doublegetReadBytesThroughput()intgetReaderIdleCount()longgetReadMessages()doublegetReadMessagesThroughput()longgetScheduledWriteBytes()intgetScheduledWriteMessages()IoServicegetService()SocketAddressgetServiceAddress()WriteRequestQueuegetWriteRequestQueue()Get the queue that contains the message waiting for being written.intgetWriterIdleCount()longgetWrittenBytes()doublegetWrittenBytesThroughput()longgetWrittenMessages()doublegetWrittenMessagesThroughput()inthashCode()voidincreaseIdleCount(IdleStatus status, long currentTime)Increase the count of the various Idle countervoidincreaseReadBufferSize()Increase the ReadBuffer size (it will double)voidincreaseReadBytes(long increment, long currentTime)Increase the number of read bytesvoidincreaseReadMessages(long currentTime)Increase the number of read messagesvoidincreaseScheduledWriteBytes(int increment)Increase the number of scheduled write bytes for the sessionvoidincreaseScheduledWriteMessages()Increase the number of scheduled message to writevoidincreaseWrittenBytes(int increment, long currentTime)Increase the number of written bytesvoidincreaseWrittenMessages(WriteRequest request, long currentTime)Increase the number of written messagesbooleanisActive()booleanisBothIdle()booleanisClosing()booleanisConnected()booleanisIdle(IdleStatus status)booleanisReaderIdle()booleanisReadSuspended()Is read operation is suspended for this session.booleanisScheduledForFlush()Tells if the session is scheduled for flushedbooleanisSecured()booleanisServer()booleanisWriterIdle()booleanisWriteSuspended()Is write operation is suspended for this session.static voidnotifyIdleness(Iterator<? extends IoSession> sessions, long currentTime)Fires aIoEventType.SESSION_IDLEevent to any applicable sessions in the specified collection.static voidnotifyIdleSession(IoSession session, long currentTime)Fires aIoEventType.SESSION_IDLEevent if applicable for the specifiedsession.voidofferClosedReadFuture()Inform the ReadFuture that the session has been closedvoidofferFailedReadFuture(Throwable exception)Associates a failure to a ReadFuturevoidofferReadFuture(Object message)Associates a message to a ReadFutureReadFutureread()TODO This javadoc is wrong.ObjectremoveAttribute(Object key)Removes a user-defined attribute with the specified key.booleanremoveAttribute(Object key, Object value)Removes a user defined attribute with the specified key if the current attribute value is equal to the specified value.booleanreplaceAttribute(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.voidresumeRead()Resumes read operations for this session.voidresumeWrite()Resumes write operations for this session.voidscheduledForFlush()Schedule the session for flushedObjectsetAttachment(Object attachment)Sets an attachment of this session.ObjectsetAttribute(Object key)Sets a user defined attribute without a value.ObjectsetAttribute(Object key, Object value)Sets a user-defined attribute.ObjectsetAttributeIfAbsent(Object key)Sets a user defined attribute without a value if the attribute with the specified key is not set yet.ObjectsetAttributeIfAbsent(Object key, Object value)Sets a user defined attribute if the attribute with the specified key is not set yet.voidsetAttributeMap(IoSessionAttributeMap attributes)Set the map of attributes associated with the sessionvoidsetCurrentWriteRequest(WriteRequest currentWriteRequest)Associate the current write request with the sessionbooleansetScheduledForFlush(boolean schedule)Set the scheduledForFLush flag.protected voidsetScheduledWriteBytes(int byteCount)Set the number of scheduled write bytesprotected voidsetScheduledWriteMessages(int messages)Set the number of scheduled write messagesvoidsetWriteRequestQueue(WriteRequestQueue writeRequestQueue)Create a new close aware write queue, based on the given write queue.voidsuspendRead()Suspends read operations for this session.voidsuspendWrite()Suspends write operations for this session.StringtoString()voidunscheduledForFlush()Change the session's status : it's not anymore scheduled for flushvoidupdateThroughput(long currentTime, boolean force)Update all statistical properties related with throughput assuming the specified time is the current time.WriteFuturewrite(Object message)Writes the specifiedmessageto remote peer.WriteFuturewrite(Object message, SocketAddress remoteAddress)(Optional) Writes the specifiedmessageto the specifieddestination.-
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:
getIdin 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:
isConnectedin interfaceIoSession- Returns:
trueif this session is connected with remote peer.
-
isActive
public boolean isActive()
-
isClosing
public final boolean isClosing()
-
isSecured
public boolean isSecured()
-
isServer
public boolean isServer()
-
getCloseFuture
public final CloseFuture getCloseFuture()
- Specified by:
getCloseFuturein interfaceIoSession- Returns:
- the
CloseFutureof 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 returnedCloseFutureif 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 returnedCloseFutureif 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 returnedCloseFutureif you want to wait for the session actually closed.- Specified by:
closeOnFlushin interfaceIoSession- Returns:
- The associated CloseFuture
-
closeNow
public final CloseFuture closeNow()
Closes this session immediately. This operation is asynchronous, it returns aCloseFuture.- Specified by:
closeNowin interfaceIoSession- Returns:
- The
CloseFuturethat can be use to wait for the completion of this operation
-
destroy
protected void destroy()
Destroy the session
-
getHandler
public IoHandler getHandler()
- Specified by:
getHandlerin interfaceIoSession- Returns:
- the
IoHandlerwhich 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:
readin interfaceIoSession- Returns:
- a
ReadFuturewhich 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 throwIllegalStateExceptionbecause 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)withtrue.
-
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 specifiedmessageto 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 returnedWriteFutureif you want to wait for the message actually written.
-
write
public WriteFuture write(Object message, SocketAddress remoteAddress)
(Optional) Writes the specifiedmessageto the specifieddestination. 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 returnedWriteFutureif 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 withgetAttribute( "" ).- Specified by:
getAttachmentin interfaceIoSession- Returns:
- The attachment
-
setAttachment
public final Object setAttachment(Object attachment)
Sets an attachment of this session. This method is identical withsetAttribute( "", attachment ).- Specified by:
setAttachmentin interfaceIoSession- Parameters:
attachment- The attachment- Returns:
- Old attachment.
nullif it is new.
-
getAttribute
public final Object getAttribute(Object key)
Returns the value of the user-defined attribute of this session.- Specified by:
getAttributein interfaceIoSession- Parameters:
key- the key of the attribute- Returns:
nullif 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:
getAttributein interfaceIoSession- Parameters:
key- the key of the attribute we want to retreivedefaultValue- the default value of the attribute- Returns:
- The retrieved attribute or
nullif not found
-
setAttribute
public final Object setAttribute(Object key, Object value)
Sets a user-defined attribute.- Specified by:
setAttributein interfaceIoSession- Parameters:
key- the key of the attributevalue- the value of the attribute- Returns:
- The old value of the attribute.
nullif 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:
setAttributein interfaceIoSession- Parameters:
key- the key of the attribute- Returns:
- The old value of the attribute.
nullif 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:
setAttributeIfAbsentin 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.
nullif 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:
setAttributeIfAbsentin interfaceIoSession- Parameters:
key- The key of the attribute we want to set- Returns:
- The old value of the attribute.
nullif not found.
-
removeAttribute
public final Object removeAttribute(Object key)
Removes a user-defined attribute with the specified key.- Specified by:
removeAttributein interfaceIoSession- Parameters:
key- The key of the attribute we want to remove- Returns:
- The old value of the attribute.
nullif 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:
removeAttributein interfaceIoSession- Parameters:
key- The key we want to removevalue- The value we want to remove- Returns:
trueif 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:
replaceAttributein interfaceIoSession- Parameters:
key- The key we want to replaceoldValue- The previous valuenewValue- The new value- Returns:
trueif the replacement was successful
-
containsAttribute
public final boolean containsAttribute(Object key)
- Specified by:
containsAttributein interfaceIoSession- Parameters:
key- The key of the attribute we are looking for in the session- Returns:
trueif this session contains the attribute with the specifiedkey.
-
getAttributeKeys
public final Set<Object> getAttributeKeys()
- Specified by:
getAttributeKeysin 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:
suspendReadin interfaceIoSession
-
suspendWrite
public final void suspendWrite()
Suspends write operations for this session.- Specified by:
suspendWritein interfaceIoSession
-
resumeRead
public final void resumeRead()
Resumes read operations for this session.- Specified by:
resumeReadin interfaceIoSession
-
resumeWrite
public final void resumeWrite()
Resumes write operations for this session.- Specified by:
resumeWritein interfaceIoSession
-
isReadSuspended
public boolean isReadSuspended()
Is read operation is suspended for this session.- Specified by:
isReadSuspendedin interfaceIoSession- Returns:
trueif suspended
-
isWriteSuspended
public boolean isWriteSuspended()
Is write operation is suspended for this session.- Specified by:
isWriteSuspendedin interfaceIoSession- Returns:
trueif suspended
-
getReadBytes
public final long getReadBytes()
- Specified by:
getReadBytesin interfaceIoSession- Returns:
- the total number of bytes which were read from this session.
-
getWrittenBytes
public final long getWrittenBytes()
- Specified by:
getWrittenBytesin interfaceIoSession- Returns:
- the total number of bytes which were written to this session.
-
getReadMessages
public final long getReadMessages()
- Specified by:
getReadMessagesin interfaceIoSession- Returns:
- the total number of messages which were read and decoded from this session.
-
getWrittenMessages
public final long getWrittenMessages()
- Specified by:
getWrittenMessagesin interfaceIoSession- Returns:
- the total number of messages which were written and encoded by this session.
-
getReadBytesThroughput
public final double getReadBytesThroughput()
- Specified by:
getReadBytesThroughputin interfaceIoSession- Returns:
- the number of read bytes per second.
-
getWrittenBytesThroughput
public final double getWrittenBytesThroughput()
- Specified by:
getWrittenBytesThroughputin interfaceIoSession- Returns:
- the number of written bytes per second.
-
getReadMessagesThroughput
public final double getReadMessagesThroughput()
- Specified by:
getReadMessagesThroughputin interfaceIoSession- Returns:
- the number of read messages per second.
-
getWrittenMessagesThroughput
public final double getWrittenMessagesThroughput()
- Specified by:
getWrittenMessagesThroughputin 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,forceis specified astrue, this method updates the throughput properties immediately.- Specified by:
updateThroughputin interfaceIoSession- Parameters:
currentTime- the current time in millisecondsforce- Force the update iftrue
-
getScheduledWriteBytes
public final long getScheduledWriteBytes()
- Specified by:
getScheduledWriteBytesin interfaceIoSession- Returns:
- the number of bytes which are scheduled to be written to this session.
-
getScheduledWriteMessages
public final int getScheduledWriteMessages()
- Specified by:
getScheduledWriteMessagesin 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:
getWriteRequestQueuein interfaceIoSession- Returns:
- The queue containing the pending messages.
-
getCurrentWriteRequest
public final WriteRequest getCurrentWriteRequest()
Returns theWriteRequestwhich is being processed byIoService.- Specified by:
getCurrentWriteRequestin interfaceIoSession- Returns:
nullif and if only no message is being written
-
getCurrentWriteMessage
public final Object getCurrentWriteMessage()
Returns the message which is being written byIoService.- Specified by:
getCurrentWriteMessagein interfaceIoSession- Returns:
nullif 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:
setCurrentWriteRequestin 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:
getCreationTimein interfaceIoSession- Returns:
- the session's creation time in milliseconds
-
getLastIoTime
public final long getLastIoTime()
- Specified by:
getLastIoTimein interfaceIoSession- Returns:
- the time in millis when I/O occurred lastly.
-
getLastReadTime
public final long getLastReadTime()
- Specified by:
getLastReadTimein interfaceIoSession- Returns:
- the time in millis when read operation occurred lastly.
-
getLastWriteTime
public final long getLastWriteTime()
- Specified by:
getLastWriteTimein interfaceIoSession- Returns:
- the time in millis when write operation occurred lastly.
-
isIdle
public final boolean isIdle(IdleStatus status)
- Specified by:
isIdlein interfaceIoSession- Parameters:
status- The researched idle status- Returns:
trueif this session is idle for the specifiedIdleStatus.
-
isBothIdle
public final boolean isBothIdle()
- Specified by:
isBothIdlein interfaceIoSession- Returns:
trueif this session isIdleStatus.BOTH_IDLE.- See Also:
IoSession.isIdle(IdleStatus)
-
isReaderIdle
public final boolean isReaderIdle()
- Specified by:
isReaderIdlein interfaceIoSession- Returns:
trueif this session isIdleStatus.READER_IDLE.- See Also:
IoSession.isIdle(IdleStatus)
-
isWriterIdle
public final boolean isWriterIdle()
- Specified by:
isWriterIdlein interfaceIoSession- Returns:
trueif this session isIdleStatus.WRITER_IDLE.- See Also:
IoSession.isIdle(IdleStatus)
-
getIdleCount
public final int getIdleCount(IdleStatus status)
- Specified by:
getIdleCountin interfaceIoSession- Parameters:
status- The researched idle status- Returns:
- the number of the fired continuous
sessionIdleevents for the specifiedIdleStatus.If
sessionIdleevent is fired first after some time after I/O,idleCountbecomes1.idleCountresets to0if any I/O occurs again, otherwise it increases to2and so on ifsessionIdleevent is fired again without any I/O between two (or more)sessionIdleevents.
-
getLastIdleTime
public final long getLastIdleTime(IdleStatus status)
- Specified by:
getLastIdleTimein interfaceIoSession- Parameters:
status- The researched idle status- Returns:
- the time in milliseconds when the last
sessionIdleevent is fired for the specifiedIdleStatus.
-
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:
getBothIdleCountin interfaceIoSession- Returns:
- the number of the fired continuous
sessionIdleevents forIdleStatus.BOTH_IDLE. - See Also:
IoSession.getIdleCount(IdleStatus)
-
getLastBothIdleTime
public final long getLastBothIdleTime()
- Specified by:
getLastBothIdleTimein interfaceIoSession- Returns:
- the time in milliseconds when the last
sessionIdleevent is fired forIdleStatus.BOTH_IDLE. - See Also:
IoSession.getLastIdleTime(IdleStatus)
-
getLastReaderIdleTime
public final long getLastReaderIdleTime()
- Specified by:
getLastReaderIdleTimein interfaceIoSession- Returns:
- the time in milliseconds when the last
sessionIdleevent is fired forIdleStatus.READER_IDLE. - See Also:
IoSession.getLastIdleTime(IdleStatus)
-
getLastWriterIdleTime
public final long getLastWriterIdleTime()
- Specified by:
getLastWriterIdleTimein interfaceIoSession- Returns:
- the time in milliseconds when the last
sessionIdleevent is fired forIdleStatus.WRITER_IDLE. - See Also:
IoSession.getLastIdleTime(IdleStatus)
-
getReaderIdleCount
public final int getReaderIdleCount()
- Specified by:
getReaderIdleCountin interfaceIoSession- Returns:
- the number of the fired continuous
sessionIdleevents forIdleStatus.READER_IDLE. - See Also:
IoSession.getIdleCount(IdleStatus)
-
getWriterIdleCount
public final int getWriterIdleCount()
- Specified by:
getWriterIdleCountin interfaceIoSession- Returns:
- the number of the fired continuous
sessionIdleevents forIdleStatus.WRITER_IDLE. - See Also:
IoSession.getIdleCount(IdleStatus)
-
getServiceAddress
public SocketAddress getServiceAddress()
- Specified by:
getServiceAddressin interfaceIoSession- Returns:
- the socket address of the
IoServicelistens to to manage this session. If this session is managed byIoAcceptor, it returns theSocketAddresswhich 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:
getServicein interfaceIoSession- Returns:
- the
IoServicewhich provides I/O service to this session.
-
notifyIdleness
public static void notifyIdleness(Iterator<? extends IoSession> sessions, long currentTime)
Fires aIoEventType.SESSION_IDLEevent 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_IDLEevent if applicable for the specifiedsession.- Parameters:
session- The session that is notifiedcurrentTime- the current time (i.e.System.currentTimeMillis())
-
-