public abstract class AbstractIoSession extends java.lang.Object implements IoSession
IoSession
.Modifier | Constructor and Description |
---|---|
protected |
AbstractIoSession() |
Modifier and Type | Method and Description |
---|---|
CloseFuture |
close()
Closes this session immediately.
|
CloseFuture |
close(boolean rightNow)
Closes this session immediately or after all queued write requests
are flushed.
|
CloseFuture |
closeOnFlush()
Closes this session after all queued write requests are flushed.
|
boolean |
containsAttribute(java.lang.Object key)
Returns true if this session contains the attribute with
the specified key.
|
protected void |
decreaseReadBufferSize() |
protected void |
decreaseScheduledBytesAndMessages(WriteRequest request) |
boolean |
equals(java.lang.Object o) |
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()
Returns the set of keys of all user-defined attributes.
|
protected IoSessionAttributeMap |
getAttributeMap() |
int |
getBothIdleCount()
Returns the number of the fired continuous sessionIdle events
for
IdleStatus.BOTH_IDLE . |
CloseFuture |
getCloseFuture()
Returns the
CloseFuture of this session. |
long |
getCreationTime()
Returns the time in millis when this session is created.
|
protected WriteRequest |
getCurrentWriteRequest() |
long |
getId()
Returns a unique identifier of this session.
|
int |
getIdleCount(IdleStatus status)
Returns the number of the fired continuous sessionIdle events
for the specified
IdleStatus . |
long |
getLastBothIdleTime()
Returns the time in milliseconds when the last sessionIdle event
is fired for
IdleStatus.BOTH_IDLE . |
long |
getLastIdleTime(IdleStatus status)
Returns the time in milliseconds when the last sessionIdle event
is fired for the specified
IdleStatus . |
long |
getLastIoTime()
Returns the time in millis when I/O occurred lastly.
|
long |
getLastReaderIdleTime()
Returns the time in milliseconds when the last sessionIdle event
is fired for
IdleStatus.READER_IDLE . |
long |
getLastReadTime()
Returns the time in millis when read operation occurred lastly.
|
long |
getLastWriterIdleTime()
Returns the time in milliseconds when the last sessionIdle event
is fired for
IdleStatus.WRITER_IDLE . |
long |
getLastWriteTime()
Returns the time in millis when write operation occurred lastly.
|
protected abstract IoProcessor |
getProcessor() |
long |
getReadBytes()
Returns the total number of bytes which were read from this session.
|
double |
getReadBytesThroughput()
Returns the number of read bytes per second.
|
int |
getReaderIdleCount()
Returns the number of the fired continuous sessionIdle events
for
IdleStatus.READER_IDLE . |
long |
getReadMessages()
Returns the total number of messages which were read and decoded from this session.
|
double |
getReadMessagesThroughput()
Returns the number of read messages per second.
|
long |
getScheduledWriteBytes()
Returns the number of bytes which are scheduled to be written to this
session.
|
int |
getScheduledWriteMessages()
Returns the number of messages which are scheduled to be written to this session.
|
java.net.SocketAddress |
getServiceAddress()
Returns the socket address of the
IoService listens to to manage
this session. |
TrafficMask |
getTrafficMask()
Returns the current
TrafficMask of this session. |
protected WriteRequestQueue |
getWriteRequestQueue() |
int |
getWriterIdleCount()
Returns the number of the fired continuous sessionIdle events
for
IdleStatus.WRITER_IDLE . |
long |
getWrittenBytes()
Returns the total number of bytes which were written to this session.
|
double |
getWrittenBytesThroughput()
Returns the number of written bytes per second.
|
long |
getWrittenMessages()
Returns the total number of messages which were written and encoded by this session.
|
double |
getWrittenMessagesThroughput()
Returns the number of written messages per second.
|
int |
hashCode() |
protected void |
increaseIdleCount(IdleStatus status,
long currentTime) |
protected void |
increaseReadBufferSize() |
protected void |
increaseReadBytes(long increment,
long currentTime) |
protected void |
increaseReadMessages(long currentTime) |
protected void |
increaseScheduledWriteBytes(long increment) |
protected void |
increaseScheduledWriteMessages() |
protected void |
increaseWrittenBytesAndMessages(WriteRequest request,
long currentTime) |
boolean |
isBothIdle() |
boolean |
isClosing()
Returns
true if and only if this session is being closed
(but not disconnected yet) or is closed. |
boolean |
isConnected()
Returns
true if this session is connected with remote peer. |
boolean |
isIdle(IdleStatus status)
Returns
true if this session is idle for the specified
IdleStatus . |
boolean |
isReaderIdle() |
protected boolean |
isScheduledForFlush() |
boolean |
isWriterIdle() |
protected void |
offerClosedReadFuture() |
protected void |
offerFailedReadFuture(java.lang.Throwable exception) |
protected void |
offerReadFuture(java.lang.Object message) |
ReadFuture |
read()
Returns a
ReadFuture which is notified when a new message is
received, the connection is closed or an exception is caught. |
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()
A shortcut method for
IoSession.setTrafficMask(TrafficMask) that
resumes read operations for this session. |
void |
resumeWrite()
A shortcut method for
IoSession.setTrafficMask(TrafficMask) that
resumes write operations for this session. |
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.
|
protected void |
setAttributeMap(IoSessionAttributeMap attributes) |
protected void |
setCurrentWriteRequest(WriteRequest currentWriteRequest) |
protected boolean |
setScheduledForFlush(boolean flag) |
protected void |
setScheduledWriteBytes(long byteCount) |
protected void |
setScheduledWriteMessages(int messages) |
void |
setTrafficMask(TrafficMask trafficMask)
Sets the
TrafficMask of this session which will result
the parent IoService to start to control the traffic
of this session immediately. |
protected void |
setTrafficMaskNow(TrafficMask trafficMask) |
protected void |
setWriteRequestQueue(WriteRequestQueue writeRequestQueue) |
void |
suspendRead()
A shortcut method for
IoSession.setTrafficMask(TrafficMask) that
suspends read operations for this session. |
void |
suspendWrite()
A shortcut method for
IoSession.setTrafficMask(TrafficMask) that
suspends write operations for this session. |
java.lang.String |
toString() |
protected 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.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getConfig, getFilterChain, getHandler, getLocalAddress, getRemoteAddress, getService, getTransportMetadata
public final long getId()
IoSession
protected abstract IoProcessor getProcessor()
public final boolean isConnected()
IoSession
true
if this session is connected with remote peer.isConnected
in interface IoSession
public final boolean isClosing()
IoSession
true if and only if this session is being closed
(but not disconnected yet) or is closed.
public final CloseFuture getCloseFuture()
IoSession
CloseFuture
of this session. This method returns
the same instance whenever user calls it.getCloseFuture
in interface IoSession
protected final boolean isScheduledForFlush()
protected final boolean setScheduledForFlush(boolean flag)
public final CloseFuture close(boolean rightNow)
IoSession
CloseFuture
if you want to wait for the session actually closed.close
in interface IoSession
rightNow
- true
to close this session immediately
(i.e. IoSession.close()
).
false
to close this session after all queued
write requests are flushed (i.e. IoSession.closeOnFlush()
).public final CloseFuture close()
IoSession
CloseFuture
if you want to wait for
the session actually closed.public final CloseFuture closeOnFlush()
IoSession
CloseFuture
if you want to wait for the session actually closed.closeOnFlush
in interface IoSession
public final ReadFuture 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.
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.protected final void offerReadFuture(java.lang.Object message)
protected final void offerFailedReadFuture(java.lang.Throwable exception)
protected final void offerClosedReadFuture()
public final WriteFuture write(java.lang.Object message)
IoSession
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 final WriteFuture write(java.lang.Object message, java.net.SocketAddress remoteAddress)
IoSession
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()
IoSession
getAttachment
in interface IoSession
public final java.lang.Object setAttachment(java.lang.Object attachment)
IoSession
setAttachment
in interface IoSession
public final java.lang.Object getAttribute(java.lang.Object key)
IoSession
getAttribute
in interface IoSession
key
- the key of the attributepublic final java.lang.Object getAttribute(java.lang.Object key, java.lang.Object defaultValue)
IoSession
if (containsAttribute(key)) { return getAttribute(key); } else { setAttribute(key, defaultValue); return defaultValue; }
getAttribute
in interface IoSession
public final java.lang.Object setAttribute(java.lang.Object key, java.lang.Object value)
IoSession
setAttribute
in interface IoSession
key
- the key of the attributevalue
- the value of the attributepublic final java.lang.Object setAttribute(java.lang.Object key)
IoSession
Boolean.TRUE
.setAttribute
in interface IoSession
key
- the key of the attributepublic final java.lang.Object setAttributeIfAbsent(java.lang.Object key, java.lang.Object value)
IoSession
if (containsAttribute(key)) { return getAttribute(key); } else { return setAttribute(key, value); }
setAttributeIfAbsent
in interface IoSession
public final java.lang.Object setAttributeIfAbsent(java.lang.Object key)
IoSession
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
in interface IoSession
public final java.lang.Object removeAttribute(java.lang.Object key)
IoSession
removeAttribute
in interface IoSession
public final boolean removeAttribute(java.lang.Object key, java.lang.Object value)
IoSession
if (containsAttribute(key) && getAttribute(key).equals(value)) { removeAttribute(key); return true; } else { return false; }
removeAttribute
in interface IoSession
public final boolean replaceAttribute(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
IoSession
if (containsAttribute(key) && getAttribute(key).equals(oldValue)) { setAttribute(key, newValue); return true; } else { return false; }
replaceAttribute
in interface IoSession
public final boolean containsAttribute(java.lang.Object key)
IoSession
containsAttribute
in interface IoSession
public final java.util.Set<java.lang.Object> getAttributeKeys()
IoSession
getAttributeKeys
in interface IoSession
protected final IoSessionAttributeMap getAttributeMap()
protected final void setAttributeMap(IoSessionAttributeMap attributes)
protected final void setWriteRequestQueue(WriteRequestQueue writeRequestQueue)
public final TrafficMask getTrafficMask()
IoSession
TrafficMask
of this session.getTrafficMask
in interface IoSession
public final void setTrafficMask(TrafficMask trafficMask)
IoSession
TrafficMask
of this session which will result
the parent IoService
to start to control the traffic
of this session immediately.setTrafficMask
in interface IoSession
protected final void setTrafficMaskNow(TrafficMask trafficMask)
public final void suspendRead()
IoSession
IoSession.setTrafficMask(TrafficMask)
that
suspends read operations for this session.suspendRead
in interface IoSession
public final void suspendWrite()
IoSession
IoSession.setTrafficMask(TrafficMask)
that
suspends write operations for this session.suspendWrite
in interface IoSession
public final void resumeRead()
IoSession
IoSession.setTrafficMask(TrafficMask)
that
resumes read operations for this session.resumeRead
in interface IoSession
public final void resumeWrite()
IoSession
IoSession.setTrafficMask(TrafficMask)
that
resumes write operations for this session.resumeWrite
in interface IoSession
public final long getReadBytes()
IoSession
getReadBytes
in interface IoSession
public final long getWrittenBytes()
IoSession
getWrittenBytes
in interface IoSession
public final long getReadMessages()
IoSession
getReadMessages
in interface IoSession
public final long getWrittenMessages()
IoSession
getWrittenMessages
in interface IoSession
public final double getReadBytesThroughput()
IoSession
getReadBytesThroughput
in interface IoSession
public final double getWrittenBytesThroughput()
IoSession
getWrittenBytesThroughput
in interface IoSession
public final double getReadMessagesThroughput()
IoSession
getReadMessagesThroughput
in interface IoSession
public final double getWrittenMessagesThroughput()
IoSession
getWrittenMessagesThroughput
in interface IoSession
protected final void updateThroughput(long currentTime, boolean force)
calculation interval
.
If, however, force is specified as true, this method
updates the throughput properties immediately.currentTime
- the current time in millisecondspublic final long getScheduledWriteBytes()
IoSession
getScheduledWriteBytes
in interface IoSession
public final int getScheduledWriteMessages()
IoSession
getScheduledWriteMessages
in interface IoSession
protected void setScheduledWriteBytes(long byteCount)
protected void setScheduledWriteMessages(int messages)
protected final void increaseReadBytes(long increment, long currentTime)
protected final void increaseReadMessages(long currentTime)
protected final void increaseWrittenBytesAndMessages(WriteRequest request, long currentTime)
protected final void increaseScheduledWriteBytes(long increment)
protected final void increaseScheduledWriteMessages()
protected final void decreaseScheduledBytesAndMessages(WriteRequest request)
protected final WriteRequestQueue getWriteRequestQueue()
protected final WriteRequest getCurrentWriteRequest()
protected final void setCurrentWriteRequest(WriteRequest currentWriteRequest)
protected final void increaseReadBufferSize()
protected final void decreaseReadBufferSize()
public final long getCreationTime()
IoSession
getCreationTime
in interface IoSession
public final long getLastIoTime()
IoSession
getLastIoTime
in interface IoSession
public final long getLastReadTime()
IoSession
getLastReadTime
in interface IoSession
public final long getLastWriteTime()
IoSession
getLastWriteTime
in interface IoSession
public final boolean isIdle(IdleStatus status)
IoSession
true
if this session is idle for the specified
IdleStatus
.public final boolean isBothIdle()
public final boolean isReaderIdle()
public final boolean isWriterIdle()
public final int getIdleCount(IdleStatus status)
IoSession
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.getIdleCount
in interface IoSession
public final long getLastIdleTime(IdleStatus status)
IoSession
IdleStatus
.getLastIdleTime
in interface IoSession
protected final void increaseIdleCount(IdleStatus status, long currentTime)
public final int getBothIdleCount()
IoSession
IdleStatus.BOTH_IDLE
.getBothIdleCount
in interface IoSession
IoSession.getIdleCount(IdleStatus)
public final long getLastBothIdleTime()
IoSession
IdleStatus.BOTH_IDLE
.getLastBothIdleTime
in interface IoSession
IoSession.getLastIdleTime(IdleStatus)
public final long getLastReaderIdleTime()
IoSession
IdleStatus.READER_IDLE
.getLastReaderIdleTime
in interface IoSession
IoSession.getLastIdleTime(IdleStatus)
public final long getLastWriterIdleTime()
IoSession
IdleStatus.WRITER_IDLE
.getLastWriterIdleTime
in interface IoSession
IoSession.getLastIdleTime(IdleStatus)
public final int getReaderIdleCount()
IoSession
IdleStatus.READER_IDLE
.getReaderIdleCount
in interface IoSession
IoSession.getIdleCount(IdleStatus)
public final int getWriterIdleCount()
IoSession
IdleStatus.WRITER_IDLE
.getWriterIdleCount
in interface IoSession
IoSession.getIdleCount(IdleStatus)
public java.net.SocketAddress 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()
.getServiceAddress
in interface IoSession
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2004-2019 Apache MINA Project. All Rights Reserved.