public class Nio2Session extends AbstractCloseable implements IoSession
AbstractCloseable.State
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_READBUF_SIZE |
closeFuture, futureLock, state
log
Constructor and Description |
---|
Nio2Session(Nio2Service service,
PropertyResolver propertyResolver,
IoHandler handler,
AsynchronousSocketChannel socket,
SocketAddress acceptanceAddress) |
Modifier and Type | Method and Description |
---|---|
protected Nio2CompletionHandler<Integer,Object> |
createReadCycleCompletionHandler(ByteBuffer buffer,
Readable bufReader) |
protected Nio2CompletionHandler<Integer,Object> |
createWriteCycleCompletionHandler(Nio2DefaultIoWriteFuture future,
AsynchronousSocketChannel socket,
ByteBuffer buffer) |
protected CloseFuture |
doCloseGracefully() |
protected void |
doCloseImmediately()
doCloseImmediately is called once and only once with state == Immediate
|
protected void |
doReadCycle(ByteBuffer buffer,
Nio2CompletionHandler<Integer,Object> completion) |
protected void |
doReadCycle(ByteBuffer buffer,
Readable bufReader) |
protected void |
doShutdownOutputStream(Nio2DefaultIoWriteFuture future,
AsynchronousSocketChannel socket) |
protected void |
doWriteCycle(ByteBuffer buffer,
Nio2CompletionHandler<Integer,Object> completion) |
protected void |
exceptionCaught(Throwable exc) |
protected void |
finishWrite(Nio2DefaultIoWriteFuture future) |
SocketAddress |
getAcceptanceAddress() |
Object |
getAttribute(Object key)
Returns the value of the user-defined attribute of this session.
|
long |
getId() |
IoHandler |
getIoHandler() |
SocketAddress |
getLocalAddress() |
SocketAddress |
getRemoteAddress() |
Nio2Service |
getService() |
AsynchronousSocketChannel |
getSocket() |
protected void |
handleCompletedWriteCycle(Nio2DefaultIoWriteFuture future,
AsynchronousSocketChannel socket,
ByteBuffer buffer,
int writeLen,
Nio2CompletionHandler<Integer,Object> completionHandler,
Integer result,
Object attachment) |
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 |
handleWriteCycleFailure(Nio2DefaultIoWriteFuture future,
AsynchronousSocketChannel socket,
ByteBuffer buffer,
int writeLen,
Throwable exc,
Object attachment) |
Object |
removeAttribute(Object key)
Removes a user-defined attribute with the specified key.
|
void |
resumeRead()
Resume read operations on this session.
|
Object |
setAttribute(Object key,
Object value)
Sets a user-defined attribute.
|
Object |
setAttributeIfAbsent(Object key,
Object value)
Sets a user defined attribute if the attribute with the specified key is not set yet.
|
void |
shutdownOutputStream()
Handle received EOF.
|
void |
startReading() |
void |
startReading(byte[] buf) |
void |
startReading(byte[] buf,
int offset,
int len) |
void |
startReading(ByteBuffer buffer) |
void |
startReading(int bufSize) |
protected void |
startWriting() |
void |
suspend()
Intended for tests simulating a sudden connection drop only! Do not call otherwise.
|
void |
suspendRead()
Suspend read operations on this session.
|
String |
toString() |
IoWriteFuture |
writeBuffer(Buffer buffer)
Write a packet on the socket.
|
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListener
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addCloseFutureListener, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
public static final int DEFAULT_READBUF_SIZE
public Nio2Session(Nio2Service service, PropertyResolver propertyResolver, 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 writeBuffer(Buffer buffer) throws IOException
IoSession
writeBuffer
in interface IoSession
buffer
- the buffer 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 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 shutdownOutputStream() throws IOException
IoSession
shutdownOutputStream
in interface IoSession
IOException
- If failed to shutdown the streamprotected void doShutdownOutputStream(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket) throws IOException
IOException
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)
public void suspendRead()
IoSession
suspendRead
in interface IoSession
public void resumeRead()
IoSession
resumeRead
in interface IoSession
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–2024 The Apache Software Foundation. All rights reserved.