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, wait
flush, getLocalAddress, getRemoteSocketAddress
protected IoBuffer readBuffer
protected static final org.slf4j.Logger log
protected final ConcurrentHashMap<String,Object> attributes
protected Queue<WriteMessage> writeQueue
protected long sessionIdleTimeout
protected 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 boolean useBlockingWrite
protected boolean useBlockingRead
protected boolean handleReadWriteConcurrently
protected ReentrantLock writeLock
protected AtomicReference<WriteMessage> currentMessage
public AbstractSession(SessionConfig sessionConfig)
public long getSessionIdleTimeout()
getSessionIdleTimeout
in interface Session
public void setSessionIdleTimeout(long sessionIdleTimeout)
setSessionIdleTimeout
in interface Session
public long getSessionTimeout()
getSessionTimeout
in interface Session
public void setSessionTimeout(long sessionTimeout)
setSessionTimeout
in interface Session
public Queue<WriteMessage> getWriteQueue()
public Statistics getStatistics()
public Handler getHandler()
getHandler
in interface Session
public Dispatcher getDispatchMessageDispatcher()
public ReentrantLock getWriteLock()
public abstract void decode()
public void updateTimeStamp()
public long getLastOperationTimeStamp()
Session
getLastOperationTimeStamp
in interface Session
public final boolean isHandleReadWriteConcurrently()
Session
isHandleReadWriteConcurrently
in interface Session
public final void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
setHandleReadWriteConcurrently
in interface Session
public long getScheduleWritenBytes()
Session
getScheduleWritenBytes
in interface Session
public CodecFactory.Encoder getEncoder()
Session
getEncoder
in interface Session
public void setEncoder(CodecFactory.Encoder encoder)
Session
setEncoder
in interface Session
public CodecFactory.Decoder getDecoder()
Session
getDecoder
in interface Session
public IoBuffer getReadBuffer()
public void setReadBuffer(IoBuffer readBuffer)
public void setDecoder(CodecFactory.Decoder decoder)
setDecoder
in interface Session
public final ByteOrder getReadBufferByteOrder()
Session
getReadBufferByteOrder
in interface Session
public final void setReadBufferByteOrder(ByteOrder readBufferByteOrder)
setReadBufferByteOrder
in interface Session
protected 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()
Session
public final void setClosed(boolean closed)
public void close()
Session
protected abstract void closeChannel() throws IOException
IOException
public void onException(Throwable e)
protected void onClosed()
public void setAttribute(String key, Object value)
Session
setAttribute
in interface Session
public Object setAttributeIfAbsent(String key, Object value)
setAttributeIfAbsent
in interface Session
public void removeAttribute(String key)
Session
removeAttribute
in interface Session
public Object getAttribute(String key)
Session
getAttribute
in interface Session
public void clearAttributes()
Session
clearAttributes
in interface Session
public void start()
Session
protected abstract void start0()
protected void onStarted()
public void write(Object packet)
Session
public abstract void writeFromUserCode(WriteMessage message)
public final boolean isLoopbackConnection()
Session
isLoopbackConnection
in interface Session
public boolean isUseBlockingWrite()
Session
isUseBlockingWrite
in interface Session
public void setUseBlockingWrite(boolean useBlockingWrite)
Session
setUseBlockingWrite
in interface Session
public boolean isUseBlockingRead()
Session
isUseBlockingRead
in interface Session
public void setUseBlockingRead(boolean useBlockingRead)
setUseBlockingRead
in interface Session
public void clearWriteQueue()
public boolean isExpired()
Session
public boolean isIdle()
Session
public long transferTo(long position, long count, FileChannel target) throws IOException
IOException
public long transferFrom(long position, long count, FileChannel source) throws IOException
IOException
protected void onCreated()
Copyright © 2021. All rights reserved.