public class Nio2Session extends AbstractCloseable implements IoSession
AbstractCloseable.State
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_READBUF_SIZE |
closeFuture, lock, state
log
CLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT
Constructor and Description |
---|
Nio2Session(Nio2Service service,
FactoryManager manager,
IoHandler handler,
AsynchronousSocketChannel socket,
SocketAddress acceptanceAddress) |
addCloseFutureListener, builder, close, isClosed, isClosing, preClose, removeCloseFutureListener
getSimplifiedLogger
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
public static final int DEFAULT_READBUF_SIZE
public Nio2Session(Nio2Service service, FactoryManager manager, IoHandler handler, AsynchronousSocketChannel socket, SocketAddress acceptanceAddress) throws IOException
IOException
public long getId()
public Object getAttribute(Object key)
IoSession
getAttribute
in interface IoSession
key
- the key of the attributenull
if there is no attribute with the specified keypublic Object setAttribute(Object key, Object value)
IoSession
setAttribute
in interface IoSession
key
- the key of the attributevalue
- the value of the attributenull
if it is new.public Object setAttributeIfAbsent(Object key, Object value)
IoSession
if (containsAttribute(key)) {
return getAttribute(key);
} else {
return setAttribute(key, value);
}
setAttributeIfAbsent
in interface IoSession
key
- The key of the attribute we want to setvalue
- The value we want to setnull
if not found.public Object removeAttribute(Object key)
IoSession
removeAttribute
in interface IoSession
key
- The key of the attribute we want to removenull
if not found.public SocketAddress getRemoteAddress()
getRemoteAddress
in interface ConnectionEndpointsIndicator
public SocketAddress getLocalAddress()
getLocalAddress
in interface ConnectionEndpointsIndicator
public SocketAddress getAcceptanceAddress()
getAcceptanceAddress
in interface IoSession
null
if session was initiated by this peer instead of being acceptedpublic AsynchronousSocketChannel getSocket()
public IoHandler getIoHandler()
public void suspend()
public IoWriteFuture writePacket(Buffer buffer) throws IOException
PacketWriter
writePacket
in interface PacketWriter
buffer
- the buffer to encode and send. NOTE: the buffer must not be touched
until the returned write future is completed.IoWriteFuture
that can be used to check when the packet has actually been sentIOException
- if an error occurred when encoding sending the packetprotected void exceptionCaught(Throwable exc)
protected CloseFuture doCloseGracefully()
doCloseGracefully
in class AbstractCloseable
protected void doCloseImmediately()
AbstractCloseable
doCloseImmediately is called once and only once with state == Immediate
Overriding methods should always call the base implementation. It may be called concurrently while preClose() or doCloseGracefully is executing
doCloseImmediately
in class AbstractCloseable
public Nio2Service getService()
getService
in interface IoSession
IoService
that created this session.public void startReading()
public void startReading(int bufSize)
public void startReading(byte[] buf)
public void startReading(byte[] buf, int offset, int len)
public void startReading(ByteBuffer buffer)
protected void doReadCycle(ByteBuffer buffer, Readable bufReader)
protected Nio2CompletionHandler<Integer,Object> createReadCycleCompletionHandler(ByteBuffer buffer, Readable bufReader)
protected void handleReadCycleCompletion(ByteBuffer buffer, Readable bufReader, Nio2CompletionHandler<Integer,Object> completionHandler, Integer result, Object attachment)
protected void handleReadCycleFailure(ByteBuffer buffer, Readable bufReader, Throwable exc, Object attachment)
protected void doReadCycle(ByteBuffer buffer, Nio2CompletionHandler<Integer,Object> completion)
protected void startWriting()
protected void doWriteCycle(ByteBuffer buffer, Nio2CompletionHandler<Integer,Object> completion)
protected Nio2CompletionHandler<Integer,Object> createWriteCycleCompletionHandler(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer)
protected void handleCompletedWriteCycle(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer, int writeLen, Nio2CompletionHandler<Integer,Object> completionHandler, Integer result, Object attachment)
protected void handleWriteCycleFailure(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer, int writeLen, Throwable exc, Object attachment)
protected void finishWrite(Nio2DefaultIoWriteFuture future)
Copyright © 2008–2022 The Apache Software Foundation. All rights reserved.