Skip to content

Commit

Permalink
Merge pull request #66 from jamezp/issue65
Browse files Browse the repository at this point in the history
[65] Do not attempt to shut down more than once.
  • Loading branch information
jamezp authored Aug 7, 2024
2 parents 1afce2a + 402175e commit f6a9eff
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract class AbstractServerManager<T extends ModelControllerClient> implements
private final boolean shutdownOnClose;
private final DeploymentManager deploymentManager;
private final AtomicBoolean closed;
private final AtomicBoolean shutdown;

protected AbstractServerManager(final ProcessHandle process, final T client,
final boolean shutdownOnClose) {
Expand All @@ -44,6 +45,7 @@ protected AbstractServerManager(final ProcessHandle process, final T client,
this.shutdownOnClose = shutdownOnClose;
deploymentManager = DeploymentManager.create(client);
this.closed = new AtomicBoolean(false);
this.shutdown = new AtomicBoolean(false);
}

@Override
Expand Down Expand Up @@ -154,7 +156,9 @@ public void executeReload(final ModelNode reloadOp) throws IOException, Operatio
@Override
public void shutdown(final long timeout) throws IOException {
checkState();
internalShutdown(client(), timeout);
if (shutdown.compareAndSet(false, true)) {
internalShutdown(client(), timeout);
}
waitForShutdown(client());
}

Expand All @@ -165,7 +169,9 @@ public CompletableFuture<ServerManager> shutdownAsync(final long timeout) {
if (process != null) {
return CompletableFuture.supplyAsync(() -> {
try {
internalShutdown(client, timeout);
if (shutdown.compareAndSet(false, true)) {
internalShutdown(client, timeout);
}
} catch (IOException e) {
throw new CompletionException("Failed to shutdown server.", e);
}
Expand All @@ -189,7 +195,9 @@ public CompletableFuture<ServerManager> shutdownAsync(final long timeout) {
}
return CompletableFuture.supplyAsync(() -> {
try {
internalShutdown(client, timeout);
if (shutdown.compareAndSet(false, true)) {
internalShutdown(client, timeout);
}
} catch (IOException e) {
throw new CompletionException("Failed to shutdown server.", e);
}
Expand Down Expand Up @@ -223,7 +231,9 @@ void internalClose(final boolean shutdownOnClose, final boolean waitForShutdown)
if (closed.compareAndSet(false, true)) {
if (shutdownOnClose) {
try {
internalShutdown(client, 0);
if (shutdown.compareAndSet(false, true)) {
internalShutdown(client, 0);
}
if (waitForShutdown) {
waitForShutdown(client);
}
Expand Down

0 comments on commit f6a9eff

Please sign in to comment.