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 specializedSshFutureListener
that 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 ClientChannel
clientChannel
protected DefaultOpenFuture
completedFuture
private java.util.concurrent.atomic.AtomicBoolean
open
protected 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 int
clearPendingQueue()
void
close()
protected void
flushPendingQueue()
ClientChannel
getClientChannel()
OpenFuture
getCompletedFuture()
int
handleIncomingMessage(Buffer buffer, java.util.function.Consumer<? super java.lang.Throwable> errHandler)
Checks if the future is already open and manages the message handling accordingly:boolean
isOpen()
protected boolean
markClosed()
Marks the queue as closedprotected OpenFuture
markCompletionException(java.lang.Throwable err)
protected OpenFuture
markCompletionSuccessful()
void
operationComplete(OpenFuture future)
Invoked when the operation associated with theSshFuture
has been completed even if you add the listener after the completion.java.lang.String
toString()
protected void
writeMessage(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:
getClientChannel
in interfaceClientChannelHolder
- Returns:
- The underlying
ClientChannel
used
-
getCompletedFuture
public OpenFuture getCompletedFuture()
- Returns:
- An internal
OpenFuture
that 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:
isOpen
in interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
markClosed
protected boolean markClosed()
Marks the queue as closed- Returns:
true
if 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 messageBuffer
errHandler
- The error handler to invoke it had to enqueue the message and was unsuccessful in writing it. Must be non-null
if future not open yet. Otherwise, ifnull
and 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:SshFutureListener
Invoked when the operation associated with theSshFuture
has been completed even if you add the listener after the completion.- Specified by:
operationComplete
in interfaceSshFutureListener<OpenFuture>
- Parameters:
future
- The sourceSshFuture
which 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:
toString
in classjava.lang.Object
-
-