Skip to content

Commit

Permalink
[WFCORE-7120] Move the server-side embedding logic to the server and …
Browse files Browse the repository at this point in the history
…host-controller modules
  • Loading branch information
bstansberry committed Dec 26, 2024
1 parent 7b6198a commit fddefa9
Show file tree
Hide file tree
Showing 25 changed files with 237 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<module name="org.jboss.vfs" services="import"/>
<module name="org.jboss.xnio"/>
<module name="org.wildfly.common"/>
<module name="org.wildfly.embedding-spi"/>
<module name="org.wildfly.installation-manager" services="import"/>
<module name="org.wildfly.security.elytron-private" services="import"/>
<module name="org.wildfly.service"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<module name="org.wildfly.common"/>
<!-- Allow javax->jakarta deployment transformation if this module is provided -->
<module name="org.wildfly.deployment.transformation" optional="true" services="import"/>
<module name="org.wildfly.embedding-spi"/>
<module name="org.wildfly.extension.core-management-client" />
<module name="org.wildfly.installation-manager" services="import"/>
<module name="org.wildfly.security.elytron-private" services="import"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@
</resources>

<dependencies>
<module name="java.desktop"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.common"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.controller"/>
<module name="java.desktop"/> <!-- for PropertyChangeListener -->
<module name="org.jboss.as.controller-client"/>
<module name="org.jboss.as.host-controller"/>
<module name="org.jboss.as.host-controller" services="import"/>
<module name="org.jboss.as.server" services="import"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.stdio"/>
<module name="org.jboss.threads"/>
<module name="org.wildfly.embedding-spi"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
</resources>

<dependencies>
<module name="java.desktop"/>
<module name="java.desktop"/> <!-- for PropertyChangeListener -->
<module name="org.jboss.as.controller-client"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
</dependencies>
Expand Down
33 changes: 0 additions & 33 deletions embedded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,39 +109,6 @@
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-host-controller</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.msc</groupId>
<artifactId>jboss-msc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ServiceLoader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand All @@ -21,8 +22,12 @@
import org.wildfly.core.embedding.spi.EmbeddedProcessState;
import org.wildfly.core.embedding.spi.ProcessStateNotifier;

/**
* Base class for modular-classloader-side implementations of {@link StandaloneServer} and {@link HostController}.
*/
abstract class AbstractEmbeddedManagedProcess implements EmbeddedManagedProcess {

private final EmbeddedProcessBootstrap.Type type;
private final PropertyChangeListener processStateListener;
private final String[] cmdargs;
private final ClassLoader embeddedModuleCL;
Expand All @@ -31,7 +36,8 @@ abstract class AbstractEmbeddedManagedProcess implements EmbeddedManagedProcess
private ModelControllerClient modelControllerClient;
private ExecutorService executorService;

AbstractEmbeddedManagedProcess(String[] cmdargs, ClassLoader embeddedModuleCL) {
AbstractEmbeddedManagedProcess(EmbeddedProcessBootstrap.Type type, String[] cmdargs, ClassLoader embeddedModuleCL) {
this.type = type;
this.cmdargs = cmdargs;
this.embeddedModuleCL = embeddedModuleCL;

Expand All @@ -45,20 +51,20 @@ public void propertyChange(PropertyChangeEvent evt) {
}

@Override
public synchronized ModelControllerClient getModelControllerClient() {
public final synchronized ModelControllerClient getModelControllerClient() {
return modelControllerClient == null ? null : new DelegatingModelControllerClient(this::getActiveModelControllerClient);
}

@Override
public void start() throws EmbeddedProcessStartException {
public final void start() throws EmbeddedProcessStartException {
EmbeddedProcessBootstrapConfiguration bootstrapConfiguration = getBootstrapConfiguration();

ClassLoader tccl = SecurityActions.getTccl();
try {
SecurityActions.setTccl(embeddedModuleCL);
try {

EmbeddedProcessBootstrap bootstrap = loadEmbeddedProcessBootstrap(embeddedModuleCL);
EmbeddedProcessBootstrap bootstrap = loadEmbeddedProcessBootstrap();
embeddedProcess = bootstrap.startup(bootstrapConfiguration);
if (embeddedProcess == null) {
// TODO before adding embedded-spi, why did we ignore Main.determineEnvironment not providing one?
Expand All @@ -83,7 +89,7 @@ public void start() throws EmbeddedProcessStartException {
}

@Override
public void stop() {
public final void stop() {
ClassLoader tccl = SecurityActions.getTccl();
try {
SecurityActions.setTccl(embeddedModuleCL);
Expand Down Expand Up @@ -113,9 +119,17 @@ EmbeddedProcessBootstrapConfiguration getBootstrapConfiguration() {
);
}

abstract EmbeddedProcessBootstrap loadEmbeddedProcessBootstrap(ClassLoader embeddedModuleCL);
private EmbeddedProcessBootstrap loadEmbeddedProcessBootstrap() {
ServiceLoader<EmbeddedProcessBootstrap> loader = ServiceLoader.load(EmbeddedProcessBootstrap.class, embeddedModuleCL);
for (EmbeddedProcessBootstrap epb : loader) {
if (type == epb.getType()) {
return epb;
}
}
throw new IllegalStateException();
}

final synchronized void establishModelControllerClient(EmbeddedProcessState state, boolean storeState) {
private synchronized void establishModelControllerClient(EmbeddedProcessState state, boolean storeState) {
ModelControllerClient newClient = null;
if (state != EmbeddedProcessState.STOPPING && state != EmbeddedProcessState.STOPPED && embeddedProcess != null) {
EmbeddedModelControllerClientFactory clientFactory = embeddedProcess.getModelControllerClientFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

package org.wildfly.core.embedded;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -19,7 +20,7 @@
import org.wildfly.core.embedding.spi.EmbeddedProcessBootstrapConfiguration;

/**
* This is the host controller counterpart to EmbeddedProcessFactory which lives behind a module class loader.
* This is the host controller counterpart to EmbeddedProcessFactory that lives behind a module class loader.
* <p>
* Factory that sets up an embedded {@link HostController} using modular classloading.
* </p>
Expand All @@ -40,6 +41,7 @@
* @author Ken Wills <[email protected]>
* @see EmbeddedProcessFactory
*/

public class EmbeddedHostControllerFactory {

public static final String JBOSS_EMBEDDED_ROOT = "jboss.embedded.root";
Expand Down Expand Up @@ -180,7 +182,7 @@ private static class HostControllerImpl extends AbstractEmbeddedManagedProcess i
private final Map<String, String> systemEnv; // TODO why is this not used?

public HostControllerImpl(final File jbossHomeDir, String[] cmdargs, Properties systemProps, Map<String, String> systemEnv, ClassLoader embeddedModuleCL) {
super(cmdargs, embeddedModuleCL);
super(EmbeddedProcessBootstrap.Type.HOST_CONTROLLER, cmdargs, embeddedModuleCL);
this.jbossHomeDir = jbossHomeDir;
this.systemProps = systemProps;
this.systemEnv = systemEnv;
Expand All @@ -193,12 +195,6 @@ EmbeddedProcessBootstrapConfiguration getBootstrapConfiguration() {
return configuration;
}

@Override
EmbeddedProcessBootstrap loadEmbeddedProcessBootstrap(ClassLoader embeddedModuleCL) {
return new HostEmbeddedProcessBootstrap();
}


}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface EmbeddedManagedProcess {
/**
* Returns the current process state of this managed process.
* <p>
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:[email protected]">Andrew Lee Rubinger</a>
* @author [email protected].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.wildfly.core.embedding.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.
* <p>
* Factory that sets up an embedded @{link StandaloneServer} using modular classloading.
* </p>
Expand Down Expand Up @@ -179,7 +179,7 @@ private static class StandaloneServerImpl extends AbstractEmbeddedManagedProcess
private final ModuleLoader moduleLoader;

public StandaloneServerImpl(String[] cmdargs, Properties systemProps, Map<String, String> systemEnv, ModuleLoader moduleLoader, ClassLoader embeddedModuleCL) {
super(cmdargs, embeddedModuleCL);
super(EmbeddedProcessBootstrap.Type.STANDALONE_SERVER, cmdargs, embeddedModuleCL);
this.systemProps = systemProps;
this.systemEnv = systemEnv;
this.moduleLoader = moduleLoader;
Expand All @@ -205,11 +205,6 @@ EmbeddedProcessBootstrapConfiguration getBootstrapConfiguration() {
configuration.setSystemEnv(systemEnv);
return configuration;
}

@Override
EmbeddedProcessBootstrap loadEmbeddedProcessBootstrap(ClassLoader embeddedModuleCL) {
return new StandaloneEmbeddedProcessBootstrap();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,4 @@ public interface EmbeddedLogger extends BasicLogger {
@Message(id = 146, value = "Failed to restore context %s")
@LogMessage(level = Logger.Level.ERROR)
void failedToRestoreContext(@Cause Throwable cause, Context context);

@Message(id = 147, value = "Embedded process services are not available after %d seconds: %s")
@LogMessage(level = Logger.Level.ERROR)
void embeddedProcessServicesUnavailable(int timeout, String unavailable);
}
Loading

0 comments on commit fddefa9

Please sign in to comment.