Skip to content

Commit

Permalink
[WFMP-274] Do not close the management client while the ServerManager…
Browse files Browse the repository at this point in the history
… is still in use.

https://issues.redhat.com/browse/WFMP-274
Signed-off-by: James R. Perkins <[email protected]>
  • Loading branch information
jamezp committed Sep 9, 2024
1 parent e6f5ce1 commit e2fca95
Showing 1 changed file with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,55 +160,54 @@ protected ServerContext startServer(final ServerType serverType) throws MojoExec
final StandardOutput out = standardOutput();
// Create the server and close the client after the start. The process will continue running even after
// the maven process may have been finished
try (ModelControllerClient client = createClient()) {
if (ServerManager.isRunning(client)) {
throw new MojoExecutionException(String.format("%s server is already running?", serverType));
}
final CommandBuilder commandBuilder = createCommandBuilder(server);
log.info(String.format("%s server is starting up.", serverType));
final Launcher launcher = Launcher.of(commandBuilder)
.setRedirectErrorStream(true);
if (env != null) {
for (Map.Entry<String, String> entry : env.entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
launcher.addEnvironmentVariable(entry.getKey(), entry.getValue());
}
final ModelControllerClient client = createClient();
if (ServerManager.isRunning(client)) {
throw new MojoExecutionException(String.format("%s server is already running?", serverType));
}
final CommandBuilder commandBuilder = createCommandBuilder(server);
log.info(String.format("%s server is starting up.", serverType));
final Launcher launcher = Launcher.of(commandBuilder)
.setRedirectErrorStream(true);
if (env != null) {
for (Map.Entry<String, String> entry : env.entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
launcher.addEnvironmentVariable(entry.getKey(), entry.getValue());
}
}
out.getRedirect().ifPresent(launcher::redirectOutput);
}
out.getRedirect().ifPresent(launcher::redirectOutput);

final Process process = launcher.launch();
if (serverType == ServerType.DOMAIN) {
serverManager = ServerManager.builder().process(process).client(client).domain();
} else {
serverManager = ServerManager.builder().process(process).client(client).standalone();
}
// Note that if this thread is started and no shutdown goal is executed this stop the stdout and stderr
// from being logged any longer. The user was warned in the documentation.
out.startConsumer(process);
if (!serverManager.waitFor(startupTimeout, TimeUnit.SECONDS)) {
throw new MojoExecutionException(String.format("Server failed to start in %s seconds.", startupTimeout));
}
if (!process.isAlive()) {
throw new MojoExecutionException("The process has been terminated before the start goal has completed.");
final Process process = launcher.launch();
if (serverType == ServerType.DOMAIN) {
serverManager = ServerManager.builder().process(process).client(client).domain();
} else {
serverManager = ServerManager.builder().process(process).client(client).standalone();
}
// Note that if this thread is started and no shutdown goal is executed this stop the stdout and stderr
// from being logged any longer. The user was warned in the documentation.
out.startConsumer(process);
if (!serverManager.waitFor(startupTimeout, TimeUnit.SECONDS)) {
throw new MojoExecutionException(String.format("Server failed to start in %s seconds.", startupTimeout));
}
if (!process.isAlive()) {
throw new MojoExecutionException("The process has been terminated before the start goal has completed.");
}
return new ServerContext() {
@Override
public Process process() {
return process;
}
return new ServerContext() {
@Override
public Process process() {
return process;
}

@Override
public CommandBuilder commandBuilder() {
return commandBuilder;
}
@Override
public CommandBuilder commandBuilder() {
return commandBuilder;
}

@Override
public Path jbossHome() {
return server;
}
};
}
@Override
public Path jbossHome() {
return server;
}
};
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
Expand Down

0 comments on commit e2fca95

Please sign in to comment.