Package org.apache.sshd.common.io
Interface IoSession
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.nio.channels.Channel
,java.io.Closeable
,Closeable
,ConnectionEndpointsIndicator
- All Known Implementing Classes:
Nio2Session
public interface IoSession extends ConnectionEndpointsIndicator, Closeable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CloseFuture
close(boolean immediately)
Closes this session immediately or after all queued write requests are flushed.java.net.SocketAddress
getAcceptanceAddress()
java.lang.Object
getAttribute(java.lang.Object key)
Returns the value of the user-defined attribute of this session.long
getId()
IoService
getService()
java.lang.Object
removeAttribute(java.lang.Object key)
Removes a user-defined attribute with the specified key.void
resumeRead()
Resume read operations on this session.java.lang.Object
setAttribute(java.lang.Object key, java.lang.Object value)
Sets a user-defined attribute.java.lang.Object
setAttributeIfAbsent(java.lang.Object key, java.lang.Object value)
Sets a user defined attribute if the attribute with the specified key is not set yet.void
shutdownOutputStream()
Handle received EOF.void
suspendRead()
Suspend read operations on this session.IoWriteFuture
writeBuffer(Buffer buffer)
Write a packet on the socket.-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.util.net.ConnectionEndpointsIndicator
getLocalAddress, getRemoteAddress
-
-
-
-
Method Detail
-
getId
long getId()
- Returns:
- a unique identifier for this session. Every session has its own ID which is different from any other.
-
getAcceptanceAddress
java.net.SocketAddress getAcceptanceAddress()
- Returns:
- The service address through which this session was accepted -
null
if session was initiated by this peer instead of being accepted
-
getAttribute
java.lang.Object getAttribute(java.lang.Object key)
Returns the value of the user-defined attribute of this session.- Parameters:
key
- the key of the attribute- Returns:
null
if there is no attribute with the specified key
-
setAttribute
java.lang.Object setAttribute(java.lang.Object key, java.lang.Object value)
Sets a user-defined attribute.- Parameters:
key
- the key of the attributevalue
- the value of the attribute- Returns:
- The old value of the attribute -
null
if it is new.
-
setAttributeIfAbsent
java.lang.Object setAttributeIfAbsent(java.lang.Object key, java.lang.Object value)
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
- The key of the attribute we want to setvalue
- The value we want to set- Returns:
- The old value of the attribute -
null
if not found.
-
removeAttribute
java.lang.Object removeAttribute(java.lang.Object key)
Removes a user-defined attribute with the specified key.- Parameters:
key
- The key of the attribute we want to remove- Returns:
- The old value of the attribute -
null
if not found.
-
writeBuffer
IoWriteFuture writeBuffer(Buffer buffer) throws java.io.IOException
Write a packet on the socket. Multiple writes can be issued concurrently and will be queued.- Parameters:
buffer
- the buffer send. NOTE: the buffer must not be touched until the returned write future is completed.- Returns:
- An
IoWriteFuture
that can be used to check when the packet has actually been sent - Throws:
java.io.IOException
- if an error occurred when sending the packet
-
close
CloseFuture close(boolean immediately)
Closes this session immediately or after all queued write requests are flushed. This operation is asynchronous. Wait for the returnedCloseFuture
if you want to wait for the session actually closed.- Specified by:
close
in interfaceCloseable
- Parameters:
immediately
-true
to close this session immediately. The pending write requests will simply be discarded.false
to close this session after all queued write requests are flushed.- Returns:
- The generated
CloseFuture
-
shutdownOutputStream
void shutdownOutputStream() throws java.io.IOException
Handle received EOF.- Throws:
java.io.IOException
- If failed to shutdown the stream
-
suspendRead
void 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.
-
resumeRead
void resumeRead()
Resume read operations on this session.
-
-