* Factory that sets up an embedded {@link HostController} using modular classloading. *
@@ -66,13 +41,14 @@ * @author Ken Wills- * The returned value is a String representation of one of the possible {@code ControlledProcessState.State} values. + * The returned value is a String representation of one of the possible {@code EmbeddedProcessState} values. * * @return The current process state, or {@code null} if currently the process state is unknown. * @throws UnsupportedOperationException if the requested operation is not supported by the implementation of this embedded server. diff --git a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedManagedProcessImpl.java b/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedManagedProcessImpl.java index 1ff976f5d22..11a68ae8ed1 100644 --- a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedManagedProcessImpl.java +++ b/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedManagedProcessImpl.java @@ -12,10 +12,10 @@ import org.wildfly.core.embedded.logging.EmbeddedLogger; /** - * Indirection to the {@link StandaloneServer} or {@link HostController}; used to encapsulate access to the underlying - * embedded instance in a manner that does not directly link this class. Necessary to avoid {@link ClassCastException} - * when this class is loaded by the application {@link ClassLoader} (or any other hierarchical CL) while the server is - * loaded by a modular environment. + * Embedding-application-side indirection to the {@link StandaloneServer} or {@link HostController}. + * Used to encapsulate access to the underlying embedded instance in a manner that does not directly link this class. + * Necessary to avoid {@link ClassCastException} when this class is loaded by the application {@link ClassLoader} + * (or any other hierarchical CL) while the server is loaded by a modular environment. * * @author Andrew Lee Rubinger * @author Thomas.Diesler@jboss.com. diff --git a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedProcessFactory.java b/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedProcessFactory.java index 5fd12279a0c..1faaf11283c 100644 --- a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedProcessFactory.java +++ b/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedProcessFactory.java @@ -18,7 +18,6 @@ import org.jboss.modules.Module; import org.jboss.modules.ModuleClassLoader; -import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoadException; import org.jboss.modules.ModuleLoader; import org.wildfly.core.embedded.logging.EmbeddedLogger; @@ -41,17 +40,6 @@ public class EmbeddedProcessFactory { private static final String MODULE_ID_EMBEDDED = "org.wildfly.embedded"; private static final String MODULE_ID_VFS = "org.jboss.vfs"; - private static final String SYSPROP_KEY_JBOSS_DOMAIN_BASE_DIR = "jboss.domain.base.dir"; - private static final String SYSPROP_KEY_JBOSS_DOMAIN_CONFIG_DIR = "jboss.domain.config.dir"; - private static final String SYSPROP_KEY_JBOSS_DOMAIN_DEPLOYMENT_DIR = "jboss.domain.deployment.dir"; - private static final String SYSPROP_KEY_JBOSS_DOMAIN_TEMP_DIR = "jboss.domain.temp.dir"; - private static final String SYSPROP_KEY_JBOSS_DOMAIN_LOG_DIR = "jboss.domain.log.dir"; - - static final String[] DOMAIN_KEYS = { - SYSPROP_KEY_JBOSS_DOMAIN_BASE_DIR, SYSPROP_KEY_JBOSS_DOMAIN_CONFIG_DIR, SYSPROP_KEY_JBOSS_DOMAIN_DEPLOYMENT_DIR, - SYSPROP_KEY_JBOSS_DOMAIN_TEMP_DIR, SYSPROP_KEY_JBOSS_DOMAIN_LOG_DIR, SYSPROP_KEY_JBOSS_DOMAIN_CONFIG_DIR - }; - private static final String HOST_FACTORY = "org.wildfly.core.embedded.EmbeddedHostControllerFactory"; private static final String SERVER_FACTORY = "org.wildfly.core.embedded.EmbeddedStandaloneServerFactory"; /** @@ -302,14 +290,11 @@ public static HostController createHostController(final Configuration configurat } private static void setupVfsModule(final ModuleLoader moduleLoader) { - final ModuleIdentifier vfsModuleID = ModuleIdentifier.create(MODULE_ID_VFS); - final Module vfsModule; try { - vfsModule = moduleLoader.loadModule(vfsModuleID); + Module.registerURLStreamHandlerFactoryModule(moduleLoader.loadModule(MODULE_ID_VFS)); } catch (final ModuleLoadException mle) { throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle,MODULE_ID_VFS, moduleLoader); } - Module.registerURLStreamHandlerFactoryModule(vfsModule); } private static Object createManagedProcess(final ProcessType embeddedType, final Method createServerMethod, final Configuration configuration, ModuleClassLoader embeddedModuleCL) { diff --git a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedStandaloneServerFactory.java b/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedStandaloneServerFactory.java index af60e960c6c..93241ebead4 100644 --- a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedStandaloneServerFactory.java +++ b/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedStandaloneServerFactory.java @@ -5,48 +5,21 @@ package org.wildfly.core.embedded; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.Collections; import java.util.Map; import java.util.Properties; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Supplier; -import org.jboss.as.controller.ControlledProcessState; -import org.jboss.as.controller.ProcessStateNotifier; -import org.jboss.as.controller.ControlledProcessStateService; -import org.jboss.as.controller.ModelControllerClientFactory; -import org.jboss.as.controller.client.ModelControllerClient; -import org.jboss.as.controller.client.helpers.DelegatingModelControllerClient; -import org.jboss.as.server.Bootstrap; -import org.jboss.as.server.ElapsedTime; -import org.jboss.as.server.Main; -import org.jboss.as.server.ServerEnvironment; -import org.jboss.as.server.ServerService; -import org.jboss.as.server.SystemExiter; import org.jboss.modules.ModuleLoader; -import org.jboss.msc.Service; -import org.jboss.msc.service.ServiceActivator; -import org.jboss.msc.service.ServiceActivatorContext; -import org.jboss.msc.service.ServiceBuilder; -import org.jboss.msc.service.ServiceContainer; -import org.jboss.msc.service.ServiceController; -import org.jboss.msc.service.StartContext; -import org.jboss.msc.service.StopContext; import org.wildfly.core.embedded.logging.EmbeddedLogger; +import org.wildfly.core.embedded.spi.EmbeddedProcessBootstrap; +import org.wildfly.core.embedded.spi.EmbeddedProcessBootstrapConfiguration; /** - * This is the standalone server counter-part of EmbeddedProcessFactory which lives behind a module class loader. + * This is the standalone server counter-part of EmbeddedProcessFactory that lives behind a module class loader. *
* Factory that sets up an embedded @{link StandaloneServer} using modular classloading. *
@@ -71,6 +44,9 @@ public class EmbeddedStandaloneServerFactory { public static final String JBOSS_EMBEDDED_ROOT = "jboss.embedded.root"; + private static final String SERVER_BASE_DIR = "jboss.server.base.dir"; + private static final String SERVER_CONFIG_DIR = "jboss.server.config.dir"; + private static final String SERVER_DATA_DIR = "jboss.server.data.dir"; private EmbeddedStandaloneServerFactory() { } @@ -100,8 +76,8 @@ static void setupCleanDirectories(Path jbossHomeDir, Properties props) { return; } - File originalConfigDir = getFileUnderAsRoot(jbossHomeDir.toFile(), props, ServerEnvironment.SERVER_CONFIG_DIR, "configuration", true); - File originalDataDir = getFileUnderAsRoot(jbossHomeDir.toFile(), props, ServerEnvironment.SERVER_DATA_DIR, "data", false); + File originalConfigDir = getFileUnderAsRoot(jbossHomeDir.toFile(), props, SERVER_CONFIG_DIR, "configuration", true); + File originalDataDir = getFileUnderAsRoot(jbossHomeDir.toFile(), props, SERVER_DATA_DIR, "data", false); try { Path configDir = tempRoot.resolve("config"); @@ -117,9 +93,9 @@ static void setupCleanDirectories(Path jbossHomeDir, Properties props) { copyDirectory(originalDataDir, dataDir.toFile()); } - props.put(ServerEnvironment.SERVER_BASE_DIR, tempRoot.toAbsolutePath().toString()); - props.put(ServerEnvironment.SERVER_CONFIG_DIR, configDir.toAbsolutePath().toString()); - props.put(ServerEnvironment.SERVER_DATA_DIR, dataDir.toAbsolutePath().toString()); + props.put(SERVER_BASE_DIR, tempRoot.toAbsolutePath().toString()); + props.put(SERVER_CONFIG_DIR, configDir.toAbsolutePath().toString()); + props.put(SERVER_DATA_DIR, dataDir.toAbsolutePath().toString()); } catch (IOException e) { throw EmbeddedLogger.ROOT_LOGGER.cannotSetupEmbeddedServer(e); } @@ -129,7 +105,7 @@ static void setupCleanDirectories(Path jbossHomeDir, Properties props) { private static File getFileUnderAsRoot(File jbossHomeDir, Properties props, String propName, String relativeLocation, boolean mustExist) { String prop = props.getProperty(propName, null); if (prop == null) { - prop = props.getProperty(ServerEnvironment.SERVER_BASE_DIR, null); + prop = props.getProperty(SERVER_BASE_DIR, null); if (prop == null) { File dir = new File(jbossHomeDir, "standalone" + File.separator + relativeLocation); if (mustExist && (!dir.exists() || !dir.isDirectory())) { @@ -138,12 +114,12 @@ private static File getFileUnderAsRoot(File jbossHomeDir, Properties props, Stri return dir; } else { File server = new File(prop); - validateDirectory(ServerEnvironment.SERVER_BASE_DIR, server); + validateDirectory(SERVER_BASE_DIR, server); return new File(server, relativeLocation); } } else { File dir = new File(prop); - validateDirectory(ServerEnvironment.SERVER_CONFIG_DIR, dir); + validateDirectory(SERVER_CONFIG_DIR, dir); return dir; } @@ -196,135 +172,17 @@ private static void copyDirectory(File src, File dest) { } - private static class StandaloneServerImpl implements StandaloneServer { + private static class StandaloneServerImpl extends AbstractEmbeddedManagedProcess implements StandaloneServer { - private final PropertyChangeListener processStateListener; - private final String[] cmdargs; private final Properties systemProps; private final Map
+ * In a VM with a {@link java.lang.SecurityManager SecurityManager} installed, invocations
+ * against the returned client can only occur from a calling context with the
+ * {@code org.jboss.as.controller.security.ControllerPermission#PERFORM_IN_VM_CALL PERFORM_IN_VM_CALL}
+ * permission. Without this permission a {@link SecurityException} will be thrown.
+ *
+ * @param executor the executor to use for asynchronous operation execution. Cannot be {@code null}
+ * @return the client. Will not return {@code null}
+ *
+ * @throws SecurityException if the caller does not have the
+ * {@code org.jboss.as.controller.security.ControllerPermission#CAN_ACCESS_MODEL_CONTROLLER CAN_ACCESS_MODEL_CONTROLLER}
+ * permission
+ */
+ LocalModelControllerClient createEmbeddedClient(Executor executor);
+}
diff --git a/embedded/src/main/java/org/wildfly/core/embedded/spi/EmbeddedProcessBootstrap.java b/embedded/src/main/java/org/wildfly/core/embedded/spi/EmbeddedProcessBootstrap.java
new file mode 100644
index 00000000000..2d10337ef9b
--- /dev/null
+++ b/embedded/src/main/java/org/wildfly/core/embedded/spi/EmbeddedProcessBootstrap.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.wildfly.core.embedded.spi;
+
+/**
+ * Service interface that standalone server or host controller bootstrap logic can implement
+ * to allow their type of process to be bootstrapped in an embedded environment.
+ */
+public interface EmbeddedProcessBootstrap {
+
+ enum Type {
+ STANDALONE_SERVER,
+ HOST_CONTROLLER
+ }
+
+ /**
+ * Gets the type of managed process this object bootstraps.
+ * @return the type. Will not be {@code null}.
+ */
+ Type getType();
+
+ /**
+ * Bootstraps an embedded process based on the provided configuration.
+ *
+ * @param configuration configuration for the bootstrap. Cannot be {@code null}.
+ *
+ * @return container object providing the embedding code access to items needed to manage the embedded process
+ *
+ * @throws Exception if one occurs while bootstrapping the process.
+ */
+ BootstrappedEmbeddedProcess startup(EmbeddedProcessBootstrapConfiguration configuration) throws Exception;
+}
diff --git a/embedded/src/main/java/org/wildfly/core/embedded/spi/EmbeddedProcessBootstrapConfiguration.java b/embedded/src/main/java/org/wildfly/core/embedded/spi/EmbeddedProcessBootstrapConfiguration.java
new file mode 100644
index 00000000000..b55acfb456d
--- /dev/null
+++ b/embedded/src/main/java/org/wildfly/core/embedded/spi/EmbeddedProcessBootstrapConfiguration.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.wildfly.core.embedded.spi;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Consumer;
+
+import org.jboss.modules.ModuleLoader;
+
+/**
+ * Configuration information for {@link EmbeddedProcessBootstrap#startup(EmbeddedProcessBootstrapConfiguration) starting}
+ * a {@link BootstrappedEmbeddedProcess}.
+ */
+public final class EmbeddedProcessBootstrapConfiguration {
+
+ private final String[] cmdArgs;
+ private volatile ModuleLoader moduleLoader;
+ private final Consumerlistener
is null, no exception is thrown and no action
+ * is taken.
+ *
+ * @param listener the listener
+ *
+ * @throws IllegalStateException if the process is not an embedded process
+ */
+ void addProcessStateListener(PropertyChangeListener listener);
+
+
+ /**
+ * Remove a listener for changes in the current state.
+ * If listener
was added more than once,
+ * it will be notified one less time after being removed.
+ * If listener
is null, or was never added, no exception is
+ * thrown and no action is taken.
+ *
+ * @param listener the listener
+ *
+ * @throws IllegalStateException if the process is not an embedded process
+ */
+ void removeProcessStateListener(PropertyChangeListener listener);
+}
+
diff --git a/embedded/src/test/java/org/wildfly/core/embedded/EmbeddedServerFactorySetupUnitTestCase.java b/embedded/src/test/java/org/wildfly/core/embedded/EmbeddedServerFactorySetupUnitTestCase.java
index 6cf3868148b..3275c72f37d 100644
--- a/embedded/src/test/java/org/wildfly/core/embedded/EmbeddedServerFactorySetupUnitTestCase.java
+++ b/embedded/src/test/java/org/wildfly/core/embedded/EmbeddedServerFactorySetupUnitTestCase.java
@@ -11,7 +11,6 @@
import java.nio.file.Paths;
import java.util.Properties;
-import org.jboss.as.server.ServerEnvironment;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -22,6 +21,10 @@
* @version $Revision: 1.1 $
*/
public class EmbeddedServerFactorySetupUnitTestCase {
+ private static final String SERVER_BASE_DIR = "jboss.server.base.dir";
+ private static final String SERVER_CONFIG_DIR = "jboss.server.config.dir";
+ private static final String SERVER_DATA_DIR = "jboss.server.data.dir";
+
final Path standardJBossHome;
final Path alternativeServer;
final Path alternativeDataDir;
@@ -66,65 +69,65 @@ public void testEmbeddedRootNoOverrides() throws Exception {
Assert.assertEquals(4, props.size());
Assert.assertEquals(embeddedRoot.toAbsolutePath().toString(), props.getProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT));
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_BASE_DIR, -1);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_DATA_DIR, 1);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_CONFIG_DIR, 1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_BASE_DIR, -1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_DATA_DIR, 1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_CONFIG_DIR, 1);
}
@Test
public void testEmbeddedRootServerOverride() throws Exception {
Properties props = new Properties();
props.setProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT, embeddedRoot.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_BASE_DIR, alternativeServer.toAbsolutePath().toString());
+ props.setProperty(SERVER_BASE_DIR, alternativeServer.toAbsolutePath().toString());
EmbeddedStandaloneServerFactory.setupCleanDirectories(standardJBossHome, props);
Assert.assertEquals(4, props.size());
Assert.assertEquals(embeddedRoot.toAbsolutePath().toString(), props.getProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT));
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_BASE_DIR, -1);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_DATA_DIR, 2);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_CONFIG_DIR, 2);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_BASE_DIR, -1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_DATA_DIR, 2);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_CONFIG_DIR, 2);
}
@Test
public void testDataAndConfigOverride() throws Exception {
Properties props = new Properties();
props.setProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT, embeddedRoot.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_DATA_DIR, alternativeDataDir.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_CONFIG_DIR, alternativeConfigDir.toAbsolutePath().toString());
+ props.setProperty(SERVER_DATA_DIR, alternativeDataDir.toAbsolutePath().toString());
+ props.setProperty(SERVER_CONFIG_DIR, alternativeConfigDir.toAbsolutePath().toString());
EmbeddedStandaloneServerFactory.setupCleanDirectories(standardJBossHome, props);
Assert.assertEquals(4, props.size());
Assert.assertEquals(embeddedRoot.toAbsolutePath().toString(), props.getProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT));
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_BASE_DIR, -1);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_DATA_DIR, 3);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_CONFIG_DIR, 4);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_BASE_DIR, -1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_DATA_DIR, 3);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_CONFIG_DIR, 4);
}
@Test
public void testServerOverrideAndDataAndConfigOverride() throws Exception {
Properties props = new Properties();
props.setProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT, embeddedRoot.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_BASE_DIR, alternativeServer.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_DATA_DIR, alternativeDataDir.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_CONFIG_DIR, alternativeConfigDir.toAbsolutePath().toString());
+ props.setProperty(SERVER_BASE_DIR, alternativeServer.toAbsolutePath().toString());
+ props.setProperty(SERVER_DATA_DIR, alternativeDataDir.toAbsolutePath().toString());
+ props.setProperty(SERVER_CONFIG_DIR, alternativeConfigDir.toAbsolutePath().toString());
EmbeddedStandaloneServerFactory.setupCleanDirectories(standardJBossHome, props);
Assert.assertEquals(4, props.size());
Assert.assertEquals(embeddedRoot.toAbsolutePath().toString(), props.getProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT));
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_BASE_DIR, -1);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_DATA_DIR, 3);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_CONFIG_DIR, 4);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_BASE_DIR, -1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_DATA_DIR, 3);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_CONFIG_DIR, 4);
}
@Test
public void testServerOverrideAndConfigOverride() throws Exception {
Properties props = new Properties();
props.setProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT, embeddedRoot.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_BASE_DIR, alternativeServer.toAbsolutePath().toString());
- props.setProperty(ServerEnvironment.SERVER_CONFIG_DIR, alternativeConfigDir.toAbsolutePath().toString());
+ props.setProperty(SERVER_BASE_DIR, alternativeServer.toAbsolutePath().toString());
+ props.setProperty(SERVER_CONFIG_DIR, alternativeConfigDir.toAbsolutePath().toString());
EmbeddedStandaloneServerFactory.setupCleanDirectories(standardJBossHome, props);
Assert.assertEquals(4, props.size());
Assert.assertEquals(embeddedRoot.toAbsolutePath().toString(), props.getProperty(EmbeddedStandaloneServerFactory.JBOSS_EMBEDDED_ROOT));
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_BASE_DIR, -1);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_DATA_DIR, 2);
- assertPropertyAndEmbeddedRootFile(props, ServerEnvironment.SERVER_CONFIG_DIR, 4);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_BASE_DIR, -1);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_DATA_DIR, 2);
+ assertPropertyAndEmbeddedRootFile(props, SERVER_CONFIG_DIR, 4);
}
private void assertPropertyAndEmbeddedRootFile(Properties props, String property, int id) {
diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerBootstrap.java b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerBootstrap.java
index 76494a2b717..dc23ce74e6e 100644
--- a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerBootstrap.java
+++ b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerBootstrap.java
@@ -43,7 +43,7 @@ public HostControllerBootstrap(final HostControllerEnvironment environment, fina
*/
public void bootstrap() throws Exception {
final HostRunningModeControl runningModeControl = environment.getRunningModeControl();
- final ControlledProcessState processState = new ControlledProcessState(true);
+ final ControlledProcessState processState = new ControlledProcessState(true, false);
shutdownHook.setControlledProcessState(processState);
ServiceTarget target = serviceContainer.subTarget();
ProcessStateNotifier processStateNotifier = ControlledProcessStateService.addService(target, processState);
diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java
index f8deb495d74..23979092afb 100644
--- a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java
+++ b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java
@@ -42,10 +42,13 @@
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.as.version.ProductConfig;
import org.jboss.msc.service.Service;
+import org.jboss.msc.service.ServiceActivator;
+import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceContainer;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
+import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
@@ -80,11 +83,13 @@ public JBossThreadFactory run() {
private final String authCode;
private final CapabilityRegistry capabilityRegistry;
private final ElapsedTime elapsedTime;
- private volatile FutureServiceContainer futureContainer;
+ private final ServiceActivator[] extraServices;
+ private final FutureServiceContainer futureContainer;
private volatile boolean everStopped;
public HostControllerService(final HostControllerEnvironment environment, final HostRunningModeControl runningModeControl,
- final String authCode, final ControlledProcessState processState, FutureServiceContainer futureContainer) {
+ final String authCode, final ControlledProcessState processState,
+ final FutureServiceContainer futureContainer, ServiceActivator... extraServices) {
this.environment = environment;
this.runningModeControl = runningModeControl;
this.authCode = authCode;
@@ -92,6 +97,7 @@ public HostControllerService(final HostControllerEnvironment environment, final
this.elapsedTime = environment.getElapsedTime();
this.futureContainer = futureContainer;
this.capabilityRegistry = new CapabilityRegistry(false);
+ this.extraServices = extraServices;
}
public HostControllerService(final HostControllerEnvironment environment, final HostRunningModeControl runningModeControl,
@@ -197,6 +203,24 @@ public void start(StartContext context) throws StartException {
DomainModelControllerService.addService(serviceTarget, environment, runningModeControl, processState,
bootstrapListener, hostPathManagerService, capabilityRegistry, THREAD_GROUP);
+
+ if (extraServices != null && extraServices.length > 0) {
+ final ServiceActivatorContext serviceActivatorContext = new ServiceActivatorContext() {
+ @Override
+ public ServiceTarget getServiceTarget() {
+ return serviceTarget;
+ }
+
+ @Override
+ public ServiceRegistry getServiceRegistry() {
+ return context.getController().getServiceContainer();
+ }
+ };
+
+ for(ServiceActivator activator : extraServices) {
+ activator.activate(serviceActivatorContext);
+ }
+ }
}
@Override
diff --git a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedHostControllerBootstrap.java b/host-controller/src/main/java/org/jboss/as/host/controller/embedded/EmbeddedHostControllerBootstrap.java
similarity index 78%
rename from embedded/src/main/java/org/wildfly/core/embedded/EmbeddedHostControllerBootstrap.java
rename to host-controller/src/main/java/org/jboss/as/host/controller/embedded/EmbeddedHostControllerBootstrap.java
index dc42b8db520..9af3ee61ddb 100644
--- a/embedded/src/main/java/org/wildfly/core/embedded/EmbeddedHostControllerBootstrap.java
+++ b/host-controller/src/main/java/org/jboss/as/host/controller/embedded/EmbeddedHostControllerBootstrap.java
@@ -3,25 +3,25 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package org.wildfly.core.embedded;
+package org.jboss.as.host.controller.embedded;
+
-import java.beans.PropertyChangeListener;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.Future;
import org.jboss.as.controller.ControlledProcessState;
-import org.jboss.as.controller.ProcessStateNotifier;
import org.jboss.as.controller.ControlledProcessStateService;
import org.jboss.as.host.controller.HostControllerEnvironment;
import org.jboss.as.host.controller.HostControllerService;
import org.jboss.as.host.controller.HostRunningModeControl;
import org.jboss.as.server.FutureServiceContainer;
import org.jboss.as.server.jmx.RunningStateJmx;
+import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceContainer;
import org.jboss.msc.service.ServiceTarget;
/**
- * Bootstrap of the Embedded HostController process.
+ * Embedded variant of {@link org.jboss.as.host.controller.HostControllerBootstrap}. TODO see if these can be unified.
*
* @author Ken Wills (c) 2015 Red Hat Inc.
*/
@@ -31,30 +31,29 @@ public class EmbeddedHostControllerBootstrap {
private final ServiceContainer serviceContainer;
private final HostControllerEnvironment environment;
private final String authCode;
- private final FutureServiceContainer futureContainer;
- public EmbeddedHostControllerBootstrap(FutureServiceContainer futureContainer, final HostControllerEnvironment environment, final String authCode) {
+ public EmbeddedHostControllerBootstrap(final HostControllerEnvironment environment, final String authCode) {
this.environment = environment;
this.authCode = authCode;
this.shutdownHook = new ShutdownHook();
this.serviceContainer = shutdownHook.register();
- this.futureContainer = futureContainer;
}
- public FutureServiceContainer bootstrap(PropertyChangeListener processStateListener, AtomicReference