Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFCORE-6894 Extract interfaces from SuspendController appropriate for its consumers #6117

Merged
merged 9 commits into from
Sep 10, 2024
7 changes: 3 additions & 4 deletions server/src/main/java/org/jboss/as/server/ServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import org.jboss.as.server.moduleservice.ExtensionIndexService;
import org.jboss.as.server.moduleservice.ExternalModule;
import org.jboss.as.server.moduleservice.ServiceModuleLoader;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
Expand Down Expand Up @@ -161,12 +162,10 @@ public final class ServerService extends AbstractControllerService {
private final SuspendController suspendController;
public static final String SERVER_NAME = "server";

static final String SUSPEND_CONTROLLER_CAPABILITY_NAME = "org.wildfly.server.suspend-controller";
static final String EXTERNAL_MODULE_CAPABILITY_NAME = "org.wildfly.management.external-module";

static final RuntimeCapability<Void> SUSPEND_CONTROLLER_CAPABILITY =
RuntimeCapability.Builder.of(SUSPEND_CONTROLLER_CAPABILITY_NAME, SuspendController.class)
.build();
// TODO Remove type narrowing as soon as references to the implementation class are dropped from WildFly
pferraro marked this conversation as resolved.
Show resolved Hide resolved
static final RuntimeCapability<Void> SUSPEND_CONTROLLER_CAPABILITY = RuntimeCapability.Builder.of(ServerSuspendController.SERVICE_DESCRIPTOR.asType(SuspendController.class)).build();

static final RuntimeCapability<Void> EXTERNAL_MODULE_CAPABILITY =
RuntimeCapability.Builder.of(EXTERNAL_MODULE_CAPABILITY_NAME, ExternalModule.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.deployment.module.ExtensionListEntry;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.server.suspend.ServerActivity;
import org.jboss.as.server.suspend.SuspendableActivity;
import org.jboss.as.version.Stability;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.logging.BasicLogger;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ public interface ServerLogger extends BasicLogger {

@LogMessage(level = ERROR)
@Message(id = 215, value = "Failed to resume activity %s. To resume normal operation it is recommended that you restart the server.")
void failedToResume(ServerActivity activity, @Cause Exception cause);
void failedToResume(SuspendableActivity activity, @Cause Throwable cause);

@LogMessage(level = ERROR)
@Message(id = 216, value = "Error cleaning obsolete content %s ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.as.server.suspend.OperationListener;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.server.suspend.SuspendController.State;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand Down Expand Up @@ -147,7 +146,7 @@ public void handleResult(OperationContext.ResultAction resultAction, OperationCo
//to stop new requests being accepted as it is shutting down
final ShutdownAction shutdown = new ShutdownAction(getOperationName(operation), restart, performInstallation);
final SuspendController suspendController = ServerShutdownHandler.this.suspendController;
if (suspendController.getState() == State.SUSPENDED) {
if (suspendController.getState() == SuspendController.State.SUSPENDED) {
// WFCORE-4935 if server is already in suspend, don't register any listener, just shut it down
shutdown.shutdown();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
* its delegate.
*
* @author Stuart Douglas
* @deprecated To be removed without replacement
*/
@Deprecated(forRemoval = true)
pferraro marked this conversation as resolved.
Show resolved Hide resolved
public class CountingRequestCountCallback implements ServerActivityCallback {

private final AtomicInteger count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@

package org.jboss.as.server.suspend;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

/**
* A server activity that may have to finish before the server can shut down gracefully.
*
* @author Stuart Douglas
* @deprecated Use {@link SuspendableActivity} instead.
*/
public interface ServerActivity {
@Deprecated(forRemoval = true)
pferraro marked this conversation as resolved.
Show resolved Hide resolved
public interface ServerActivity extends SuspendableActivity {

/**
* The lowest valid value to return from {@link #getExecutionGroup()}.
*/
@SuppressWarnings("unused")
int LOWEST_EXECUTION_GROUP = 1;
int LOWEST_EXECUTION_GROUP = SuspendableActivityRegistry.SuspendPriority.FIRST.ordinal();
/**
* The default value returned from {@link #getExecutionGroup()}. Implementations should use this
* unless there is a clear reason to use a different value.
*/
int DEFAULT_EXECUTION_GROUP = 5;
int DEFAULT_EXECUTION_GROUP = SuspendableActivityRegistry.SuspendPriority.DEFAULT.ordinal();
/**
* The highest valid value to return from {@link #getExecutionGroup()}.
*/
@SuppressWarnings("unused")
int HIGHEST_EXECUTION_GROUP = 10;
int HIGHEST_EXECUTION_GROUP = SuspendableActivityRegistry.SuspendPriority.LAST.ordinal();

/**
* Returns a value that indicates to which set of {@code ServerActivity} instances
* {@link SuspendController#registerActivity(ServerActivity) registered} with the {@link SuspendController}
* {@link ServerActivityRegistry#addServerActivity(ServerActivity) registered} with the {@link ServerActivityRegistry}
* this activity should belong. All {@code ServerActivity} instances with the same execution group value have their
* {@link #preSuspend(ServerActivityCallback) preSuspend}, {@link #suspended(ServerActivityCallback) suspended}
* and {@link #resume() resume} methods invoked separately from activities with different execution group values.
Expand Down Expand Up @@ -78,4 +83,37 @@ default int getExecutionGroup() {
*/
void resume();

@Override
default CompletionStage<Void> prepare(ServerSuspendContext context) {
CompletableFuture<Void> future = new CompletableFuture<>();
try {
this.preSuspend(() -> future.complete(null));
} catch (Throwable e) {
future.completeExceptionally(e);
}
return future;
}

@Override
default CompletionStage<Void> suspend(ServerSuspendContext context) {
CompletableFuture<Void> future = new CompletableFuture<>();
try {
this.suspended(() -> future.complete(null));
} catch (Throwable e) {
future.completeExceptionally(e);
}
return future;
}

@Override
default CompletionStage<Void> resume(ServerResumeContext context) {
CompletableFuture<Void> future = new CompletableFuture<>();
try {
this.resume();
future.complete(null);
} catch (Throwable e) {
future.completeExceptionally(e);
}
return future;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* suspend controller know that all requests have finished.
*
* @author Stuart Douglas
* @deprecated To be removed without replacement.
*/
@Deprecated(forRemoval = true)
pferraro marked this conversation as resolved.
Show resolved Hide resolved
public interface ServerActivityCallback {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.server.suspend;

/**
* A context for server resume handling.
*/
public interface ServerResumeContext {
/**
* Indicates whether the server is resuming as part of the startup sequence.
* @return true, if the server is starting, false otherwise.
*/
boolean isStarting();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.server.suspend;

/**
* A context for server suspend handling.
*/
public interface ServerSuspendContext extends ServerResumeContext {
/**
* Indicates whether the server is suspending as part of the shutdown sequence.
* @return true, if the server is stopping, false otherwise.
*/
boolean isStopping();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.server.suspend;

import java.util.concurrent.CompletionStage;

import org.wildfly.service.descriptor.NullaryServiceDescriptor;

public interface ServerSuspendController extends SuspensionStateProvider {
NullaryServiceDescriptor<ServerSuspendController> SERVICE_DESCRIPTOR = SuspensionStateProvider.SERVICE_DESCRIPTOR.asType(ServerSuspendController.class);

enum Context implements ServerSuspendContext {
STARTUP(true, false),
RUNNING(false, false),
SHUTDOWN(false, true),
;
private final boolean starting;
private final boolean stopping;

Context(boolean starting, boolean stopping) {
this.starting = starting;
this.stopping = stopping;
}

@Override
public boolean isStarting() {
return this.starting;
}

@Override
public boolean isStopping() {
return this.stopping;
}
}

/**
* Suspends all registered activity and Transitions the controller from {@link State#RUNNING} to {@link State#SUSPENDED} via the intermediate states: {@link State#PRE_SUSPEND} and {@link State#SUSPENDING}
* @return a completion stage that completes after {@link SuspendableActivity#prepare(ServerSuspendContext)} completion, followed by {@link SuspendableActivity#suspend(ServerSuspendContext)} completion for all registered activity.
*/
CompletionStage<Void> suspend(ServerSuspendContext context);

/**
* Resumes all registered activity and transitions the controller from {@link State#SUSPENDED} to {@link State#RUNNING}.
* @return a stage that will complete after {@link SuspendableActivity#cancel(ServerSuspendCancelContext)} completion for all registered activity.
*/
CompletionStage<Void> resume(ServerResumeContext context);

/**
* Resets the state of the suspend controller to {@link State#SUSPENDED}.
*/
void reset();

/**
* Adds the specified server suspension event listener to this controller.
* @param listener a server suspension event listener
*/
void addListener(OperationListener listener);

/**
* Removes the specified server suspension event listener from this controller.
* @param listener a server suspension event listener
*/
void removeListener(OperationListener listener);
}
Loading