public class ClientChannelPendingMessagesQueue extends AbstractLoggingBean implements SshFutureListener<OpenFuture>, java.nio.channels.Channel, ClientChannelHolder
SshFutureListener
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.Modifier and Type | Field and 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 |
log
Constructor and Description |
---|
ClientChannelPendingMessagesQueue(ClientChannel channel) |
Modifier and Type | Method and 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 closed
|
protected OpenFuture |
markCompletionException(java.lang.Throwable err) |
protected OpenFuture |
markCompletionSuccessful() |
void |
operationComplete(OpenFuture future)
Invoked when the operation associated with the
SshFuture 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) |
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
validateListener
getChannel
protected final java.util.Deque<java.util.Map.Entry<Buffer,java.util.function.Consumer<? super java.lang.Throwable>>> pendingQueue
protected final DefaultOpenFuture completedFuture
private final ClientChannel clientChannel
private final java.util.concurrent.atomic.AtomicBoolean open
public ClientChannelPendingMessagesQueue(ClientChannel channel)
public ClientChannel getClientChannel()
getClientChannel
in interface ClientChannelHolder
ClientChannel
usedpublic OpenFuture getCompletedFuture()
OpenFuture
that can be used to wait for all internal pending messages to be flushed
before actually signaling that operation is completepublic boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
protected boolean markClosed()
true
if was open and now is closedpublic int handleIncomingMessage(Buffer buffer, java.util.function.Consumer<? super java.lang.Throwable> errHandler) throws java.io.IOException
buffer
- The message Buffer
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, if null
and exception
occurs it will be simple re-thrownjava.io.IOException
- If wrote the message directly, encountered an error and no handler was provided.protected void writeMessage(Buffer buffer, java.util.function.Consumer<? super java.io.IOException> errHandler) throws java.io.IOException
java.io.IOException
public void operationComplete(OpenFuture future)
SshFutureListener
SshFuture
has been completed even if you add the listener
after the completion.operationComplete
in interface SshFutureListener<OpenFuture>
future
- The source SshFuture
which called this callback.protected void flushPendingQueue()
protected OpenFuture markCompletionSuccessful()
protected OpenFuture markCompletionException(java.lang.Throwable err)
protected int clearPendingQueue()
public java.lang.String toString()
toString
in class java.lang.Object