Package com.google.code.yanf4j.nio.impl
Class AbstractNioSession
- java.lang.Object
-
- com.google.code.yanf4j.core.impl.AbstractSession
-
- com.google.code.yanf4j.nio.impl.AbstractNioSession
-
- All Implemented Interfaces:
Session
,NioSession
- Direct Known Subclasses:
NioTCPSession
public abstract class AbstractNioSession extends AbstractSession implements NioSession
Abstract nio session
-
-
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 protected java.nio.channels.SelectableChannel
selectableChannel
protected SelectorManager
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 AbstractNioSession(NioSessionConfig sessionConfig)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.nio.channels.SelectableChannel
channel()
return the channel for this connectionprotected void
closeChannel()
protected long
doRealWrite(java.nio.channels.SelectableChannel channel, IoBuffer buffer)
void
enableRead(java.nio.channels.Selector selector)
Enable read eventvoid
enableWrite(java.nio.channels.Selector selector)
Enable write eventvoid
flush()
Flush the write queue,this method may be no effect if OP_WRITE is running.protected void
flush0()
java.net.InetAddress
getLocalAddress()
private void
interestRead(java.nio.channels.SelectionKey key)
private void
interestWrite(java.nio.channels.SelectionKey key)
void
onEvent(EventType event, java.nio.channels.Selector selector)
�ɷ�IO�¼�protected void
onRead(java.nio.channels.SelectionKey key)
protected void
onWrite(java.nio.channels.SelectionKey key)
protected abstract void
readFromBuffer()
protected void
registerSession()
protected boolean
schduleWriteMessage(WriteMessage writeMessage)
protected void
start0()
protected void
unregisterChannel()
protected void
unregisterSession()
void
writeFromUserCode(WriteMessage message)
protected abstract java.lang.Object
writeToChannel(WriteMessage msg)
-
Methods inherited from class com.google.code.yanf4j.core.impl.AbstractSession
clearAttributes, clearWriteQueue, close, decode, dispatchReceivedMessage, getAttribute, getDecoder, getDispatchMessageDispatcher, getEncoder, getHandler, getLastOperationTimeStamp, getReadBuffer, getReadBufferByteOrder, getScheduleWritenBytes, getSessionIdleTimeout, getSessionTimeout, getStatistics, getWriteLock, getWriteQueue, isClosed, isExpired, 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, wrapMessage, 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, getRemoteSocketAddress, getScheduleWritenBytes, getSessionIdleTimeout, getSessionTimeout, isClosed, isExpired, isHandleReadWriteConcurrently, isIdle, isLoopbackConnection, isUseBlockingRead, isUseBlockingWrite, removeAttribute, setAttribute, setAttributeIfAbsent, setDecoder, setEncoder, setHandleReadWriteConcurrently, setReadBufferByteOrder, setSessionIdleTimeout, setSessionTimeout, setUseBlockingRead, setUseBlockingWrite, start, write
-
-
-
-
Field Detail
-
selectorManager
protected SelectorManager selectorManager
-
selectableChannel
protected java.nio.channels.SelectableChannel selectableChannel
-
-
Constructor Detail
-
AbstractNioSession
public AbstractNioSession(NioSessionConfig sessionConfig)
-
-
Method Detail
-
channel
public java.nio.channels.SelectableChannel channel()
Description copied from interface:NioSession
return the channel for this connection- Specified by:
channel
in interfaceNioSession
- Returns:
-
enableRead
public final void enableRead(java.nio.channels.Selector selector)
Description copied from interface:NioSession
Enable read event- Specified by:
enableRead
in interfaceNioSession
-
interestRead
private void interestRead(java.nio.channels.SelectionKey key)
-
start0
protected void start0()
- Specified by:
start0
in classAbstractSession
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
- Specified by:
getLocalAddress
in interfaceSession
-
writeToChannel
protected abstract java.lang.Object writeToChannel(WriteMessage msg) throws java.nio.channels.ClosedChannelException, java.io.IOException
- Throws:
java.nio.channels.ClosedChannelException
java.io.IOException
-
onWrite
protected void onWrite(java.nio.channels.SelectionKey key)
-
enableWrite
public final void enableWrite(java.nio.channels.Selector selector)
Description copied from interface:NioSession
Enable write event- Specified by:
enableWrite
in interfaceNioSession
-
interestWrite
private void interestWrite(java.nio.channels.SelectionKey key)
-
onRead
protected void onRead(java.nio.channels.SelectionKey key)
-
readFromBuffer
protected abstract void readFromBuffer()
-
closeChannel
protected void closeChannel() throws java.io.IOException
- Specified by:
closeChannel
in classAbstractSession
- Throws:
java.io.IOException
-
unregisterChannel
protected final void unregisterChannel() throws java.io.IOException
- Throws:
java.io.IOException
-
registerSession
protected final void registerSession()
-
unregisterSession
protected void unregisterSession()
-
writeFromUserCode
public void writeFromUserCode(WriteMessage message)
- Specified by:
writeFromUserCode
in classAbstractSession
-
schduleWriteMessage
protected boolean schduleWriteMessage(WriteMessage writeMessage)
-
flush
public void flush()
Description copied from interface:Session
Flush the write queue,this method may be no effect if OP_WRITE is running.
-
flush0
protected final void flush0()
-
doRealWrite
protected final long doRealWrite(java.nio.channels.SelectableChannel channel, IoBuffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
onEvent
public final void onEvent(EventType event, java.nio.channels.Selector selector)
�ɷ�IO�¼�- Specified by:
onEvent
in interfaceNioSession
-
-