Skip to content

Commit

Permalink
[SSHD-1338] Restore binary compatibility with 2.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 29, 2024
1 parent 44a0b1b commit 8744f06
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum CancelOption {
/**
* Indicates that even if waiting on a future times out or is interrupted, it shall not be canceled.
* <p>
* {@link #CANCEL_ON_TIMEOUT} and {@link #CANCEL_ON_INTERRUPT} take predence over this flag. The main purpose of
* {@link #CANCEL_ON_TIMEOUT} and {@link #CANCEL_ON_INTERRUPT} take precedence over this flag. The main purpose of
* this flag is to be able to call {@code verify(timeout, NO_CANCELLATION)} to suppress cancelling a future on
* time-outs or interrupts altogether. By default, {@code verify(timeout)} will cancel the future on both time-outs
* and interrupts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
*/
@FunctionalInterface
public interface VerifiableFuture<T> {
/**
* Wait {@link Long#MAX_VALUE} msec. and verify that the operation was successful
*
* @return The (same) future instance
* @throws IOException If failed to verify successfully on time
* @see #verify(long, CancelOption[])
*/
default T verify() throws IOException {
return verify(Long.MAX_VALUE, new CancelOption[0]);
}

/**
* Wait {@link Long#MAX_VALUE} msec. and verify that the operation was successful
*
Expand All @@ -45,6 +56,19 @@ default T verify(CancelOption... options) throws IOException {
return verify(Long.MAX_VALUE, options);
}

/**
* Wait and verify that the operation was successful
*
* @param timeout The number of time units to wait
* @param unit The wait {@link TimeUnit}
* @return The (same) future instance
* @throws IOException If failed to verify successfully on time
* @see #verify(long, CancelOption[])
*/
default T verify(long timeout, TimeUnit unit) throws IOException {
return verify(timeout, unit, new CancelOption[0]);
}

/**
* Wait and verify that the operation was successful
*
Expand All @@ -60,6 +84,18 @@ default T verify(long timeout, TimeUnit unit, CancelOption... options) throws IO
return verify(unit.toMillis(timeout), options);
}

/**
* Wait and verify that the operation was successful
*
* @param timeout The maximum duration to wait, <code>null</code> to wait forever
* @return The (same) future instance
* @throws IOException If failed to verify successfully on time
* @see #verify(long, CancelOption[])
*/
default T verify(Duration timeout) throws IOException {
return verify(timeout, new CancelOption[0]);
}

/**
* Wait and verify that the operation was successful
*
Expand All @@ -74,6 +110,17 @@ default T verify(Duration timeout, CancelOption... options) throws IOException {
return timeout != null ? verify(timeout.toMillis(), options) : verify(options);
}

/**
* Wait and verify that the operation was successful
*
* @param timeoutMillis Wait timeout in milliseconds
* @return The (same) future instance
* @throws IOException If failed to verify successfully on time
*/
default T verify(long timeoutMillis) throws IOException {
return verify(timeoutMillis, new CancelOption[0]);
}

/**
* Wait and verify that the operation was successful
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public interface WaitableFuture {
*/
Object getId();

/**
* Wait {@link Long#MAX_VALUE} msec. for the asynchronous operation to complete. The attached listeners will be
* notified when the operation is completed.
*
* @return {@code true} if the operation is completed.
* @throws IOException if failed - specifically {@link java.io.InterruptedIOException} if waiting was interrupted
* @see #await(long, CancelOption[])
*/
default boolean await() throws IOException {
return await(new CancelOption[0]);
}

/**
* Wait {@link Long#MAX_VALUE} msec. for the asynchronous operation to complete. The attached listeners will be
* notified when the operation is completed.
Expand All @@ -50,6 +62,19 @@ default boolean await(CancelOption... options) throws IOException {
return await(Long.MAX_VALUE, options);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout.
*
* @param timeout The number of time units to wait
* @param unit The {@link TimeUnit} for waiting
* @return {@code true} if the operation is completed.
* @throws IOException if failed - specifically {@link java.io.InterruptedIOException} if waiting was interrupted
* @see #await(long, CancelOption[])
*/
default boolean await(long timeout, TimeUnit unit) throws IOException {
return await(timeout, unit, new CancelOption[0]);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout.
*
Expand All @@ -65,6 +90,18 @@ default boolean await(long timeout, TimeUnit unit, CancelOption... options) thro
return await(unit.toMillis(timeout), options);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout.
*
* @param timeout The maximum duration to wait, <code>null</code> to wait forever
* @return {@code true} if the operation is completed.
* @throws IOException if failed - specifically {@link java.io.InterruptedIOException} if waiting was interrupted
* @see #await(long, CancelOption[])
*/
default boolean await(Duration timeout) throws IOException {
return await(timeout, new CancelOption[0]);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout.
*
Expand All @@ -79,6 +116,17 @@ default boolean await(Duration timeout, CancelOption... options) throws IOExcept
return timeout != null ? await(timeout.toMillis(), options) : await(options);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout.
*
* @param timeoutMillis Wait time in milliseconds
* @return {@code true} if the operation is completed.
* @throws IOException if failed - specifically {@link java.io.InterruptedIOException} if waiting was interrupted
*/
default boolean await(long timeoutMillis) throws IOException {
return await(timeoutMillis, new CancelOption[0]);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout.
*
Expand All @@ -90,6 +138,17 @@ default boolean await(Duration timeout, CancelOption... options) throws IOExcept
*/
boolean await(long timeoutMillis, CancelOption... options) throws IOException;

/**
* Wait {@link Long#MAX_VALUE} msec. for the asynchronous operation to complete uninterruptibly. The attached
* listeners will be notified when the operation is completed.
*
* @return {@code true} if the operation is completed.
* @see #awaitUninterruptibly(long, CancelOption[])
*/
default boolean awaitUninterruptibly() {
return awaitUninterruptibly(new CancelOption[0]);
}

/**
* Wait {@link Long#MAX_VALUE} msec. for the asynchronous operation to complete uninterruptibly. The attached
* listeners will be notified when the operation is completed.
Expand All @@ -103,6 +162,18 @@ default boolean awaitUninterruptibly(CancelOption... options) {
return awaitUninterruptibly(Long.MAX_VALUE, options);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
*
* @param timeout The number of time units to wait
* @param unit The {@link TimeUnit} for waiting
* @return {@code true} if the operation is completed.
* @see #awaitUninterruptibly(long, CancelOption[])
*/
default boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
return awaitUninterruptibly(timeout, unit, new CancelOption[0]);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
*
Expand All @@ -117,6 +188,16 @@ default boolean awaitUninterruptibly(long timeout, TimeUnit unit, CancelOption..
return awaitUninterruptibly(unit.toMillis(timeout), options);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
*
* @param timeoutMillis Wait time, <code>null</code> to wait forever
* @return {@code true} if the operation is finished.
*/
default boolean awaitUninterruptibly(Duration timeoutMillis) {
return awaitUninterruptibly(timeoutMillis, new CancelOption[0]);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
*
Expand All @@ -129,6 +210,16 @@ default boolean awaitUninterruptibly(Duration timeoutMillis, CancelOption... opt
return timeoutMillis != null ? awaitUninterruptibly(timeoutMillis.toMillis(), options) : awaitUninterruptibly(options);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
*
* @param timeoutMillis Wait time in milliseconds
* @return {@code true} if the operation is finished.
*/
default boolean awaitUninterruptibly(long timeoutMillis) {
return awaitUninterruptibly(timeoutMillis, new CancelOption[0]);
}

/**
* Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
*
Expand Down

0 comments on commit 8744f06

Please sign in to comment.