Interface IoSession
-
- All Known Subinterfaces:
BroadcastIoSession
- All Known Implementing Classes:
BaseIoSession,VmPipeSessionImpl
public interface IoSessionA handle which represents connection between two endpoints regardless of transport types.IoSessionprovides user-defined attributes. User-defined attributes are application-specific data which is associated with a session. It often contains objects that represents the state of a higher-level protocol and becomes a way to exchange data between filters and handlers.Adjusting Transport Type Specific Properties
You can simply downcast the session to an appropriate subclass.
Thread Safety
IoSessionis thread-safe. But please note that performing more than onewrite(Object)calls at the same time will cause theIoFilter.filterWrite(IoFilter.NextFilter, IoSession, IoFilter.WriteRequest)is executed simnutaneously, and therefore you have to make sure theIoFilterimplementations you're using are thread-safe, too.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CloseFutureclose()Closes this session immediately.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.IoSessionConfiggetConfig()Returns the configuration of this session.longgetCreationTime()Returns the time in millis when this session is created.IoFilterChaingetFilterChain()Returns the filter chain that only affects this session.IoHandlergetHandler()Returns theIoHandlerwhich handles this session.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.java.net.SocketAddressgetLocalAddress()Returns the socket address of local machine which is associated with this session.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.java.net.SocketAddressgetRemoteAddress()Returns the socket address of remote peer.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.IoServicegetService()Returns theIoServicewhich provides I/O service to this session.java.net.SocketAddressgetServiceAddress()Returns the socket address of theIoServicelistens to to manage this session.IoServiceConfiggetServiceConfig()Returns theIoServiceConfigof this session.TrafficMaskgetTrafficMask()Returns the currentTrafficMaskof this session.TransportTypegetTransportType()Returns transport type of 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.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.java.lang.ObjectremoveAttribute(java.lang.String key)Removes a user-defined attribute with the specified key.voidresumeRead()A shortcut method forsetTrafficMask(TrafficMask)that resumes read operations for this session.voidresumeWrite()A shortcut method forsetTrafficMask(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.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 forsetTrafficMask(TrafficMask)that suspends read operations for this session.voidsuspendWrite()A shortcut method forsetTrafficMask(TrafficMask)that suspends write operations for this session.WriteFuturewrite(java.lang.Object message)Writes the specifiedmessageto remote peer.
-
-
-
Method Detail
-
getServiceConfig
IoServiceConfig getServiceConfig()
Returns theIoServiceConfigof this session.
-
getConfig
IoSessionConfig getConfig()
Returns the configuration of this session.
-
getFilterChain
IoFilterChain getFilterChain()
Returns the filter chain that only affects this session.
-
write
WriteFuture write(java.lang.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.
-
close
CloseFuture close()
Closes this session immediately. This operation is asynthronous. Wait for the returnedCloseFutureif you want to wait for the session actually closed.
-
getAttachment
java.lang.Object getAttachment()
Returns an attachment of this session. This method is identical with getAttribute( "" ).
-
setAttachment
java.lang.Object setAttachment(java.lang.Object attachment)
Sets an attachment of this session. This method is identical with setAttribute( "", attachment ).- Returns:
- Old attachment. null if it is new.
-
getAttribute
java.lang.Object getAttribute(java.lang.String key)
Returns the value of user-defined attribute of this session.- Parameters:
key- the key of the attribute- Returns:
- null if there is no attribute with the specified key
-
setAttribute
java.lang.Object setAttribute(java.lang.String key, java.lang.Object value)Sets a user-defined attribute.- 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
java.lang.Object setAttribute(java.lang.String 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.- Parameters:
key- the key of the attribute- Returns:
- The old value of the attribute. null if it is new.
-
removeAttribute
java.lang.Object removeAttribute(java.lang.String key)
Removes a user-defined attribute with the specified key.- Returns:
- The old value of the attribute. null if not found.
-
containsAttribute
boolean containsAttribute(java.lang.String key)
Returns true if this session contains the attribute with the specified key.
-
getAttributeKeys
java.util.Set<java.lang.String> getAttributeKeys()
Returns the set of keys of all user-defined attributes.
-
getTransportType
TransportType getTransportType()
Returns transport type of this session.
-
isConnected
boolean isConnected()
Returnstrueif this session is connected with remote peer.
-
isClosing
boolean isClosing()
Returnstrue if and only if this session is being closed (but not disconnected yet) or is closed.
-
getCloseFuture
CloseFuture getCloseFuture()
Returns theCloseFutureof this session. This method returns the same instance whenever user calls it.
-
getRemoteAddress
java.net.SocketAddress getRemoteAddress()
Returns the socket address of remote peer.
-
getLocalAddress
java.net.SocketAddress getLocalAddress()
Returns the socket address of local machine which is associated with this session.
-
getServiceAddress
java.net.SocketAddress getServiceAddress()
Returns the socket address of theIoServicelistens to to manage this session. If this session is managed byIoAcceptor, it returns theSocketAddresswhich is specified as a parameter ofIoAcceptor.bind(SocketAddress, IoHandler). If this session is managed byIoConnector, this method returns the same address with that ofgetRemoteAddress().
-
getIdleTime
int getIdleTime(IdleStatus status)
Returns idle time for the specified type of idleness in seconds.
-
getIdleTimeInMillis
long getIdleTimeInMillis(IdleStatus status)
Returns idle time for the specified type of idleness in milliseconds.
-
setIdleTime
void setIdleTime(IdleStatus status, int idleTime)
Sets idle time for the specified type of idleness in seconds.
-
getWriteTimeout
int getWriteTimeout()
Returns write timeout in seconds.
-
getWriteTimeoutInMillis
long getWriteTimeoutInMillis()
Returns write timeout in milliseconds.
-
setWriteTimeout
void setWriteTimeout(int writeTimeout)
Sets write timeout in seconds.
-
getTrafficMask
TrafficMask getTrafficMask()
Returns the currentTrafficMaskof this session.
-
setTrafficMask
void setTrafficMask(TrafficMask trafficMask)
Sets theTrafficMaskof this session which will result the parentIoServiceto start to control the traffic of this session immediately.
-
suspendRead
void suspendRead()
A shortcut method forsetTrafficMask(TrafficMask)that suspends read operations for this session.
-
suspendWrite
void suspendWrite()
A shortcut method forsetTrafficMask(TrafficMask)that suspends write operations for this session.
-
resumeRead
void resumeRead()
A shortcut method forsetTrafficMask(TrafficMask)that resumes read operations for this session.
-
resumeWrite
void resumeWrite()
A shortcut method forsetTrafficMask(TrafficMask)that resumes write operations for this session.
-
getReadBytes
long getReadBytes()
Returns the total number of bytes which were read from this session.
-
getWrittenBytes
long getWrittenBytes()
Returns the total number of bytes which were written to this session.
-
getReadMessages
long getReadMessages()
Returns the total number of messages which were read and decoded from this session.
-
getWrittenMessages
long getWrittenMessages()
Returns the total number of messages which were written and encoded by this session.
-
getWrittenWriteRequests
long getWrittenWriteRequests()
Returns the total number of write requests which were written to this session.
-
getScheduledWriteRequests
int getScheduledWriteRequests()
Returns the number of write requests which are scheduled to be written to this session.
-
getScheduledWriteBytes
int getScheduledWriteBytes()
Returns the number of bytes which are scheduled to be written to this session.
-
getCreationTime
long getCreationTime()
Returns the time in millis when this session is created.
-
getLastIoTime
long getLastIoTime()
Returns the time in millis when I/O occurred lastly.
-
getLastReadTime
long getLastReadTime()
Returns the time in millis when read operation occurred lastly.
-
getLastWriteTime
long getLastWriteTime()
Returns the time in millis when write operation occurred lastly.
-
isIdle
boolean isIdle(IdleStatus status)
Returnstrueif this session is idle for the specifiedIdleStatus.
-
getIdleCount
int getIdleCount(IdleStatus status)
Returns 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.
-
getLastIdleTime
long getLastIdleTime(IdleStatus status)
Returns the time in millis when the last sessionIdle event is fired for the specifiedIdleStatus.
-
-