Skip to content

Commit

Permalink
Merge pull request #6117 from pferraro/WFCORE-6894
Browse files Browse the repository at this point in the history
WFCORE-6894 Extract interfaces from SuspendController appropriate for its consumers
  • Loading branch information
yersan authored Sep 10, 2024
2 parents ac36091 + e9919cf commit 386233c
Show file tree
Hide file tree
Showing 36 changed files with 977 additions and 834 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<module name="org.jboss.msc"/>
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.vfs" services="import"/>
<module name="org.wildfly.common"/>
<module name="org.wildfly.extension.core-management-client"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.service"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.server.suspend.OperationListener;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.wildfly.common.function.Functions;
import org.wildfly.extension.core.management.client.Process;
import org.wildfly.extension.core.management.client.Process.RunningState;
import org.wildfly.extension.core.management.client.RuntimeConfigurationStateChangeEvent;
Expand All @@ -57,7 +58,7 @@ public class ProcessStateListenerService implements Service {
static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("core", "management", "process-state-listener");

private final Supplier<ProcessStateNotifier> processStateNotifierSupplier;
private final Supplier<SuspendController> suspendControllerSupplier;
private final Supplier<ServerSuspendController> suspendControllerSupplier;
private final Supplier<Executor> executorSupplier;
private final PropertyChangeListener propertyChangeListener;
private final OperationListener operationListener;
Expand All @@ -72,7 +73,7 @@ public class ProcessStateListenerService implements Service {

private ProcessStateListenerService(ProcessType processType, RunningMode runningMode, String name, ProcessStateListener listener, Map<String, String> properties, int timeout,
final Supplier<ProcessStateNotifier> processStateNotifierSupplier,
final Supplier<SuspendController> suspendControllerSupplier,
final Supplier<ServerSuspendController> suspendControllerSupplier,
final Supplier<Executor> executorSupplier
) {
CoreManagementLogger.ROOT_LOGGER.debugf("Initalizing ProcessStateListenerService with a running mode of %s", runningMode);
Expand Down Expand Up @@ -109,7 +110,7 @@ public void complete() {

@Override
public void cancelled() {
if(runningState == null || runningState == Process.RunningState.STARTING) {//gracefull startup
if (runningState == null || runningState == Process.RunningState.STARTING) {//gracefull startup
suspendTransition(Process.RunningState.STARTING, Process.RunningState.SUSPENDED);
}
switch (runningMode) {
Expand All @@ -121,10 +122,6 @@ public void cancelled() {
break;
}
}

@Override
public void timeout() {
}
};
} else {
operationListener = null;
Expand Down Expand Up @@ -241,8 +238,8 @@ static void install(CapabilityServiceTarget serviceTarget, ProcessType processTy
final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(PROCESS_STATE_LISTENER_CAPABILITY.fromBaseCapability(listenerName));
final Supplier<ProcessStateNotifier> psnSupplier = builder.requires(ProcessStateNotifier.SERVICE_DESCRIPTOR);
final Supplier<Executor> esSupplier = builder.requires(Capabilities.MANAGEMENT_EXECUTOR);
final Supplier<SuspendController> scSupplier = !processType.isHostController() ? builder.requiresCapability("org.wildfly.server.suspend-controller", SuspendController.class) : null;
builder.setInstance(new ProcessStateListenerService(processType, runningMode, listenerName, listener, properties, timeout, psnSupplier, scSupplier, esSupplier));
final Supplier<ServerSuspendController> suspendController = !processType.isHostController() ? builder.requires(ServerSuspendController.SERVICE_DESCRIPTOR) : Functions.constantSupplier(null);
builder.setInstance(new ProcessStateListenerService(processType, runningMode, listenerName, listener, properties, timeout, psnSupplier, suspendController, esSupplier));
builder.install();
}

Expand All @@ -258,8 +255,7 @@ public void start(StartContext context) {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(currentTccl);
}
processStateNotifierSupplier.get().addPropertyChangeListener(propertyChangeListener);
final Supplier<SuspendController> suspendControllerSupplier = ProcessStateListenerService.this.suspendControllerSupplier;
SuspendController controller = suspendControllerSupplier != null ? suspendControllerSupplier.get() : null;
ServerSuspendController controller = ProcessStateListenerService.this.suspendControllerSupplier.get();
if (controller != null) {
controller.addListener(operationListener);
CoreManagementLogger.ROOT_LOGGER.debugf("Starting ProcessStateListenerService with a SuspendControllerState %s", controller.getState());
Expand Down Expand Up @@ -321,7 +317,7 @@ public void stop(StopContext context) {
Runnable asyncStop = () -> {
synchronized (stopLock) {
processStateNotifierSupplier.get().removePropertyChangeListener(propertyChangeListener);
SuspendController controller = suspendControllerSupplier != null ? suspendControllerSupplier.get() : null;
ServerSuspendController controller = ProcessStateListenerService.this.suspendControllerSupplier.get();
if (controller != null) {
controller.removeListener(operationListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.jboss.as.server.ServerPathManagerService;
import org.jboss.as.server.controller.resources.ServerRootResourceDefinition;
import org.jboss.as.server.controller.resources.VersionModelInitializer;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.version.ProductConfig;
import org.jboss.as.version.Version;
import org.jboss.dmr.ModelNode;
Expand Down Expand Up @@ -407,7 +408,7 @@ public void setRootResourceDefinitionDelegate() {
securityIdentitySupplier,
AuditLogger.NO_OP_LOGGER,
getMutableRootResourceRegistrationProvider(),
getBootErrorCollector(), capabilityRegistry));
getBootErrorCollector(), capabilityRegistry, new SuspendController()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
hostRegistration.registerReadOnlyAttribute(HostResourceDefinition.RUNTIME_CONFIGURATION_STATE, new ProcessStateAttributeHandler(processState));
hostRegistration.registerReadOnlyAttribute(HostResourceDefinition.HOST_STATE, new ProcessStateAttributeHandler(processState));
hostRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.RUNNING_MODE, new RunningModeReadHandler(runningModeControl));
hostRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.SUSPEND_STATE, SuspendStateReadHandler.INSTANCE);
hostRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.SUSPEND_STATE, new SuspendStateReadHandler(null));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.as.server.suspend.ServerActivityCallback;

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

/**
Expand All @@ -26,7 +28,7 @@
public class ControlPoint {

private static final AtomicIntegerFieldUpdater<ControlPoint> activeRequestCountUpdater = AtomicIntegerFieldUpdater.newUpdater(ControlPoint.class, "activeRequestCount");
private static final AtomicReferenceFieldUpdater<ControlPoint, ServerActivityCallback> listenerUpdater = AtomicReferenceFieldUpdater.newUpdater(ControlPoint.class, ServerActivityCallback.class, "listener");
private static final AtomicReferenceFieldUpdater<ControlPoint, CompletableFuture> pauseUpdater = AtomicReferenceFieldUpdater.newUpdater(ControlPoint.class, CompletableFuture.class, "pauseFuture");

private final RequestController controller;
private final String deployment;
Expand All @@ -45,7 +47,7 @@ public class ControlPoint {
private volatile boolean paused = false;

@SuppressWarnings("unused")
private volatile ServerActivityCallback listener = null;
private volatile CompletableFuture<Void> pauseFuture = null;

/**
* The number of services that are using this entry point.
Expand All @@ -69,33 +71,47 @@ public String getDeployment() {
}

/**
* Pause the current entry point, and invoke the provided listener when all current requests have finished.
*
* If individual control point tracking is not enabled then the listener will be invoked straight away
* Pause the current entry point returning a stage that completes when all current requests have completed.
*
* @param requestCountListener The listener to invoke
* If individual control point tracking is not enabled then a completed stage is returned.
*/
public void pause(ServerActivityCallback requestCountListener) {
public CompletionStage<Void> pause() {
if (paused) {
throw ServerLogger.ROOT_LOGGER.serverAlreadyPaused();
}
this.paused = true;
listenerUpdater.set(this, requestCountListener);
CompletableFuture<Void> pause = new CompletableFuture<>();
pauseUpdater.set(this, pause);
if (activeRequestCountUpdater.get(this) == 0) {
if (listenerUpdater.compareAndSet(this, requestCountListener, null)) {
requestCountListener.done();
if (pauseUpdater.compareAndSet(this, pause, null)) {
pause.complete(null);
}
}
return pause;
}

/**
* Pause the current entry point, and invoke the provided listener when all current requests have finished.
*
* If individual control point tracking is not enabled then the listener will be invoked straight away
*
* @param requestCountListener The listener to invoke
* @deprecated Superseded by {@link #pause()}.
*/
@Deprecated(forRemoval = true)
public void pause(org.jboss.as.server.suspend.ServerActivityCallback requestCountListener) {
this.pause().whenComplete((ignore, exception) -> requestCountListener.done());
}

/**
* Cancel the pause operation
*/
public void resume() {
this.paused = false;
ServerActivityCallback listener = listenerUpdater.get(this);
if (listener != null) {
listenerUpdater.compareAndSet(this, listener, null);
CompletableFuture<Void> pause = pauseUpdater.get(this);
if (pause != null) {
pauseUpdater.compareAndSet(this, pause, null);
pause.cancel(false);
}
}

Expand Down Expand Up @@ -162,10 +178,10 @@ private void decreaseRequestCount() {
if (trackIndividualControlPoints) {
int result = activeRequestCountUpdater.decrementAndGet(this);
if (paused && result == 0) {
ServerActivityCallback listener = listenerUpdater.get(this);
if (listener != null) {
if (listenerUpdater.compareAndSet(this, listener, null)) {
listener.done();
CompletableFuture<Void> pause = pauseUpdater.get(this);
if (pause != null) {
if (pauseUpdater.compareAndSet(this, pause, null)) {
pause.complete(null);
}
}
}
Expand Down
Loading

0 comments on commit 386233c

Please sign in to comment.