|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.code.yanf4j.core.impl.AbstractSession
public abstract class AbstractSession
Base connection
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.google.code.yanf4j.core.Session |
|---|
Session.SessionStatus |
| Field Summary | |
|---|---|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object> |
attributes
|
protected boolean |
closed
|
protected java.util.concurrent.atomic.AtomicReference<WriteMessage> |
currentMessage
|
protected CodecFactory.Decoder |
decoder
|
protected Dispatcher |
dispatchMessageDispatcher
|
protected CodecFactory.Encoder |
encoder
|
protected Handler |
handler
|
protected boolean |
handleReadWriteConcurrently
|
java.util.concurrent.atomic.AtomicLong |
lastOperationTimeStamp
|
protected static org.slf4j.Logger |
log
|
protected boolean |
loopback
|
protected IoBuffer |
readBuffer
|
protected java.util.concurrent.atomic.AtomicLong |
scheduleWritenBytes
|
protected long |
sessionIdleTimeout
|
protected long |
sessionTimeout
|
protected Statistics |
statistics
|
protected boolean |
useBlockingRead
|
protected boolean |
useBlockingWrite
|
protected java.util.concurrent.locks.ReentrantLock |
writeLock
|
protected java.util.Queue<WriteMessage> |
writeQueue
|
| Constructor Summary | |
|---|---|
AbstractSession(SessionConfig sessionConfig)
|
|
| Method Summary | |
|---|---|
void |
clearAttributes()
Clear attributes |
void |
clearWriteQueue()
|
void |
close()
Close session |
protected abstract void |
closeChannel()
|
abstract void |
decode()
|
protected void |
dispatchReceivedMessage(java.lang.Object message)
|
java.lang.Object |
getAttribute(java.lang.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()
|
java.nio.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()
|
java.util.concurrent.locks.ReentrantLock |
getWriteLock()
|
java.util.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(java.lang.Throwable e)
|
void |
onExpired()
|
protected void |
onIdle()
|
protected void |
onStarted()
|
protected WriteMessage |
preprocessWriteMessage(WriteMessage writeMessage)
Pre-Process WriteMessage before writing to channel |
void |
removeAttribute(java.lang.String key)
Remove attribute |
void |
setAttribute(java.lang.String key,
java.lang.Object value)
Set a attribute attched with this session |
java.lang.Object |
setAttributeIfAbsent(java.lang.String key,
java.lang.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(java.nio.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,
java.nio.channels.FileChannel source)
|
long |
transferTo(long position,
long count,
java.nio.channels.FileChannel target)
|
void |
updateTimeStamp()
|
protected abstract WriteMessage |
wrapMessage(java.lang.Object msg,
java.util.concurrent.Future<java.lang.Boolean> writeFuture)
|
void |
write(java.lang.Object packet)
Write a message,if you don't care when the message is written |
abstract 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 Detail |
|---|
protected IoBuffer readBuffer
protected static final org.slf4j.Logger log
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object> attributes
protected java.util.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 java.util.concurrent.atomic.AtomicLong lastOperationTimeStamp
protected java.util.concurrent.atomic.AtomicLong scheduleWritenBytes
protected final Dispatcher dispatchMessageDispatcher
protected volatile boolean useBlockingWrite
protected volatile boolean useBlockingRead
protected volatile boolean handleReadWriteConcurrently
protected java.util.concurrent.locks.ReentrantLock writeLock
protected java.util.concurrent.atomic.AtomicReference<WriteMessage> currentMessage
| Constructor Detail |
|---|
public AbstractSession(SessionConfig sessionConfig)
| Method Detail |
|---|
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 java.util.Queue<WriteMessage> getWriteQueue()
public Statistics getStatistics()
public Handler getHandler()
getHandler in interface Sessionpublic Dispatcher getDispatchMessageDispatcher()
public java.util.concurrent.locks.ReentrantLock getWriteLock()
public abstract void decode()
public void updateTimeStamp()
public long getLastOperationTimeStamp()
Session
getLastOperationTimeStamp in interface Sessionpublic final boolean isHandleReadWriteConcurrently()
Session
isHandleReadWriteConcurrently in interface Sessionpublic final void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
setHandleReadWriteConcurrently in interface Sessionpublic long getScheduleWritenBytes()
Session
getScheduleWritenBytes in interface Sessionpublic CodecFactory.Encoder getEncoder()
Session
getEncoder in interface Sessionpublic void setEncoder(CodecFactory.Encoder encoder)
Session
setEncoder in interface Sessionpublic CodecFactory.Decoder getDecoder()
Session
getDecoder in interface Sessionpublic IoBuffer getReadBuffer()
public void setReadBuffer(IoBuffer readBuffer)
public void setDecoder(CodecFactory.Decoder decoder)
setDecoder in interface Sessionpublic final java.nio.ByteOrder getReadBufferByteOrder()
Session
getReadBufferByteOrder in interface Sessionpublic final void setReadBufferByteOrder(java.nio.ByteOrder readBufferByteOrder)
setReadBufferByteOrder in interface Sessionprotected void onIdle()
protected void onConnected()
public void onExpired()
protected abstract WriteMessage wrapMessage(java.lang.Object msg,
java.util.concurrent.Future<java.lang.Boolean> writeFuture)
protected WriteMessage preprocessWriteMessage(WriteMessage writeMessage)
writeMessage -
protected void dispatchReceivedMessage(java.lang.Object message)
public final boolean isClosed()
Session
isClosed in interface Sessionpublic final void setClosed(boolean closed)
public void close()
Session
close in interface Session
protected abstract void closeChannel()
throws java.io.IOException
java.io.IOExceptionpublic void onException(java.lang.Throwable e)
protected void onClosed()
public void setAttribute(java.lang.String key,
java.lang.Object value)
Session
setAttribute in interface Session
public java.lang.Object setAttributeIfAbsent(java.lang.String key,
java.lang.Object value)
setAttributeIfAbsent in interface Sessionpublic void removeAttribute(java.lang.String key)
Session
removeAttribute in interface Sessionpublic java.lang.Object getAttribute(java.lang.String key)
Session
getAttribute in interface Sessionpublic void clearAttributes()
Session
clearAttributes in interface Sessionpublic void start()
Session
start in interface Sessionprotected abstract void start0()
protected void onStarted()
public void write(java.lang.Object packet)
Session
write in interface Sessionpublic abstract void writeFromUserCode(WriteMessage message)
public final boolean isLoopbackConnection()
Session
isLoopbackConnection in interface Sessionpublic boolean isUseBlockingWrite()
Session
isUseBlockingWrite in interface Sessionpublic void setUseBlockingWrite(boolean useBlockingWrite)
Session
setUseBlockingWrite in interface Sessionpublic boolean isUseBlockingRead()
Session
isUseBlockingRead in interface Sessionpublic void setUseBlockingRead(boolean useBlockingRead)
setUseBlockingRead in interface Sessionpublic void clearWriteQueue()
public boolean isExpired()
Session
isExpired in interface Sessionpublic boolean isIdle()
Session
isIdle in interface Session
public long transferTo(long position,
long count,
java.nio.channels.FileChannel target)
throws java.io.IOException
java.io.IOException
public long transferFrom(long position,
long count,
java.nio.channels.FileChannel source)
throws java.io.IOException
java.io.IOExceptionprotected void onCreated()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||