public abstract class AbstractSession extends Object implements Session
Session.SessionStatus| Modifier and Type | Field and Description |
|---|---|
protected ConcurrentHashMap<String,Object> |
attributes |
protected boolean |
closed |
protected AtomicReference<WriteMessage> |
currentMessage |
protected CodecFactory.Decoder |
decoder |
protected Dispatcher |
dispatchMessageDispatcher |
protected CodecFactory.Encoder |
encoder |
protected Handler |
handler |
protected boolean |
handleReadWriteConcurrently |
AtomicLong |
lastOperationTimeStamp |
protected static org.slf4j.Logger |
log |
protected boolean |
loopback |
protected IoBuffer |
readBuffer |
protected AtomicLong |
scheduleWritenBytes |
protected long |
sessionIdleTimeout |
protected long |
sessionTimeout |
protected Statistics |
statistics |
protected boolean |
useBlockingRead |
protected boolean |
useBlockingWrite |
protected ReentrantLock |
writeLock |
protected Queue<WriteMessage> |
writeQueue |
| Constructor and Description |
|---|
AbstractSession(SessionConfig sessionConfig) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearAttributes()
Clear attributes
|
void |
clearWriteQueue() |
void |
close()
Close session
|
protected abstract void |
closeChannel() |
abstract void |
decode() |
protected void |
dispatchReceivedMessage(Object message) |
Object |
getAttribute(String key)
Return attribute associated with key
|
CodecFactory.Decoder |
getDecoder()
Return current decoder
|
Dispatcher |
getDispatchMessageDispatcher() |
CodecFactory.Encoder |
getEncoder()
Return current encoder
|
Handler |
getHandler() |
long |
getLastOperationTimeStamp()
Return last operation timestamp,operation include read,write,idle
|
IoBuffer |
getReadBuffer() |
ByteOrder |
getReadBufferByteOrder()
Return the session read buffer's byte order,big end or little end.
|
long |
getScheduleWritenBytes()
Return the bytes in write queue,there bytes is in memory.Use this method
to controll writing speed.
|
long |
getSessionIdleTimeout() |
long |
getSessionTimeout() |
Statistics |
getStatistics() |
ReentrantLock |
getWriteLock() |
Queue<WriteMessage> |
getWriteQueue() |
boolean |
isClosed()
Check if session is closed
|
boolean |
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.
|
boolean |
isHandleReadWriteConcurrently()
Return true if allow handling read and write concurrently,default is
true.
|
boolean |
isIdle()
Check if session is idle
|
boolean |
isLoopbackConnection()
return true if it is a loopback connection
|
boolean |
isUseBlockingRead()
Return true if using blocking read
|
boolean |
isUseBlockingWrite()
Return true if using blocking write
|
protected void |
onClosed() |
protected void |
onConnected() |
protected void |
onCreated() |
void |
onException(Throwable e) |
void |
onExpired() |
protected void |
onIdle() |
protected void |
onStarted() |
protected WriteMessage |
preprocessWriteMessage(WriteMessage writeMessage)
Pre-Process WriteMessage before writing to channel
|
void |
removeAttribute(String key)
Remove attribute
|
void |
setAttribute(String key,
Object value)
Set a attribute attched with this session
|
Object |
setAttributeIfAbsent(String key,
Object value) |
void |
setClosed(boolean closed) |
void |
setDecoder(CodecFactory.Decoder decoder) |
void |
setEncoder(CodecFactory.Encoder encoder)
Set encoder
|
void |
setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently) |
void |
setReadBuffer(IoBuffer readBuffer) |
void |
setReadBufferByteOrder(ByteOrder readBufferByteOrder) |
void |
setSessionIdleTimeout(long sessionIdleTimeout) |
void |
setSessionTimeout(long sessionTimeout) |
void |
setUseBlockingRead(boolean useBlockingRead) |
void |
setUseBlockingWrite(boolean useBlockingWrite)
Set if using blocking write
|
void |
start()
Start session
|
protected abstract void |
start0() |
long |
transferFrom(long position,
long count,
FileChannel source) |
long |
transferTo(long position,
long count,
FileChannel target) |
void |
updateTimeStamp() |
protected abstract WriteMessage |
wrapMessage(Object msg,
Future<Boolean> writeFuture) |
void |
write(Object packet)
Write a message,if you don't care when the message is written
|
abstract void |
writeFromUserCode(WriteMessage message) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitflush, getLocalAddress, getRemoteSocketAddressprotected IoBuffer readBuffer
protected static final org.slf4j.Logger log
protected final ConcurrentHashMap<String,Object> attributes
protected Queue<WriteMessage> writeQueue
protected volatile long sessionIdleTimeout
protected volatile long sessionTimeout
protected CodecFactory.Encoder encoder
protected CodecFactory.Decoder decoder
protected volatile boolean closed
protected Statistics statistics
protected Handler handler
protected boolean loopback
public AtomicLong lastOperationTimeStamp
protected AtomicLong scheduleWritenBytes
protected final Dispatcher dispatchMessageDispatcher
protected volatile boolean useBlockingWrite
protected volatile boolean useBlockingRead
protected volatile boolean handleReadWriteConcurrently
protected ReentrantLock writeLock
protected AtomicReference<WriteMessage> currentMessage
public AbstractSession(SessionConfig sessionConfig)
public long getSessionIdleTimeout()
getSessionIdleTimeout in interface Sessionpublic void setSessionIdleTimeout(long sessionIdleTimeout)
setSessionIdleTimeout in interface Sessionpublic long getSessionTimeout()
getSessionTimeout in interface Sessionpublic void setSessionTimeout(long sessionTimeout)
setSessionTimeout in interface Sessionpublic Queue<WriteMessage> getWriteQueue()
public Statistics getStatistics()
public Handler getHandler()
getHandler in interface Sessionpublic Dispatcher getDispatchMessageDispatcher()
public ReentrantLock getWriteLock()
public abstract void decode()
public void updateTimeStamp()
public long getLastOperationTimeStamp()
SessiongetLastOperationTimeStamp in interface Sessionpublic final boolean isHandleReadWriteConcurrently()
SessionisHandleReadWriteConcurrently in interface Sessionpublic final void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
setHandleReadWriteConcurrently in interface Sessionpublic long getScheduleWritenBytes()
SessiongetScheduleWritenBytes in interface Sessionpublic CodecFactory.Encoder getEncoder()
SessiongetEncoder in interface Sessionpublic void setEncoder(CodecFactory.Encoder encoder)
SessionsetEncoder in interface Sessionpublic CodecFactory.Decoder getDecoder()
SessiongetDecoder in interface Sessionpublic IoBuffer getReadBuffer()
public void setReadBuffer(IoBuffer readBuffer)
public void setDecoder(CodecFactory.Decoder decoder)
setDecoder in interface Sessionpublic final ByteOrder getReadBufferByteOrder()
SessiongetReadBufferByteOrder in interface Sessionpublic final void setReadBufferByteOrder(ByteOrder readBufferByteOrder)
setReadBufferByteOrder in interface Sessionprotected void onIdle()
protected void onConnected()
public void onExpired()
protected abstract WriteMessage wrapMessage(Object msg, Future<Boolean> writeFuture)
protected WriteMessage preprocessWriteMessage(WriteMessage writeMessage)
writeMessage - protected void dispatchReceivedMessage(Object message)
public final boolean isClosed()
Sessionpublic final void setClosed(boolean closed)
public void close()
Sessionprotected abstract void closeChannel()
throws IOException
IOExceptionpublic void onException(Throwable e)
protected void onClosed()
public void setAttribute(String key, Object value)
SessionsetAttribute in interface Sessionpublic Object setAttributeIfAbsent(String key, Object value)
setAttributeIfAbsent in interface Sessionpublic void removeAttribute(String key)
SessionremoveAttribute in interface Sessionpublic Object getAttribute(String key)
SessiongetAttribute in interface Sessionpublic void clearAttributes()
SessionclearAttributes in interface Sessionpublic void start()
Sessionprotected abstract void start0()
protected void onStarted()
public void write(Object packet)
Sessionpublic abstract void writeFromUserCode(WriteMessage message)
public final boolean isLoopbackConnection()
SessionisLoopbackConnection in interface Sessionpublic boolean isUseBlockingWrite()
SessionisUseBlockingWrite in interface Sessionpublic void setUseBlockingWrite(boolean useBlockingWrite)
SessionsetUseBlockingWrite in interface Sessionpublic boolean isUseBlockingRead()
SessionisUseBlockingRead in interface Sessionpublic void setUseBlockingRead(boolean useBlockingRead)
setUseBlockingRead in interface Sessionpublic void clearWriteQueue()
public boolean isExpired()
Sessionpublic boolean isIdle()
Sessionpublic long transferTo(long position,
long count,
FileChannel target)
throws IOException
IOExceptionpublic long transferFrom(long position,
long count,
FileChannel source)
throws IOException
IOExceptionprotected void onCreated()
Copyright © 2016. All rights reserved.