Skip to content

Commit

Permalink
Deprecate OperationListener.timeout(), as this is no longer serves an…
Browse files Browse the repository at this point in the history
…y purpose.
  • Loading branch information
pferraro committed Aug 2, 2024
1 parent 870ccbc commit 6fff591
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ public void cancelled() {
break;
}
}

@Override
public void timeout() {
}
};
} else {
operationListener = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private void suspend(ServiceContainer sc) {
CompletableFuture<Void> suspend = suspendController.suspend(ServerSuspendController.Context.SHUTDOWN).toCompletableFuture();
if (timeoutSeconds >= 0) {
// If necessary we'll wait 500 ms longer for it in the off chance a gc or something delays things
suspend = suspend.orTimeout(TimeUnit.MILLISECONDS.convert(timeoutSeconds, TimeUnit.SECONDS) + 500, TimeUnit.MILLISECONDS);
suspend.completeOnTimeout(null, TimeUnit.MILLISECONDS.convert(timeoutSeconds, TimeUnit.SECONDS) + 500, TimeUnit.MILLISECONDS);
}
suspend.join();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ public void cancelled() {
mbean.setRunningState(mbean.getRunningState(), RunningState.ADMIN_ONLY);
}
}

@Override
public void timeout() {
}
});
} else {
mbean.setRunningState(null, RunningState.STARTING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void handleResult(OperationContext.ResultAction resultAction, OperationCo
//to stop new requests being accepted as it is shutting down

CompletionStage<Void> suspend = ServerDomainProcessShutdownHandler.this.suspendController.suspend(ServerSuspendController.Context.SHUTDOWN);
SUSPEND_STAGE.set((seconds >= 0) ? suspend.toCompletableFuture().orTimeout(seconds, TimeUnit.SECONDS) : suspend);
SUSPEND_STAGE.set((seconds >= 0) ? suspend.toCompletableFuture().completeOnTimeout(null, seconds, TimeUnit.SECONDS) : suspend);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void handleResult(OperationContext.ResultAction resultAction, OperationCo
final ServerSuspendController suspendController = ServerShutdownHandler.this.suspendController;
CompletableFuture<Void> suspend = suspendController.suspend(ServerSuspendController.Context.SHUTDOWN).toCompletableFuture();
if (seconds >= 0) {
suspend = suspend.orTimeout(seconds, TimeUnit.SECONDS);
suspend.completeOnTimeout(null, seconds, TimeUnit.SECONDS);
}
try {
suspend.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void execute(final OperationContext context, ModelNode operation) throws
final ServerSuspendController suspendController = ServerSuspendHandler.this.suspendController;
CompletableFuture<Void> suspend = suspendController.suspend(ServerSuspendController.Context.RUNNING).toCompletableFuture();
if (seconds >= 0) {
suspend = suspend.orTimeout(seconds, TimeUnit.SECONDS);
suspend.completeOnTimeout(null, seconds, TimeUnit.SECONDS);
}
try {
suspend.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public interface OperationListener {

/**
* Invoked when a suspend operation times out.
* @deprecated This event is no longer emitted.
*/
void timeout();

@Deprecated(forRemoval = true)
default void timeout() {
// Do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import java.util.ListIterator;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -90,27 +88,7 @@ public CompletionStage<Void> suspend(ServerSuspendContext context) {
for (OperationListener listener: this.listeners) {
listener.suspendStarted();
}
// Handle TimeoutException by triggering listener
BiFunction<Void, Throwable, Void> timeoutHandler = (ignore, exception) -> {
if (exception != null) {
if (exception instanceof TimeoutException) {
for (OperationListener listener: this.listeners) {
listener.timeout();
}
return null;
}
// Don't re-wrap CompletionException/CancellationException
throw (exception instanceof RuntimeException) ? (RuntimeException) exception : new CompletionException(exception);
}
return null;
};
CompletableFuture<Void> result = new CompletableFuture<>() {
@Override
public CompletableFuture<Void> orTimeout(long timeout, TimeUnit unit) {
// Redirect timeout exceptions to ServerSuspendListener
return super.orTimeout(timeout, unit).handle(timeoutHandler);
}
};
CompletableFuture<Void> result = new CompletableFuture<>();
// Prepare activity groups in priority order, i.e. first -> last
this.phaseStage(this.activityGroups, SuspendableActivity::prepare, context, Functions.discardingBiConsumer()).whenComplete((ignored, prepareException) -> {
if (prepareException != null) {
Expand Down Expand Up @@ -235,7 +213,7 @@ public void resume() {
}

/**
* @deprecated Superseded by {@link #suspend(ServerSuspendContext)} using {@link CompletableFuture#orTimeout(Object, long, TimeUnit)}.
* @deprecated Superseded by {@link #suspend(ServerSuspendContext)} using {@link CompletableFuture#completeOnTimeout(Object, long, TimeUnit)}.
*/
@Deprecated(forRemoval = true)
public void suspend(long timeoutMillis) {
Expand All @@ -248,7 +226,7 @@ public void suspend(long timeoutMillis) {
}
CompletableFuture<Void> suspend = this.suspend(Context.RUNNING).toCompletableFuture();
if (timeoutMillis >= 0) {
suspend.orTimeout(timeoutMillis, TimeUnit.MILLISECONDS);
suspend.completeOnTimeout(null, timeoutMillis, TimeUnit.MILLISECONDS);
}
suspend.join();
}
Expand Down

0 comments on commit 6fff591

Please sign in to comment.