public class Nio2Session extends AbstractCloseable implements IoSession
AbstractCloseable.State| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_READBUF_SIZE |
closeFuture, futureLock, statelog| 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, removeCloseFutureListenerdebug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddCloseFutureListener, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenerpublic static final int DEFAULT_READBUF_SIZE
public Nio2Session(Nio2Service service, PropertyResolver propertyResolver, IoHandler handler, AsynchronousSocketChannel socket, SocketAddress acceptanceAddress) throws IOException
IOExceptionpublic long getId()
public Object getAttribute(Object key)
IoSessiongetAttribute in interface IoSessionkey - the key of the attributenull if there is no attribute with the specified keypublic Object setAttribute(Object key, Object value)
IoSessionsetAttribute in interface IoSessionkey - 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 IoSessionkey - The key of the attribute we want to setvalue - The value we want to setnull if not found.public Object removeAttribute(Object key)
IoSessionremoveAttribute in interface IoSessionkey - The key of the attribute we want to removenull if not found.public SocketAddress getRemoteAddress()
getRemoteAddress in interface ConnectionEndpointsIndicatorpublic SocketAddress getLocalAddress()
getLocalAddress in interface ConnectionEndpointsIndicatorpublic SocketAddress getAcceptanceAddress()
getAcceptanceAddress in interface IoSessionnull 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
IoSessionwriteBuffer in interface IoSessionbuffer - 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 AbstractCloseableprotected void doCloseImmediately()
AbstractCloseabledoCloseImmediately 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 AbstractCloseablepublic Nio2Service getService()
getService in interface IoSessionIoService that created this session.public void shutdownOutputStream()
throws IOException
IoSessionshutdownOutputStream in interface IoSessionIOException - If failed to shutdown the streamprotected void doShutdownOutputStream(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket) throws IOException
IOExceptionpublic 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()
IoSessionsuspendRead in interface IoSessionpublic void resumeRead()
IoSessionresumeRead in interface IoSessionprotected 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–2025 The Apache Software Foundation. All rights reserved.