Package com.google.code.yanf4j.nio.impl
Class NioTCPSession
- java.lang.Object
-
- com.google.code.yanf4j.core.impl.AbstractSession
-
- com.google.code.yanf4j.nio.impl.AbstractNioSession
-
- com.google.code.yanf4j.nio.impl.NioTCPSession
-
- All Implemented Interfaces:
Session
,NioSession
- Direct Known Subclasses:
MemcachedTCPSession
public class NioTCPSession extends AbstractNioSession
Nio tcp connection
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.code.yanf4j.core.Session
Session.SessionStatus
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.InetSocketAddress
remoteAddress
-
Fields inherited from class com.google.code.yanf4j.nio.impl.AbstractNioSession
selectableChannel, selectorManager
-
Fields inherited from class com.google.code.yanf4j.core.impl.AbstractSession
attributes, closed, currentMessage, decoder, dispatchMessageDispatcher, encoder, handler, handleReadWriteConcurrently, lastOperationTimeStamp, log, loopback, readBuffer, scheduleWritenBytes, sessionIdleTimeout, sessionTimeout, statistics, useBlockingRead, useBlockingWrite, writeLock, writeQueue
-
-
Constructor Summary
Constructors Constructor Description NioTCPSession(NioSessionConfig sessionConfig, int readRecvBufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
blockingRead()
Blocking read using temp selectorprotected java.lang.Object
blockingWrite(java.nio.channels.SelectableChannel channel, WriteMessage message, IoBuffer writeBuffer)
Blocking write using temp selectorprotected void
closeChannel()
void
decode()
Decode bufferprivate void
decodeAndDispatch()
java.net.InetSocketAddress
getRemoteSocketAddress()
Return the remote end's InetSocketAddressboolean
isExpired()
Return true if session is expired,session is expired beacause you set the sessionTimeout,if since session's last operation form now is over this vlaue,isExpired return true,and Handler.onExpired() will be invoked.protected void
readFromBuffer()
java.net.Socket
socket()
protected WriteMessage
wrapMessage(java.lang.Object msg, java.util.concurrent.Future<java.lang.Boolean> writeFuture)
protected java.lang.Object
writeToChannel(WriteMessage message)
-
Methods inherited from class com.google.code.yanf4j.nio.impl.AbstractNioSession
channel, doRealWrite, enableRead, enableWrite, flush, flush0, getLocalAddress, onEvent, onRead, onWrite, registerSession, schduleWriteMessage, start0, unregisterChannel, unregisterSession, writeFromUserCode
-
Methods inherited from class com.google.code.yanf4j.core.impl.AbstractSession
clearAttributes, clearWriteQueue, close, dispatchReceivedMessage, getAttribute, getDecoder, getDispatchMessageDispatcher, getEncoder, getHandler, getLastOperationTimeStamp, getReadBuffer, getReadBufferByteOrder, getScheduleWritenBytes, getSessionIdleTimeout, getSessionTimeout, getStatistics, getWriteLock, getWriteQueue, isClosed, isHandleReadWriteConcurrently, isIdle, isLoopbackConnection, isUseBlockingRead, isUseBlockingWrite, onClosed, onConnected, onCreated, onException, onExpired, onIdle, onStarted, preprocessWriteMessage, removeAttribute, setAttribute, setAttributeIfAbsent, setClosed, setDecoder, setEncoder, setHandleReadWriteConcurrently, setReadBuffer, setReadBufferByteOrder, setSessionIdleTimeout, setSessionTimeout, setUseBlockingRead, setUseBlockingWrite, start, transferFrom, transferTo, updateTimeStamp, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.code.yanf4j.core.Session
clearAttributes, close, getAttribute, getDecoder, getEncoder, getHandler, getLastOperationTimeStamp, getReadBufferByteOrder, getScheduleWritenBytes, getSessionIdleTimeout, getSessionTimeout, isClosed, isHandleReadWriteConcurrently, isIdle, isLoopbackConnection, isUseBlockingRead, isUseBlockingWrite, removeAttribute, setAttribute, setAttributeIfAbsent, setDecoder, setEncoder, setHandleReadWriteConcurrently, setReadBufferByteOrder, setSessionIdleTimeout, setSessionTimeout, setUseBlockingRead, setUseBlockingWrite, start, write
-
-
-
-
Constructor Detail
-
NioTCPSession
public NioTCPSession(NioSessionConfig sessionConfig, int readRecvBufferSize)
-
-
Method Detail
-
isExpired
public final boolean isExpired()
Description copied from interface:Session
Return true if session is expired,session is expired beacause you set the sessionTimeout,if since session's last operation form now is over this vlaue,isExpired return true,and Handler.onExpired() will be invoked.- Specified by:
isExpired
in interfaceSession
- Overrides:
isExpired
in classAbstractSession
- Returns:
-
writeToChannel
protected java.lang.Object writeToChannel(WriteMessage message) throws java.io.IOException
- Specified by:
writeToChannel
in classAbstractNioSession
- Throws:
java.io.IOException
-
getRemoteSocketAddress
public java.net.InetSocketAddress getRemoteSocketAddress()
Description copied from interface:Session
Return the remote end's InetSocketAddress- Returns:
-
blockingWrite
protected final java.lang.Object blockingWrite(java.nio.channels.SelectableChannel channel, WriteMessage message, IoBuffer writeBuffer) throws java.io.IOException, java.nio.channels.ClosedChannelException
Blocking write using temp selector- Parameters:
channel
-message
-writeBuffer
-- Returns:
- Throws:
java.io.IOException
java.nio.channels.ClosedChannelException
-
wrapMessage
protected WriteMessage wrapMessage(java.lang.Object msg, java.util.concurrent.Future<java.lang.Boolean> writeFuture)
- Specified by:
wrapMessage
in classAbstractSession
-
readFromBuffer
protected void readFromBuffer()
- Specified by:
readFromBuffer
in classAbstractNioSession
-
decodeAndDispatch
private void decodeAndDispatch()
-
blockingRead
protected final int blockingRead() throws java.nio.channels.ClosedChannelException, java.io.IOException
Blocking read using temp selector- Returns:
- Throws:
java.nio.channels.ClosedChannelException
java.io.IOException
-
decode
public void decode()
Decode buffer- Specified by:
decode
in classAbstractSession
-
socket
public java.net.Socket socket()
-
closeChannel
protected final void closeChannel() throws java.io.IOException
- Overrides:
closeChannel
in classAbstractNioSession
- Throws:
java.io.IOException
-
-