I reload the WildFly server as follows
CliCommandBuilder cliCommandBuilder = ...
cliCommandBuilder
.setCommand(
"reload"
);
Launcher.of(cliCommandBuilder)
.inherit()
.setRedirectErrorStream(true)
.launch();
And I need to wait for the server to start, because then I will deploy the new content. How can I do this?
I tried use method .waitFor()
from java.lang.Process
Launcher.of(cliCommandBuilder)
.inherit()
.setRedirectErrorStream(true)
.launch().waitFor();
But the thread continues to work after shutting down WildFly, not starting
I thought the reload
command waited to terminate the process until WildFly was reloaded. However, there is a helper API you could use to check the process. Something like this should work:
final CliCommandBuilder commandBuilder = CliCommandBuilder.of("/opt/wildfly-27.0.0.Final")
.setConnection("localhost:9990")
.setCommand("reload");
final Process process = Launcher.of(commandBuilder)
.inherit()
.setRedirectErrorStream(true)
.launch();
// Wait for the process to end
if (!process.waitFor(5, TimeUnit.SECONDS)) {
throw new RuntimeException("The CLI process failed to terminate");
}
try (ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990)) {
while (!ServerHelper.isStandaloneRunning(client)) {
TimeUnit.MILLISECONDS.sleep(200L);
}
if (!Operations.isSuccessfulOutcome(result)) {
throw new RuntimeException("Failed to check state: " + Operations.getFailureDescription(result).asString());
}
System.out.printf("Running Mode: %s%n", Operations.readResult(result).asString());
}