Package org.apache.sshd.client.channel
Class ClientChannelPendingMessagesQueue
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.client.channel.ClientChannelPendingMessagesQueue
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.util.EventListener,ClientChannelHolder,ChannelHolder,SshFutureListener<OpenFuture>,SshdEventListener
public class ClientChannelPendingMessagesQueue extends AbstractLoggingBean implements SshFutureListener<OpenFuture>, java.nio.channels.Channel, ClientChannelHolder
This is a specializedSshFutureListenerthat is used to enqueue data that is sent while the channel is being set-up, so that when it is established it will send them in the same order as they have been received. It also serves as a "backstop" in case session is closed (normally) while the packets as still being written.
-
-
Field Summary
Fields Modifier and Type Field Description private ClientChannelclientChannelprotected DefaultOpenFuturecompletedFutureprivate java.util.concurrent.atomic.AtomicBooleanopenprotected java.util.Deque<java.util.Map.Entry<Buffer,java.util.function.Consumer<? super java.lang.Throwable>>>pendingQueue-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ClientChannelPendingMessagesQueue(ClientChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intclearPendingQueue()voidclose()protected voidflushPendingQueue()ClientChannelgetClientChannel()OpenFuturegetCompletedFuture()inthandleIncomingMessage(Buffer buffer, java.util.function.Consumer<? super java.lang.Throwable> errHandler)Checks if the future is already open and manages the message handling accordingly:booleanisOpen()protected booleanmarkClosed()Marks the queue as closedprotected OpenFuturemarkCompletionException(java.lang.Throwable err)protected OpenFuturemarkCompletionSuccessful()voidoperationComplete(OpenFuture future)Invoked when the operation associated with theSshFuturehas been completed even if you add the listener after the completion.java.lang.StringtoString()protected voidwriteMessage(Buffer buffer, java.util.function.Consumer<? super java.io.IOException> errHandler)-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.client.channel.ClientChannelHolder
getChannel
-
-
-
-
Field Detail
-
pendingQueue
protected final java.util.Deque<java.util.Map.Entry<Buffer,java.util.function.Consumer<? super java.lang.Throwable>>> pendingQueue
-
completedFuture
protected final DefaultOpenFuture completedFuture
-
clientChannel
private final ClientChannel clientChannel
-
open
private final java.util.concurrent.atomic.AtomicBoolean open
-
-
Constructor Detail
-
ClientChannelPendingMessagesQueue
public ClientChannelPendingMessagesQueue(ClientChannel channel)
-
-
Method Detail
-
getClientChannel
public ClientChannel getClientChannel()
- Specified by:
getClientChannelin interfaceClientChannelHolder- Returns:
- The underlying
ClientChannelused
-
getCompletedFuture
public OpenFuture getCompletedFuture()
- Returns:
- An internal
OpenFuturethat can be used to wait for all internal pending messages to be flushed before actually signaling that operation is complete
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
markClosed
protected boolean markClosed()
Marks the queue as closed- Returns:
trueif was open and now is closed
-
handleIncomingMessage
public int handleIncomingMessage(Buffer buffer, java.util.function.Consumer<? super java.lang.Throwable> errHandler) throws java.io.IOException
Checks if the future is already open and manages the message handling accordingly:- If channel is not open yet, it enqueues the request
- If channel is open but there are still pending messages not yet written out, it will wait for them to be written (or exception signaled) before proceeding to write out the incoming message.
- Otherwise (i.e., channel is open and no pending messages yet) it will write the message to the underlying channel immediately.
- Parameters:
buffer- The messageBuffererrHandler- The error handler to invoke it had to enqueue the message and was unsuccessful in writing it. Must be non-nullif future not open yet. Otherwise, ifnulland exception occurs it will be simple re-thrown- Returns:
- The total number of still pending messages - zero if none and message was written (either immediately or after waiting for the pending ones to be written).
- Throws:
java.io.IOException- If wrote the message directly, encountered an error and no handler was provided.
-
writeMessage
protected void writeMessage(Buffer buffer, java.util.function.Consumer<? super java.io.IOException> errHandler) throws java.io.IOException
- Throws:
java.io.IOException
-
operationComplete
public void operationComplete(OpenFuture future)
Description copied from interface:SshFutureListenerInvoked when the operation associated with theSshFuturehas been completed even if you add the listener after the completion.- Specified by:
operationCompletein interfaceSshFutureListener<OpenFuture>- Parameters:
future- The sourceSshFuturewhich called this callback.
-
flushPendingQueue
protected void flushPendingQueue()
-
markCompletionSuccessful
protected OpenFuture markCompletionSuccessful()
-
markCompletionException
protected OpenFuture markCompletionException(java.lang.Throwable err)
-
clearPendingQueue
protected int clearPendingQueue()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-