Top Fields Constructors Methods
org.apache.sshd.common.io.nio2

public Class Nio2Session

extends AbstractCloseable
implements IoSession
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.io.IoSession, org.apache.sshd.common.Closeable, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, org.apache.sshd.common.util.net.ConnectionEndpointsIndicator
Imports
java.io.IOException, .WriteAbortedException, java.net.SocketAddress, java.nio.ByteBuffer, java.nio.channels.AsynchronousSocketChannel, .ClosedChannelException, java.time.Duration, java.util.HashMap, .Map, .Objects, .Queue, java.util.concurrent.ConcurrentLinkedQueue, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, org.apache.sshd.common.PropertyResolver, .RuntimeSshException, org.apache.sshd.common.future.CloseFuture, org.apache.sshd.common.io.IoHandler, .IoSession, .IoWriteFuture, org.apache.sshd.common.util.ExceptionUtils, .Readable, org.apache.sshd.common.util.buffer.Buffer, org.apache.sshd.common.util.closeable.AbstractCloseable, org.apache.sshd.core.CoreModuleProperties

Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private final SocketAddress
private final Map<Object, Object>
private final AtomicReference<Nio2DefaultIoWriteFuture>
public static final int
private final long
private final IoHandler
private final AtomicLong
private final AtomicLong
private final SocketAddress
private final AtomicBoolean
private final PropertyResolver
private final AtomicLong
private Thread
private volatile Runnable
private final SocketAddress
private final Nio2Service
private static final AtomicLong
private final AsynchronousSocketChannel
private volatile boolean
private final Object
private final AtomicLong
private final Queue<Nio2DefaultIoWriteFuture>
Inherited from org.apache.sshd.common.util.closeable.AbstractCloseable:
closeFuturefutureLockstate

Constructor Summary

AccessConstructor and Description
public
Nio2Session(Nio2Service service, PropertyResolver propertyResolver, IoHandler handler, AsynchronousSocketChannel socket, SocketAddress acceptanceAddress)

Method Summary

Modifier and TypeMethod and Description
protected Nio2CompletionHandler<Integer, Object>
protected Nio2CompletionHandler<Integer, Object>
protected CloseFuture
protected void
doCloseImmediately()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseImmediately.

doCloseImmediately is called once and only once with state == Immediate Overriding methods should always call the base implementation.

protected void
doReadCycle(ByteBuffer buffer, Readable bufReader)

protected void
protected void
protected void
protected void
protected void
public SocketAddress
public Object
getAttribute(Object
the key of the attribute
key
)

Implements org.apache.sshd.common.io.IoSession.getAttribute.

Returns the value of the user-defined attribute of this session.

public long
public IoHandler
public SocketAddress
public SocketAddress
public Nio2Service
public AsynchronousSocketChannel
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
public Object
removeAttribute(Object
The key of the attribute we want to remove
key
)

Implements org.apache.sshd.common.io.IoSession.removeAttribute.

Removes a user-defined attribute with the specified key.

public void
resumeRead()

Implements org.apache.sshd.common.io.IoSession.resumeRead.

Resume read operations on this session.

public Object
setAttribute(Object
the key of the attribute
key
,
Object
the value of the attribute
value
)

Implements org.apache.sshd.common.io.IoSession.setAttribute.

Sets a user-defined attribute.

public Object
setAttributeIfAbsent(Object
The key of the attribute we want to set
key
,
Object
The value we want to set
value
)

Implements org.apache.sshd.common.io.IoSession.setAttributeIfAbsent.

Sets a user defined attribute if the attribute with the specified key is not set yet.

public void
public void
public void
startReading(int bufSize)

public void
startReading(byte[] buf)

public void
startReading(byte[] buf, int offset, int len)

public void
protected void
public void
suspend()

Intended for tests simulating a sudden connection drop only!

public void
suspendRead()

Implements org.apache.sshd.common.io.IoSession.suspendRead.

Suspend read operations on this session.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public IoWriteFuture
writeBuffer(Buffer
the buffer send

Note

the buffer must not be touched until the returned write future is completed.

buffer
)

Implements org.apache.sshd.common.io.IoSession.writeBuffer.

Write a packet on the socket.

Inherited from org.apache.sshd.common.util.closeable.AbstractCloseable:
addCloseFutureListenerbuilderclosegetFutureLockisClosedisClosingpreCloseremoveCloseFutureListener

Field Detail

acceptanceAddressback to summary
private final SocketAddress acceptanceAddress
attributesback to summary
private final Map<Object, Object> attributes
currentWriteback to summary
private final AtomicReference<Nio2DefaultIoWriteFuture> currentWrite
DEFAULT_READBUF_SIZEback to summary
public static final int DEFAULT_READBUF_SIZE
idback to summary
private final long id
ioHandlerback to summary
private final IoHandler ioHandler
lastReadCycleStartback to summary
private final AtomicLong lastReadCycleStart
lastWriteCycleStartback to summary
private final AtomicLong lastWriteCycleStart
localAddressback to summary
private final SocketAddress localAddress
outputShutDownback to summary
private final AtomicBoolean outputShutDown
propertyResolverback to summary
private final PropertyResolver propertyResolver
readCyclesCounterback to summary
private final AtomicLong readCyclesCounter
readerThreadback to summary
private Thread readerThread
readRunnableback to summary
private volatile Runnable readRunnable
remoteAddressback to summary
private final SocketAddress remoteAddress
serviceback to summary
private final Nio2Service service
SESSION_ID_GENERATORback to summary
private static final AtomicLong SESSION_ID_GENERATOR
socketChannelback to summary
private final AsynchronousSocketChannel socketChannel
suspendback to summary
private volatile boolean suspend
suspendLockback to summary
private final Object suspendLock
writeCyclesCounterback to summary
private final AtomicLong writeCyclesCounter
writesback to summary
private final Queue<Nio2DefaultIoWriteFuture> writes

Constructor Detail

Nio2Sessionback to summary
public Nio2Session(Nio2Service service, PropertyResolver propertyResolver, IoHandler handler, AsynchronousSocketChannel socket, SocketAddress acceptanceAddress) throws IOException

Method Detail

createReadCycleCompletionHandlerback to summary
protected Nio2CompletionHandler<Integer, Object> createReadCycleCompletionHandler(ByteBuffer buffer, Readable bufReader)
createWriteCycleCompletionHandlerback to summary
protected Nio2CompletionHandler<Integer, Object> createWriteCycleCompletionHandler(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer)
doCloseGracefullyback to summary
protected CloseFuture doCloseGracefully()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseGracefully.

Annotations
@Override
doCloseImmediatelyback to summary
protected void doCloseImmediately()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseImmediately.

Doc from org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseImmediately.

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

Annotations
@Override
doReadCycleback to summary
protected void doReadCycle(ByteBuffer buffer, Readable bufReader)
doReadCycleback to summary
protected void doReadCycle(ByteBuffer buffer, Nio2CompletionHandler<Integer, Object> completion)
doShutdownOutputStreamback to summary
protected void doShutdownOutputStream(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket) throws IOException
doWriteCycleback to summary
protected void doWriteCycle(ByteBuffer buffer, Nio2CompletionHandler<Integer, Object> completion)
exceptionCaughtback to summary
protected void exceptionCaught(Throwable exc)
finishWriteback to summary
protected void finishWrite(Nio2DefaultIoWriteFuture future)
getAcceptanceAddressback to summary
public SocketAddress getAcceptanceAddress()

Implements org.apache.sshd.common.io.IoSession.getAcceptanceAddress.

Returns:SocketAddress

Doc from org.apache.sshd.common.io.IoSession.getAcceptanceAddress.

The service address through which this session was accepted - null if session was initiated by this peer instead of being accepted

Annotations
@Override
getAttributeback to summary
public Object getAttribute(Object key)

Implements org.apache.sshd.common.io.IoSession.getAttribute.

Doc from org.apache.sshd.common.io.IoSession.getAttribute.

Returns the value of the user-defined attribute of this session.

Parameters
key:Object

the key of the attribute

Returns:Object

null if there is no attribute with the specified key

Annotations
@Override
getIdback to summary
public long getId()

Implements org.apache.sshd.common.io.IoSession.getId.

Returns:long

Doc from org.apache.sshd.common.io.IoSession.getId.

a unique identifier for this session. Every session has its own ID which is different from any other.

Annotations
@Override
getIoHandlerback to summary
public IoHandler getIoHandler()
getLocalAddressback to summary
public SocketAddress getLocalAddress()

Implements org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getLocalAddress.

Returns:SocketAddress

Doc from org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getLocalAddress.

the socket address of local machine which is associated with this session.

Annotations
@Override
getRemoteAddressback to summary
public SocketAddress getRemoteAddress()

Implements org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getRemoteAddress.

Returns:SocketAddress

Doc from org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getRemoteAddress.

the socket address of remote peer.

Annotations
@Override
getServiceback to summary
public Nio2Service getService()

Implements org.apache.sshd.common.io.IoSession.getService.

Returns:Nio2Service

Doc from org.apache.sshd.common.io.IoSession.getService.

the IoService that created this session.

Annotations
@Override
getSocketback to summary
public AsynchronousSocketChannel getSocket()
handleCompletedWriteCycleback to summary
protected void handleCompletedWriteCycle(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer, int writeLen, Nio2CompletionHandler<Integer, Object> completionHandler, Integer result, Object attachment)
handleReadCycleCompletionback to summary
protected void handleReadCycleCompletion(ByteBuffer buffer, Readable bufReader, Nio2CompletionHandler<Integer, Object> completionHandler, Integer result, Object attachment)
handleReadCycleFailureback to summary
protected void handleReadCycleFailure(ByteBuffer buffer, Readable bufReader, Throwable exc, Object attachment)
handleWriteCycleFailureback to summary
protected void handleWriteCycleFailure(Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer, int writeLen, Throwable exc, Object attachment)
removeAttributeback to summary
public Object removeAttribute(Object key)

Implements org.apache.sshd.common.io.IoSession.removeAttribute.

Doc from org.apache.sshd.common.io.IoSession.removeAttribute.

Removes a user-defined attribute with the specified key.

Parameters
key:Object

The key of the attribute we want to remove

Returns:Object

The old value of the attribute - null if not found.

Annotations
@Override
resumeReadback to summary
public void resumeRead()

Implements org.apache.sshd.common.io.IoSession.resumeRead.

Doc from org.apache.sshd.common.io.IoSession.resumeRead.

Resume read operations on this session.

Annotations
@Override
setAttributeback to summary
public Object setAttribute(Object key, Object value)

Implements org.apache.sshd.common.io.IoSession.setAttribute.

Doc from org.apache.sshd.common.io.IoSession.setAttribute.

Sets a user-defined attribute.

Parameters
key:Object

the key of the attribute

value:Object

the value of the attribute

Returns:Object

The old value of the attribute - null if it is new.

Annotations
@Override
setAttributeIfAbsentback to summary
public Object setAttributeIfAbsent(Object key, Object value)

Implements org.apache.sshd.common.io.IoSession.setAttributeIfAbsent.

Doc from org.apache.sshd.common.io.IoSession.setAttributeIfAbsent.

Sets a user defined attribute if the attribute with the specified key is not set yet. This method is same with the following code except that the operation is performed atomically.


if (containsAttribute(key)) {
    return getAttribute(key);
} else {
    return setAttribute(key, value);
}

Parameters
key:Object

The key of the attribute we want to set

value:Object

The value we want to set

Returns:Object

The old value of the attribute - null if not found.

Annotations
@Override
shutdownOutputStreamback to summary
public void shutdownOutputStream() throws IOException

Implements org.apache.sshd.common.io.IoSession.shutdownOutputStream.

Doc from org.apache.sshd.common.io.IoSession.shutdownOutputStream.

Handle received EOF.

Annotations
@Override
Exceptions
IOException:
If failed to shutdown the stream
startReadingback to summary
public void startReading()
startReadingback to summary
public void startReading(int bufSize)
startReadingback to summary
public void startReading(byte[] buf)
startReadingback to summary
public void startReading(byte[] buf, int offset, int len)
startReadingback to summary
public void startReading(ByteBuffer buffer)
startWritingback to summary
protected void startWriting()
suspendback to summary
public void suspend()

Intended for tests simulating a sudden connection drop only! Do not call otherwise.

suspendReadback to summary
public void suspendRead()

Implements org.apache.sshd.common.io.IoSession.suspendRead.

Doc from org.apache.sshd.common.io.IoSession.suspendRead.

Suspend read operations on this session. If the session usage includes a graceful shutdown with messages being exchanged, the caller needs to take care of resuming reading the input in order to actually be able to carry on the conversation with the peer.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
writeBufferback to summary
public IoWriteFuture writeBuffer(Buffer buffer) throws IOException

Implements org.apache.sshd.common.io.IoSession.writeBuffer.

Doc from org.apache.sshd.common.io.IoSession.writeBuffer.

Write a packet on the socket. Multiple writes can be issued concurrently and will be queued.

Parameters
buffer:Buffer

the buffer send

Note

the buffer must not be touched until the returned write future is completed.

Returns:IoWriteFuture

An IoWriteFuture that can be used to check when the packet has actually been sent

Annotations
@Override
Exceptions
IOException:
if an error occurred when sending the packet