Package com.google.code.yanf4j.core.impl
Class AbstractSession
java.lang.Object
com.google.code.yanf4j.core.impl.AbstractSession
- All Implemented Interfaces:
Session
- Direct Known Subclasses:
AbstractNioSession
Base connection
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.google.code.yanf4j.core.Session
Session.SessionStatus
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentHashMap
<String, Object> protected boolean
protected AtomicReference
<WriteMessage> protected CodecFactory.Decoder
protected final Dispatcher
protected CodecFactory.Encoder
protected Handler
protected boolean
protected static final org.slf4j.Logger
protected boolean
protected IoBuffer
protected AtomicLong
protected long
protected long
protected Statistics
protected boolean
protected boolean
protected ReentrantLock
protected Queue
<WriteMessage> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear attributesvoid
void
close()
Close sessionprotected abstract void
abstract void
decode()
protected void
dispatchReceivedMessage
(Object message) getAttribute
(String key) Return attribute associated with keyReturn current decoderReturn current encoderlong
Return last operation timestamp,operation include read,write,idlefinal ByteOrder
Return the session read buffer's byte order,big end or little end.long
Return the bytes in write queue,there bytes is in memory.Use this method to controll writing speed.long
long
final boolean
isClosed()
Check if session is closedboolean
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.final boolean
Return true if allow handling read and write concurrently,default is true.boolean
isIdle()
Check if session is idlefinal boolean
return true if it is a loopback connectionboolean
Return true if using blocking readboolean
Return true if using blocking writeprotected void
onClosed()
protected void
protected void
void
void
protected void
onIdle()
private void
protected void
protected WriteMessage
preprocessWriteMessage
(WriteMessage writeMessage) Pre-Process WriteMessage before writing to channelvoid
removeAttribute
(String key) Remove attributevoid
setAttribute
(String key, Object value) Set a attribute attched with this sessionsetAttributeIfAbsent
(String key, Object value) final void
setClosed
(boolean closed) void
setDecoder
(CodecFactory.Decoder decoder) void
setEncoder
(CodecFactory.Encoder encoder) Set encoderfinal void
setHandleReadWriteConcurrently
(boolean handleReadWriteConcurrently) void
setReadBuffer
(IoBuffer readBuffer) final void
setReadBufferByteOrder
(ByteOrder readBufferByteOrder) void
setSessionIdleTimeout
(long sessionIdleTimeout) void
setSessionTimeout
(long sessionTimeout) void
setUseBlockingRead
(boolean useBlockingRead) void
setUseBlockingWrite
(boolean useBlockingWrite) Set if using blocking writevoid
start()
Start sessionprotected abstract void
start0()
long
transferFrom
(long position, long count, FileChannel source) long
transferTo
(long position, long count, FileChannel target) void
protected abstract WriteMessage
wrapMessage
(Object msg, Future<Boolean> writeFuture) void
Write a message,if you don't care when the message is writtenabstract void
writeFromUserCode
(WriteMessage message) 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
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:
getSessionIdleTimeout
in interfaceSession
-
setSessionIdleTimeout
public void setSessionIdleTimeout(long sessionIdleTimeout) - Specified by:
setSessionIdleTimeout
in interfaceSession
-
getSessionTimeout
public long getSessionTimeout()- Specified by:
getSessionTimeout
in interfaceSession
-
setSessionTimeout
public void setSessionTimeout(long sessionTimeout) - Specified by:
setSessionTimeout
in interfaceSession
-
getWriteQueue
-
getStatistics
-
getHandler
- Specified by:
getHandler
in interfaceSession
-
getDispatchMessageDispatcher
-
getWriteLock
-
decode
public abstract void decode() -
updateTimeStamp
public void updateTimeStamp() -
getLastOperationTimeStamp
public long getLastOperationTimeStamp()Description copied from interface:Session
Return last operation timestamp,operation include read,write,idle- Specified by:
getLastOperationTimeStamp
in interfaceSession
- Returns:
-
isHandleReadWriteConcurrently
public final boolean isHandleReadWriteConcurrently()Description copied from interface:Session
Return true if allow handling read and write concurrently,default is true.- Specified by:
isHandleReadWriteConcurrently
in interfaceSession
- Returns:
-
setHandleReadWriteConcurrently
public final void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently) - Specified by:
setHandleReadWriteConcurrently
in interfaceSession
-
getScheduleWritenBytes
public long getScheduleWritenBytes()Description copied from interface:Session
Return the bytes in write queue,there bytes is in memory.Use this method to controll writing speed.- Specified by:
getScheduleWritenBytes
in interfaceSession
- Returns:
-
getEncoder
Description copied from interface:Session
Return current encoder- Specified by:
getEncoder
in interfaceSession
- Returns:
-
setEncoder
Description copied from interface:Session
Set encoder- Specified by:
setEncoder
in interfaceSession
- Parameters:
encoder
-
-
getDecoder
Description copied from interface:Session
Return current decoder- Specified by:
getDecoder
in interfaceSession
- Returns:
-
getReadBuffer
-
setReadBuffer
-
setDecoder
- Specified by:
setDecoder
in interfaceSession
-
getReadBufferByteOrder
Description copied from interface:Session
Return the session read buffer's byte order,big end or little end.- Specified by:
getReadBufferByteOrder
in interfaceSession
- Returns:
-
setReadBufferByteOrder
- Specified by:
setReadBufferByteOrder
in 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
public final boolean isClosed()Description copied from interface:Session
Check if session is closed -
setClosed
public final void setClosed(boolean closed) -
close
public void close()Description copied from interface:Session
Close session -
closeChannel
- Throws:
IOException
-
onException
-
onClosed
protected void onClosed() -
setAttribute
Description copied from interface:Session
Set a attribute attched with this session- Specified by:
setAttribute
in interfaceSession
- Parameters:
key
-value
-
-
setAttributeIfAbsent
- Specified by:
setAttributeIfAbsent
in interfaceSession
-
removeAttribute
Description copied from interface:Session
Remove attribute- Specified by:
removeAttribute
in interfaceSession
- Parameters:
key
-
-
getAttribute
Description copied from interface:Session
Return attribute associated with key- Specified by:
getAttribute
in interfaceSession
- Parameters:
key
-- Returns:
-
clearAttributes
public void clearAttributes()Description copied from interface:Session
Clear attributes- Specified by:
clearAttributes
in interfaceSession
-
start
public void start()Description copied from interface:Session
Start session -
start0
protected abstract void start0() -
onStarted
protected void onStarted() -
write
Description copied from interface:Session
Write a message,if you don't care when the message is written -
writeFromUserCode
-
isLoopbackConnection
public final boolean isLoopbackConnection()Description copied from interface:Session
return true if it is a loopback connection- Specified by:
isLoopbackConnection
in interfaceSession
- Returns:
-
isUseBlockingWrite
public boolean isUseBlockingWrite()Description copied from interface:Session
Return true if using blocking write- Specified by:
isUseBlockingWrite
in interfaceSession
- Returns:
-
setUseBlockingWrite
public void setUseBlockingWrite(boolean useBlockingWrite) Description copied from interface:Session
Set if using blocking write- Specified by:
setUseBlockingWrite
in interfaceSession
- Parameters:
useBlockingWrite
-
-
isUseBlockingRead
public boolean isUseBlockingRead()Description copied from interface:Session
Return true if using blocking read- Specified by:
isUseBlockingRead
in interfaceSession
- Returns:
-
setUseBlockingRead
public void setUseBlockingRead(boolean useBlockingRead) - Specified by:
setUseBlockingRead
in interfaceSession
-
clearWriteQueue
public void clearWriteQueue() -
isExpired
public 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. -
isIdle
public boolean isIdle()Description copied from interface:Session
Check if session is idle -
transferTo
- Throws:
IOException
-
transferFrom
- Throws:
IOException
-
onCreated
protected void onCreated()
-