Class AbstractSession
java.lang.Object
com.google.code.yanf4j.core.impl.AbstractSession
- All Implemented Interfaces:
Session
- Direct Known Subclasses:
AbstractNioSession
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface Session
Session.SessionStatus -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentHashMap<String, Object> protected booleanprotected AtomicReference<WriteMessage> protected CodecFactory.Decoderprotected final Dispatcherprotected CodecFactory.Encoderprotected Handlerprotected booleanprotected static final org.slf4j.Loggerprotected booleanprotected IoBufferprotected AtomicLongprotected longprotected longprotected Statisticsprotected booleanprotected booleanprotected ReentrantLockprotected Queue<WriteMessage> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear attributesvoidvoidclose()Close sessionprotected abstract voidabstract voiddecode()protected voiddispatchReceivedMessage(Object message) getAttribute(String key) Return attribute associated with keyReturn current decoderReturn current encoderlongReturn last operation timestamp,operation include read,write,idlefinal ByteOrderReturn the session read buffer's byte order,big end or little end.longReturn the bytes in write queue,there bytes is in memory.Use this method to controll writing speed.longlongfinal booleanisClosed()Check if session is closedbooleanReturn 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.final booleanReturn true if allow handling read and write concurrently,default is true.booleanisIdle()Check if session is idlefinal booleanreturn true if it is a loopback connectionbooleanReturn true if using blocking readbooleanReturn true if using blocking writeprotected voidonClosed()protected voidprotected voidvoidvoidprotected voidonIdle()private voidprotected voidprotected WriteMessagepreprocessWriteMessage(WriteMessage writeMessage) Pre-Process WriteMessage before writing to channelvoidremoveAttribute(String key) Remove attributevoidsetAttribute(String key, Object value) Set a attribute attched with this sessionsetAttributeIfAbsent(String key, Object value) final voidsetClosed(boolean closed) voidsetDecoder(CodecFactory.Decoder decoder) voidsetEncoder(CodecFactory.Encoder encoder) Set encoderfinal voidsetHandleReadWriteConcurrently(boolean handleReadWriteConcurrently) voidsetReadBuffer(IoBuffer readBuffer) final voidsetReadBufferByteOrder(ByteOrder readBufferByteOrder) voidsetSessionIdleTimeout(long sessionIdleTimeout) voidsetSessionTimeout(long sessionTimeout) voidsetUseBlockingRead(boolean useBlockingRead) voidsetUseBlockingWrite(boolean useBlockingWrite) Set if using blocking writevoidstart()Start sessionprotected abstract voidstart0()longtransferFrom(long position, long count, FileChannel source) longtransferTo(long position, long count, FileChannel target) voidprotected abstract WriteMessagewrapMessage(Object msg, Future<Boolean> writeFuture) voidWrite a message,if you don't care when the message is writtenabstract voidwriteFromUserCode(WriteMessage message) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Session
flush, getLocalAddress, getRemoteSocketAddress
-
Field Details
-
readBuffer
-
log
protected static final org.slf4j.Logger log -
attributes
-
writeQueue
-
sessionIdleTimeout
protected long sessionIdleTimeout -
sessionTimeout
protected long sessionTimeout -
encoder
-
decoder
-
closed
protected volatile boolean closed -
statistics
-
handler
-
loopback
protected boolean loopback -
lastOperationTimeStamp
-
scheduleWritenBytes
-
dispatchMessageDispatcher
-
useBlockingWrite
protected boolean useBlockingWrite -
useBlockingRead
protected boolean useBlockingRead -
handleReadWriteConcurrently
protected boolean handleReadWriteConcurrently -
writeLock
-
currentMessage
-
-
Constructor Details
-
AbstractSession
-
-
Method Details
-
getSessionIdleTimeout
public long getSessionIdleTimeout()- Specified by:
getSessionIdleTimeoutin interfaceSession
-
setSessionIdleTimeout
public void setSessionIdleTimeout(long sessionIdleTimeout) - Specified by:
setSessionIdleTimeoutin interfaceSession
-
getSessionTimeout
public long getSessionTimeout()- Specified by:
getSessionTimeoutin interfaceSession
-
setSessionTimeout
public void setSessionTimeout(long sessionTimeout) - Specified by:
setSessionTimeoutin interfaceSession
-
getWriteQueue
-
getStatistics
-
getHandler
- Specified by:
getHandlerin interfaceSession
-
getDispatchMessageDispatcher
-
getWriteLock
-
decode
public abstract void decode() -
updateTimeStamp
public void updateTimeStamp() -
getLastOperationTimeStamp
public long getLastOperationTimeStamp()Description copied from interface:SessionReturn last operation timestamp,operation include read,write,idle- Specified by:
getLastOperationTimeStampin interfaceSession- Returns:
-
isHandleReadWriteConcurrently
public final boolean isHandleReadWriteConcurrently()Description copied from interface:SessionReturn true if allow handling read and write concurrently,default is true.- Specified by:
isHandleReadWriteConcurrentlyin interfaceSession- Returns:
-
setHandleReadWriteConcurrently
public final void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently) - Specified by:
setHandleReadWriteConcurrentlyin interfaceSession
-
getScheduleWritenBytes
public long getScheduleWritenBytes()Description copied from interface:SessionReturn the bytes in write queue,there bytes is in memory.Use this method to controll writing speed.- Specified by:
getScheduleWritenBytesin interfaceSession- Returns:
-
getEncoder
Description copied from interface:SessionReturn current encoder- Specified by:
getEncoderin interfaceSession- Returns:
-
setEncoder
Description copied from interface:SessionSet encoder- Specified by:
setEncoderin interfaceSession- Parameters:
encoder-
-
getDecoder
Description copied from interface:SessionReturn current decoder- Specified by:
getDecoderin interfaceSession- Returns:
-
getReadBuffer
-
setReadBuffer
-
setDecoder
- Specified by:
setDecoderin interfaceSession
-
getReadBufferByteOrder
Description copied from interface:SessionReturn the session read buffer's byte order,big end or little end.- Specified by:
getReadBufferByteOrderin interfaceSession- Returns:
-
setReadBufferByteOrder
- Specified by:
setReadBufferByteOrderin interfaceSession
-
onIdle
protected void onIdle() -
onConnected
protected void onConnected() -
onExpired
public void onExpired() -
wrapMessage
-
preprocessWriteMessage
Pre-Process WriteMessage before writing to channel- Parameters:
writeMessage-- Returns:
-
dispatchReceivedMessage
-
onMessage
-
isClosed
-
setClosed
public final void setClosed(boolean closed) -
close
-
closeChannel
- Throws:
IOException
-
onException
-
onClosed
protected void onClosed() -
setAttribute
Description copied from interface:SessionSet a attribute attched with this session- Specified by:
setAttributein interfaceSession- Parameters:
key-value-
-
setAttributeIfAbsent
- Specified by:
setAttributeIfAbsentin interfaceSession
-
removeAttribute
Description copied from interface:SessionRemove attribute- Specified by:
removeAttributein interfaceSession- Parameters:
key-
-
getAttribute
Description copied from interface:SessionReturn attribute associated with key- Specified by:
getAttributein interfaceSession- Parameters:
key-- Returns:
-
clearAttributes
public void clearAttributes()Description copied from interface:SessionClear attributes- Specified by:
clearAttributesin interfaceSession
-
start
-
start0
protected abstract void start0() -
onStarted
protected void onStarted() -
write
-
writeFromUserCode
-
isLoopbackConnection
public final boolean isLoopbackConnection()Description copied from interface:Sessionreturn true if it is a loopback connection- Specified by:
isLoopbackConnectionin interfaceSession- Returns:
-
isUseBlockingWrite
public boolean isUseBlockingWrite()Description copied from interface:SessionReturn true if using blocking write- Specified by:
isUseBlockingWritein interfaceSession- Returns:
-
setUseBlockingWrite
public void setUseBlockingWrite(boolean useBlockingWrite) Description copied from interface:SessionSet if using blocking write- Specified by:
setUseBlockingWritein interfaceSession- Parameters:
useBlockingWrite-
-
isUseBlockingRead
public boolean isUseBlockingRead()Description copied from interface:SessionReturn true if using blocking read- Specified by:
isUseBlockingReadin interfaceSession- Returns:
-
setUseBlockingRead
public void setUseBlockingRead(boolean useBlockingRead) - Specified by:
setUseBlockingReadin interfaceSession
-
clearWriteQueue
public void clearWriteQueue() -
isExpired
public boolean isExpired()Description copied from interface:SessionReturn 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. -
isIdle
-
transferTo
- Throws:
IOException
-
transferFrom
- Throws:
IOException
-
onCreated
protected void onCreated()
-