+ * When the server manager is closed, the underlying client is also closed. + *
* * @author James R. Perkins */ @SuppressWarnings("unused") -public interface ServerManager { +public interface ServerManager extends AutoCloseable { /** * A builder used to build a {@link ServerManager}. @@ -39,9 +42,10 @@ class Builder { private String managementAddress; private int managementPort; private ProcessHandle process; + private boolean shutdownOnClose; /** - * Sets the client to use for the server manager. + * Sets the client to use for the server manager. The caller is responsible for closing the client. * * @param client the client to use to communicate with the server * @@ -105,6 +109,19 @@ public Builder managementPort(final int managementPort) { return this; } + /** + * When set to {@code true} the server will be {@linkplain ServerManager#shutdown() shutdown} when the server + * manager is {@linkplain ServerManager#close() closed}. + * + * @param shutdownOnClose {@code true} to shutdown the server when the server manager is closed + * + * @return this builder + */ + public Builder shutdownOnClose(final boolean shutdownOnClose) { + this.shutdownOnClose = shutdownOnClose; + return this; + } + /** * Creates a {@link StandaloneManager} based on the builders settings. If the * {@link #client(ModelControllerClient) client} was not set, the {@link #managementAddress(String) managementAddress} @@ -113,7 +130,7 @@ public Builder managementPort(final int managementPort) { * @return a new {@link StandaloneManager} */ public StandaloneManager standalone() { - return new StandaloneManager(process, getOrCreateClient()); + return new StandaloneManager(process, getOrCreateClient(), shutdownOnClose); } /** @@ -124,7 +141,7 @@ public StandaloneManager standalone() { * @return a new {@link DomainManager} */ public DomainManager domain() { - return new DomainManager(process, getOrCreateDomainClient()); + return new DomainManager(process, getOrCreateDomainClient(), shutdownOnClose); } /** @@ -153,9 +170,9 @@ public CompletableFuture