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:
Closeable,AutoCloseable,Channel,EventListener,ClientChannelHolder,ChannelHolder,SshFutureListener<OpenFuture>,SshdEventListener
public class ClientChannelPendingMessagesQueue extends AbstractLoggingBean implements SshFutureListener<OpenFuture>, 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.- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected DefaultOpenFuturecompletedFutureprotected Deque<Map.Entry<Buffer,Consumer<? super 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, Consumer<? super Throwable> errHandler)Checks if the future is already open and manages the message handling accordingly:booleanisOpen()protected booleanmarkClosed()Marks the queue as closedprotected OpenFuturemarkCompletionException(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.StringtoString()protected voidwriteMessage(Buffer buffer, Consumer<? super 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
-
-
-
-
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
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
markClosed
protected boolean markClosed()
Marks the queue as closed- Returns:
trueif was open and now is closed
-
handleIncomingMessage
public int handleIncomingMessage(Buffer buffer, Consumer<? super Throwable> errHandler) throws 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:
IOException- If wrote the message directly, encountered an error and no handler was provided.
-
writeMessage
protected void writeMessage(Buffer buffer, Consumer<? super IOException> errHandler) throws IOException
- Throws:
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(Throwable err)
-
clearPendingQueue
protected int clearPendingQueue()
-
-