public abstract class AbstractIoSession extends java.lang.Object implements IoSession
IoSession
.限定符和类型 | 字段和说明 |
---|---|
protected IoSessionConfig |
config
The session config
|
限定符 | 构造器和说明 |
---|---|
protected |
AbstractIoSession(IoService service)
Create a Session for a service
|
限定符和类型 | 方法和说明 |
---|---|
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(java.lang.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 written
|
boolean |
equals(java.lang.Object o)
TODO This is a ridiculous implementation.
|
java.lang.Object |
getAttachment()
Returns an attachment of this session.
|
java.lang.Object |
getAttribute(java.lang.Object key)
Returns the value of the user-defined attribute of this session.
|
java.lang.Object |
getAttribute(java.lang.Object key,
java.lang.Object defaultValue)
Returns the value of user defined attribute associated with the
specified key.
|
java.util.Set<java.lang.Object> |
getAttributeKeys() |
IoSessionAttributeMap |
getAttributeMap() |
int |
getBothIdleCount() |
CloseFuture |
getCloseFuture() |
IoSessionConfig |
getConfig() |
long |
getCreationTime() |
java.lang.Object |
getCurrentWriteMessage()
Returns the message which is being written by
IoService . |
WriteRequest |
getCurrentWriteRequest()
Returns the
WriteRequest which is being processed by
IoService . |
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() |
java.net.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 counter
|
void |
increaseReadBufferSize()
Increase the ReadBuffer size (it will double)
|
void |
increaseReadBytes(long increment,
long currentTime)
Increase the number of read bytes
|
void |
increaseReadMessages(long currentTime)
Increase the number of read messages
|
void |
increaseScheduledWriteBytes(int increment)
Increase the number of scheduled write bytes for the session
|
void |
increaseScheduledWriteMessages()
Increase the number of scheduled message to write
|
void |
increaseWrittenBytes(int increment,
long currentTime)
Increase the number of written bytes
|
void |
increaseWrittenMessages(WriteRequest request,
long currentTime)
Increase the number of written messages
|
boolean |
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 flushed
|
boolean |
isSecured() |
boolean |
isWriterIdle() |
boolean |
isWriteSuspended()
Is write operation is suspended for this session.
|
static void |
notifyIdleness(java.util.Iterator<? extends IoSession> sessions,
long currentTime)
Fires a
IoEventType.SESSION_IDLE event to any applicable sessions
in the specified collection. |
static void |
notifyIdleSession(IoSession session,
long currentTime)
Fires a
IoEventType.SESSION_IDLE event if applicable for the
specified session . |
void |
offerClosedReadFuture()
Inform the ReadFuture that the session has been closed
|
void |
offerFailedReadFuture(java.lang.Throwable exception)
Associates a failure to a ReadFuture
|
void |
offerReadFuture(java.lang.Object message)
Associates a message to a ReadFuture
|
ReadFuture |
read()
TODO This javadoc is wrong.
|
java.lang.Object |
removeAttribute(java.lang.Object key)
Removes a user-defined attribute with the specified key.
|
boolean |
removeAttribute(java.lang.Object key,
java.lang.Object value)
Removes a user defined attribute with the specified key if the current
attribute value is equal to the specified value.
|
boolean |
replaceAttribute(java.lang.Object key,
java.lang.Object oldValue,
java.lang.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 flushed
|
java.lang.Object |
setAttachment(java.lang.Object attachment)
Sets an attachment of this session.
|
java.lang.Object |
setAttribute(java.lang.Object key)
Sets a user defined attribute without a value.
|
java.lang.Object |
setAttribute(java.lang.Object key,
java.lang.Object value)
Sets a user-defined attribute.
|
java.lang.Object |
setAttributeIfAbsent(java.lang.Object key)
Sets a user defined attribute without a value if the attribute with
the specified key is not set yet.
|
java.lang.Object |
setAttributeIfAbsent(java.lang.Object key,
java.lang.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 session
|
void |
setCurrentWriteRequest(WriteRequest currentWriteRequest)
Associate the current write request with the session
|
boolean |
setScheduledForFlush(boolean schedule)
Set the scheduledForFLush flag.
|
protected void |
setScheduledWriteBytes(int byteCount)
Set the number of scheduled write bytes
|
protected void |
setScheduledWriteMessages(int messages)
Set the number of scheduled write messages
|
void |
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.
|
java.lang.String |
toString() |
void |
unscheduledForFlush()
Change the session's status : it's not anymore scheduled for flush
|
void |
updateThroughput(long currentTime,
boolean force)
Update all statistical properties related with throughput assuming
the specified time is the current time.
|
WriteFuture |
write(java.lang.Object message)
Writes the specified
message to remote peer. |
WriteFuture |
write(java.lang.Object message,
java.net.SocketAddress remoteAddress)
(Optional) Writes the specified message to the specified destination.
|
getFilterChain, getLocalAddress, getRemoteAddress, getTransportMetadata
protected IoSessionConfig config
protected AbstractIoSession(IoService service)
service
- the Service for this sessionpublic final long getId()
public abstract IoProcessor getProcessor()
public final boolean isConnected()
isConnected
在接口中 IoSession
public final boolean isClosing()
public boolean isSecured()
public final CloseFuture getCloseFuture()
getCloseFuture
在接口中 IoSession
CloseFuture
of this session. This method returns
the same instance whenever user calls it.public final boolean isScheduledForFlush()
public final void scheduledForFlush()
public final void unscheduledForFlush()
public final boolean setScheduledForFlush(boolean schedule)
schedule
- the new value to set if not already set.public final CloseFuture close(boolean rightNow)
CloseFuture
if you want to wait for the session actually closed.public final CloseFuture close()
CloseFuture
if you want to wait for the session actually closed.public final CloseFuture closeOnFlush()
CloseFuture
if you want to wait
for the session actually closed.closeOnFlush
在接口中 IoSession
public final CloseFuture closeNow()
CloseFuture
.public IoHandler getHandler()
getHandler
在接口中 IoSession
IoHandler
which handles this session.public IoSessionConfig getConfig()
public final ReadFuture read()
read
在接口中 IoSession
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
throw IllegalStateException
because all received events must be
queued somewhere to support this operation, possibly leading to memory
leak. This means you have to keep calling IoSession.read()
once you
enabled this operation. To enable this operation, please call
IoSessionConfig.setUseReadOperation(boolean)
with true.public final void offerReadFuture(java.lang.Object message)
message
- the message to associate to the ReadFuturepublic final void offerFailedReadFuture(java.lang.Throwable exception)
exception
- the exception to associate to the ReadFuturepublic final void offerClosedReadFuture()
public WriteFuture write(java.lang.Object message)
message
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 returned WriteFuture
if you want
to wait for the message actually written.public WriteFuture write(java.lang.Object message, java.net.SocketAddress remoteAddress)
IoHandler.messageSent(IoSession, Object)
will be invoked when the message is actually sent to remote peer. You can
also wait for the returned WriteFuture
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.
public final java.lang.Object getAttachment()
getAttachment
在接口中 IoSession
public final java.lang.Object setAttachment(java.lang.Object attachment)
setAttachment
在接口中 IoSession
attachment
- The attachmentpublic final java.lang.Object getAttribute(java.lang.Object key)
getAttribute
在接口中 IoSession
key
- the key of the attributepublic final java.lang.Object getAttribute(java.lang.Object key, java.lang.Object defaultValue)
if (containsAttribute(key)) { return getAttribute(key); } else { setAttribute(key, defaultValue); return defaultValue; }
getAttribute
在接口中 IoSession
key
- the key of the attribute we want to retreivedefaultValue
- the default value of the attributepublic final java.lang.Object setAttribute(java.lang.Object key, java.lang.Object value)
setAttribute
在接口中 IoSession
key
- the key of the attributevalue
- the value of the attributepublic final java.lang.Object setAttribute(java.lang.Object key)
Boolean.TRUE
.setAttribute
在接口中 IoSession
key
- the key of the attributepublic final java.lang.Object setAttributeIfAbsent(java.lang.Object key, java.lang.Object value)
if (containsAttribute(key)) { return getAttribute(key); } else { return setAttribute(key, value); }
setAttributeIfAbsent
在接口中 IoSession
key
- The key of the attribute we want to setvalue
- The value we want to setpublic final java.lang.Object setAttributeIfAbsent(java.lang.Object key)
Boolean.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); }
setAttributeIfAbsent
在接口中 IoSession
key
- The key of the attribute we want to setpublic final java.lang.Object removeAttribute(java.lang.Object key)
removeAttribute
在接口中 IoSession
key
- The key of the attribute we want to removepublic final boolean removeAttribute(java.lang.Object key, java.lang.Object value)
if (containsAttribute(key) && getAttribute(key).equals(value)) { removeAttribute(key); return true; } else { return false; }
removeAttribute
在接口中 IoSession
key
- The key we want to removevalue
- The value we want to removepublic final boolean replaceAttribute(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
if (containsAttribute(key) && getAttribute(key).equals(oldValue)) { setAttribute(key, newValue); return true; } else { return false; }
replaceAttribute
在接口中 IoSession
key
- The key we want to replaceoldValue
- The previous valuenewValue
- The new valuepublic final boolean containsAttribute(java.lang.Object key)
containsAttribute
在接口中 IoSession
key
- The key of the attribute we are looking for in the sessionpublic final java.util.Set<java.lang.Object> getAttributeKeys()
getAttributeKeys
在接口中 IoSession
public final IoSessionAttributeMap getAttributeMap()
public final void setAttributeMap(IoSessionAttributeMap attributes)
attributes
- The Map of attributespublic final void setWriteRequestQueue(WriteRequestQueue writeRequestQueue)
writeRequestQueue
- The write request queuepublic final void suspendRead()
suspendRead
在接口中 IoSession
public final void suspendWrite()
suspendWrite
在接口中 IoSession
public final void resumeRead()
resumeRead
在接口中 IoSession
public final void resumeWrite()
resumeWrite
在接口中 IoSession
public boolean isReadSuspended()
isReadSuspended
在接口中 IoSession
public boolean isWriteSuspended()
isWriteSuspended
在接口中 IoSession
public final long getReadBytes()
getReadBytes
在接口中 IoSession
public final long getWrittenBytes()
getWrittenBytes
在接口中 IoSession
public final long getReadMessages()
getReadMessages
在接口中 IoSession
public final long getWrittenMessages()
getWrittenMessages
在接口中 IoSession
public final double getReadBytesThroughput()
getReadBytesThroughput
在接口中 IoSession
public final double getWrittenBytesThroughput()
getWrittenBytesThroughput
在接口中 IoSession
public final double getReadMessagesThroughput()
getReadMessagesThroughput
在接口中 IoSession
public final double getWrittenMessagesThroughput()
getWrittenMessagesThroughput
在接口中 IoSession
public final void updateThroughput(long currentTime, boolean force)
calculation interval
.
If, however, force is specified as true, this method
updates the throughput properties immediately.updateThroughput
在接口中 IoSession
currentTime
- the current time in millisecondsforce
- Force the update if truepublic final long getScheduledWriteBytes()
getScheduledWriteBytes
在接口中 IoSession
public final int getScheduledWriteMessages()
getScheduledWriteMessages
在接口中 IoSession
protected void setScheduledWriteBytes(int byteCount)
byteCount
- The number of scheduled bytes for writeprotected void setScheduledWriteMessages(int messages)
messages
- The number of scheduled messages for writepublic final void increaseReadBytes(long increment, long currentTime)
increment
- The number of read bytescurrentTime
- The current timepublic final void increaseReadMessages(long currentTime)
currentTime
- The current timepublic final void increaseWrittenBytes(int increment, long currentTime)
increment
- The number of written bytescurrentTime
- The current timepublic final void increaseWrittenMessages(WriteRequest request, long currentTime)
request
- The written messagecurrentTime
- The current tilepublic final void increaseScheduledWriteBytes(int increment)
increment
- The number of newly added bytes to writepublic final void increaseScheduledWriteMessages()
public final void decreaseScheduledBytesAndMessages(WriteRequest request)
request
- The written messagepublic final WriteRequestQueue getWriteRequestQueue()
getWriteRequestQueue
在接口中 IoSession
public final WriteRequest getCurrentWriteRequest()
WriteRequest
which is being processed by
IoService
.getCurrentWriteRequest
在接口中 IoSession
public final java.lang.Object getCurrentWriteMessage()
IoService
.getCurrentWriteMessage
在接口中 IoSession
public final void setCurrentWriteRequest(WriteRequest currentWriteRequest)
setCurrentWriteRequest
在接口中 IoSession
currentWriteRequest
- the current write request to associatepublic final void increaseReadBufferSize()
public final void decreaseReadBufferSize()
public final long getCreationTime()
getCreationTime
在接口中 IoSession
public final long getLastIoTime()
getLastIoTime
在接口中 IoSession
public final long getLastReadTime()
getLastReadTime
在接口中 IoSession
public final long getLastWriteTime()
getLastWriteTime
在接口中 IoSession
public final boolean isIdle(IdleStatus status)
isIdle
在接口中 IoSession
status
- The researched idle statusIdleStatus
.public final boolean isBothIdle()
isBothIdle
在接口中 IoSession
IdleStatus.BOTH_IDLE
.IoSession.isIdle(IdleStatus)
public final boolean isReaderIdle()
isReaderIdle
在接口中 IoSession
IdleStatus.READER_IDLE
.IoSession.isIdle(IdleStatus)
public final boolean isWriterIdle()
isWriterIdle
在接口中 IoSession
IdleStatus.WRITER_IDLE
.IoSession.isIdle(IdleStatus)
public final int getIdleCount(IdleStatus status)
getIdleCount
在接口中 IoSession
status
- The researched idle statusIdleStatus
.
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.
public final long getLastIdleTime(IdleStatus status)
getLastIdleTime
在接口中 IoSession
status
- The researched idle statusIdleStatus
.public final void increaseIdleCount(IdleStatus status, long currentTime)
status
- The current statuscurrentTime
- The current timepublic final int getBothIdleCount()
getBothIdleCount
在接口中 IoSession
IdleStatus.BOTH_IDLE
.IoSession.getIdleCount(IdleStatus)
public final long getLastBothIdleTime()
getLastBothIdleTime
在接口中 IoSession
IdleStatus.BOTH_IDLE
.IoSession.getLastIdleTime(IdleStatus)
public final long getLastReaderIdleTime()
getLastReaderIdleTime
在接口中 IoSession
IdleStatus.READER_IDLE
.IoSession.getLastIdleTime(IdleStatus)
public final long getLastWriterIdleTime()
getLastWriterIdleTime
在接口中 IoSession
IdleStatus.WRITER_IDLE
.IoSession.getLastIdleTime(IdleStatus)
public final int getReaderIdleCount()
getReaderIdleCount
在接口中 IoSession
IdleStatus.READER_IDLE
.IoSession.getIdleCount(IdleStatus)
public final int getWriterIdleCount()
getWriterIdleCount
在接口中 IoSession
IdleStatus.WRITER_IDLE
.IoSession.getIdleCount(IdleStatus)
public java.net.SocketAddress getServiceAddress()
getServiceAddress
在接口中 IoSession
IoService
listens to to manage
this session. If this session is managed by IoAcceptor
, it
returns the SocketAddress
which is specified as a parameter of
IoAcceptor.bind()
. If this session is managed by
IoConnector
, this method returns the same address with
that of IoSession.getRemoteAddress()
.public final int hashCode()
hashCode
在类中 java.lang.Object
public final boolean equals(java.lang.Object o)
equals
在类中 java.lang.Object
public java.lang.String toString()
toString
在类中 java.lang.Object
public IoService getService()
getService
在接口中 IoSession
IoService
which provides I/O service to this session.public static void notifyIdleness(java.util.Iterator<? extends IoSession> sessions, long currentTime)
IoEventType.SESSION_IDLE
event to any applicable sessions
in the specified collection.sessions
- The sessions that are notifiedcurrentTime
- the current time (i.e. System.currentTimeMillis()
)public static void notifyIdleSession(IoSession session, long currentTime)
IoEventType.SESSION_IDLE
event if applicable for the
specified session
.session
- The session that is notifiedcurrentTime
- the current time (i.e. System.currentTimeMillis()
)