简体   繁体   中英

How to wait for the WildFly server to reload?

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());
}

You need to explicitly connect the CLI to the server. By default, this is localhost:9990 , which you can access by adding connect to the CLI commands (see the WildFly Admin Guide ). Otherwise, you should use the setController method .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM