Package org.apache.mina.common.support
Class BaseIoSession
- java.lang.Object
-
- org.apache.mina.common.support.BaseIoSession
-
- All Implemented Interfaces:
IoSession
- Direct Known Subclasses:
VmPipeSessionImpl
public abstract class BaseIoSession extends java.lang.Object implements IoSession
Base implementation ofIoSession.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseIoSession()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CloseFutureclose()Closes this session immediately.protected voidclose0()Implement this method to perform real close operation.booleancontainsAttribute(java.lang.String key)Returns true if this session contains the attribute with the specified key.java.lang.ObjectgetAttachment()Returns an attachment of this session.java.lang.ObjectgetAttribute(java.lang.String key)Returns the value of user-defined attribute of this session.java.util.Set<java.lang.String>getAttributeKeys()Returns the set of keys of all user-defined attributes.CloseFuturegetCloseFuture()Returns theCloseFutureof this session.longgetCreationTime()Returns the time in millis when this session is created.intgetIdleCount(IdleStatus status)Returns the number of the fired continuous sessionIdle events for the specifiedIdleStatus.intgetIdleTime(IdleStatus status)Returns idle time for the specified type of idleness in seconds.longgetIdleTimeInMillis(IdleStatus status)Returns idle time for the specified type of idleness in milliseconds.longgetLastIdleTime(IdleStatus status)Returns the time in millis when the last sessionIdle event is fired for the specifiedIdleStatus.longgetLastIoTime()Returns the time in millis when I/O occurred lastly.longgetLastReadTime()Returns the time in millis when read operation occurred lastly.longgetLastWriteTime()Returns the time in millis when write operation occurred lastly.longgetReadBytes()Returns the total number of bytes which were read from this session.longgetReadMessages()Returns the total number of messages which were read and decoded from this session.intgetScheduledWriteBytes()Returns the number of bytes which are scheduled to be written to this session.intgetScheduledWriteRequests()Returns the number of write requests which are scheduled to be written to this session.TrafficMaskgetTrafficMask()Returns the currentTrafficMaskof this session.intgetWriteTimeout()Returns write timeout in seconds.longgetWriteTimeoutInMillis()Returns write timeout in milliseconds.longgetWrittenBytes()Returns the total number of bytes which were written to this session.longgetWrittenMessages()Returns the total number of messages which were written and encoded by this session.longgetWrittenWriteRequests()Returns the total number of write requests which were written to this session.voidincreaseIdleCount(IdleStatus status)voidincreaseReadBytes(int increment)voidincreaseReadMessages()voidincreaseScheduledWriteBytes(int increment)voidincreaseScheduledWriteRequests()voidincreaseWrittenBytes(int increment)voidincreaseWrittenMessages()booleanisClosing()Returnstrue if and only if this session is being closed (but not disconnected yet) or is closed.booleanisConnected()Returnstrueif this session is connected with remote peer.booleanisIdle(IdleStatus status)Returnstrueif this session is idle for the specifiedIdleStatus.booleanisScheduledForFlush()java.lang.ObjectremoveAttribute(java.lang.String key)Removes a user-defined attribute with the specified key.voidresumeRead()A shortcut method forIoSession.setTrafficMask(TrafficMask)that resumes read operations for this session.voidresumeWrite()A shortcut method forIoSession.setTrafficMask(TrafficMask)that resumes write operations for this session.java.lang.ObjectsetAttachment(java.lang.Object attachment)Sets an attachment of this session.java.lang.ObjectsetAttribute(java.lang.String key)Sets a user defined attribute without a value.java.lang.ObjectsetAttribute(java.lang.String key, java.lang.Object value)Sets a user-defined attribute.voidsetIdleTime(IdleStatus status, int idleTime)Sets idle time for the specified type of idleness in seconds.booleansetScheduledForFlush(boolean flag)voidsetTrafficMask(TrafficMask trafficMask)Sets theTrafficMaskof this session which will result the parentIoServiceto start to control the traffic of this session immediately.voidsetWriteTimeout(int writeTimeout)Sets write timeout in seconds.voidsuspendRead()A shortcut method forIoSession.setTrafficMask(TrafficMask)that suspends read operations for this session.voidsuspendWrite()A shortcut method forIoSession.setTrafficMask(TrafficMask)that suspends write operations for this session.java.lang.StringtoString()protected abstract voidupdateTrafficMask()Signals theIoServicethat theTrafficMaskof this session has been changed.WriteFuturewrite(java.lang.Object message)Writes the specifiedmessageto remote peer.WriteFuturewrite(java.lang.Object message, java.net.SocketAddress remoteAddress)protected voidwrite0(IoFilter.WriteRequest writeRequest)Implement this method to perform real write operation with the specifiedwriteRequest.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.mina.common.IoSession
getConfig, getFilterChain, getHandler, getLocalAddress, getRemoteAddress, getService, getServiceAddress, getServiceConfig, getTransportType
-
-
-
-
Method Detail
-
isConnected
public boolean isConnected()
Description copied from interface:IoSessionReturnstrueif this session is connected with remote peer.- Specified by:
isConnectedin interfaceIoSession
-
isClosing
public boolean isClosing()
Description copied from interface:IoSessionReturnstrue if and only if this session is being closed (but not disconnected yet) or is closed.
-
getCloseFuture
public CloseFuture getCloseFuture()
Description copied from interface:IoSessionReturns theCloseFutureof this session. This method returns the same instance whenever user calls it.- Specified by:
getCloseFuturein interfaceIoSession
-
isScheduledForFlush
public boolean isScheduledForFlush()
-
setScheduledForFlush
public boolean setScheduledForFlush(boolean flag)
-
close
public CloseFuture close()
Description copied from interface:IoSessionCloses this session immediately. This operation is asynthronous. Wait for the returnedCloseFutureif you want to wait for the session actually closed.
-
close0
protected void close0()
Implement this method to perform real close operation. By default, this method is implemented to set the future to 'closed' immediately.
-
write
public WriteFuture write(java.lang.Object message)
Description copied from interface:IoSessionWrites 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(java.lang.Object message, java.net.SocketAddress remoteAddress)
-
write0
protected void write0(IoFilter.WriteRequest writeRequest)
Implement this method to perform real write operation with the specifiedwriteRequest. By default, this method is implemented to set the future to 'not written' immediately.- Parameters:
writeRequest- Write request to make
-
getAttachment
public java.lang.Object getAttachment()
Description copied from interface:IoSessionReturns an attachment of this session. This method is identical with getAttribute( "" ).- Specified by:
getAttachmentin interfaceIoSession
-
setAttachment
public java.lang.Object setAttachment(java.lang.Object attachment)
Description copied from interface:IoSessionSets an attachment of this session. This method is identical with setAttribute( "", attachment ).- Specified by:
setAttachmentin interfaceIoSession- Returns:
- Old attachment. null if it is new.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String key)
Description copied from interface:IoSessionReturns the value of user-defined attribute of this session.- Specified by:
getAttributein interfaceIoSession- Parameters:
key- the key of the attribute- Returns:
- null if there is no attribute with the specified key
-
setAttribute
public java.lang.Object setAttribute(java.lang.String key, java.lang.Object value)Description copied from interface:IoSessionSets 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. null if it is new.
-
setAttribute
public java.lang.Object setAttribute(java.lang.String key)
Description copied from interface:IoSessionSets 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. null if it is new.
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String key)
Description copied from interface:IoSessionRemoves a user-defined attribute with the specified key.- Specified by:
removeAttributein interfaceIoSession- Returns:
- The old value of the attribute. null if not found.
-
containsAttribute
public boolean containsAttribute(java.lang.String key)
Description copied from interface:IoSessionReturns true if this session contains the attribute with the specified key.- Specified by:
containsAttributein interfaceIoSession
-
getAttributeKeys
public java.util.Set<java.lang.String> getAttributeKeys()
Description copied from interface:IoSessionReturns the set of keys of all user-defined attributes.- Specified by:
getAttributeKeysin interfaceIoSession
-
getIdleTime
public int getIdleTime(IdleStatus status)
Description copied from interface:IoSessionReturns idle time for the specified type of idleness in seconds.- Specified by:
getIdleTimein interfaceIoSession
-
getIdleTimeInMillis
public long getIdleTimeInMillis(IdleStatus status)
Description copied from interface:IoSessionReturns idle time for the specified type of idleness in milliseconds.- Specified by:
getIdleTimeInMillisin interfaceIoSession
-
setIdleTime
public void setIdleTime(IdleStatus status, int idleTime)
Description copied from interface:IoSessionSets idle time for the specified type of idleness in seconds.- Specified by:
setIdleTimein interfaceIoSession
-
getWriteTimeout
public int getWriteTimeout()
Description copied from interface:IoSessionReturns write timeout in seconds.- Specified by:
getWriteTimeoutin interfaceIoSession
-
getWriteTimeoutInMillis
public long getWriteTimeoutInMillis()
Description copied from interface:IoSessionReturns write timeout in milliseconds.- Specified by:
getWriteTimeoutInMillisin interfaceIoSession
-
setWriteTimeout
public void setWriteTimeout(int writeTimeout)
Description copied from interface:IoSessionSets write timeout in seconds.- Specified by:
setWriteTimeoutin interfaceIoSession
-
getTrafficMask
public TrafficMask getTrafficMask()
Description copied from interface:IoSessionReturns the currentTrafficMaskof this session.- Specified by:
getTrafficMaskin interfaceIoSession
-
setTrafficMask
public void setTrafficMask(TrafficMask trafficMask)
Description copied from interface:IoSessionSets theTrafficMaskof this session which will result the parentIoServiceto start to control the traffic of this session immediately.- Specified by:
setTrafficMaskin interfaceIoSession
-
suspendRead
public void suspendRead()
Description copied from interface:IoSessionA shortcut method forIoSession.setTrafficMask(TrafficMask)that suspends read operations for this session.- Specified by:
suspendReadin interfaceIoSession
-
suspendWrite
public void suspendWrite()
Description copied from interface:IoSessionA shortcut method forIoSession.setTrafficMask(TrafficMask)that suspends write operations for this session.- Specified by:
suspendWritein interfaceIoSession
-
resumeRead
public void resumeRead()
Description copied from interface:IoSessionA shortcut method forIoSession.setTrafficMask(TrafficMask)that resumes read operations for this session.- Specified by:
resumeReadin interfaceIoSession
-
resumeWrite
public void resumeWrite()
Description copied from interface:IoSessionA shortcut method forIoSession.setTrafficMask(TrafficMask)that resumes write operations for this session.- Specified by:
resumeWritein interfaceIoSession
-
updateTrafficMask
protected abstract void updateTrafficMask()
Signals theIoServicethat theTrafficMaskof this session has been changed.
-
getReadBytes
public long getReadBytes()
Description copied from interface:IoSessionReturns the total number of bytes which were read from this session.- Specified by:
getReadBytesin interfaceIoSession
-
getWrittenBytes
public long getWrittenBytes()
Description copied from interface:IoSessionReturns the total number of bytes which were written to this session.- Specified by:
getWrittenBytesin interfaceIoSession
-
getWrittenWriteRequests
public long getWrittenWriteRequests()
Description copied from interface:IoSessionReturns the total number of write requests which were written to this session.- Specified by:
getWrittenWriteRequestsin interfaceIoSession
-
getReadMessages
public long getReadMessages()
Description copied from interface:IoSessionReturns the total number of messages which were read and decoded from this session.- Specified by:
getReadMessagesin interfaceIoSession
-
getWrittenMessages
public long getWrittenMessages()
Description copied from interface:IoSessionReturns the total number of messages which were written and encoded by this session.- Specified by:
getWrittenMessagesin interfaceIoSession
-
getScheduledWriteBytes
public int getScheduledWriteBytes()
Description copied from interface:IoSessionReturns the number of bytes which are scheduled to be written to this session.- Specified by:
getScheduledWriteBytesin interfaceIoSession
-
getScheduledWriteRequests
public int getScheduledWriteRequests()
Description copied from interface:IoSessionReturns the number of write requests which are scheduled to be written to this session.- Specified by:
getScheduledWriteRequestsin interfaceIoSession
-
increaseReadBytes
public void increaseReadBytes(int increment)
-
increaseWrittenBytes
public void increaseWrittenBytes(int increment)
-
increaseReadMessages
public void increaseReadMessages()
-
increaseWrittenMessages
public void increaseWrittenMessages()
-
increaseScheduledWriteBytes
public void increaseScheduledWriteBytes(int increment)
-
increaseScheduledWriteRequests
public void increaseScheduledWriteRequests()
-
getCreationTime
public long getCreationTime()
Description copied from interface:IoSessionReturns the time in millis when this session is created.- Specified by:
getCreationTimein interfaceIoSession
-
getLastIoTime
public long getLastIoTime()
Description copied from interface:IoSessionReturns the time in millis when I/O occurred lastly.- Specified by:
getLastIoTimein interfaceIoSession
-
getLastReadTime
public long getLastReadTime()
Description copied from interface:IoSessionReturns the time in millis when read operation occurred lastly.- Specified by:
getLastReadTimein interfaceIoSession
-
getLastWriteTime
public long getLastWriteTime()
Description copied from interface:IoSessionReturns the time in millis when write operation occurred lastly.- Specified by:
getLastWriteTimein interfaceIoSession
-
isIdle
public boolean isIdle(IdleStatus status)
Description copied from interface:IoSessionReturnstrueif this session is idle for the specifiedIdleStatus.
-
getIdleCount
public int getIdleCount(IdleStatus status)
Description copied from interface:IoSessionReturns the number of the fired continuous sessionIdle events for the specifiedIdleStatus.If sessionIdle event is fired first after some time after I/O, idleCount becomes 1. idleCount resets to 0 if any I/O occurs again, otherwise it increases to 2 and so on if sessionIdle event is fired again without any I/O between two (or more) sessionIdle events.
- Specified by:
getIdleCountin interfaceIoSession
-
getLastIdleTime
public long getLastIdleTime(IdleStatus status)
Description copied from interface:IoSessionReturns the time in millis when the last sessionIdle event is fired for the specifiedIdleStatus.- Specified by:
getLastIdleTimein interfaceIoSession
-
increaseIdleCount
public void increaseIdleCount(IdleStatus status)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-