use of org.glassfish.embeddable.GlassFishRuntime in project Payara by payara.
the class StaticGlassFishRuntimeBuilder method build.
public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException {
/* Step 1. Build the classloader. */
// The classloader should contain installRoot/modules/**/*.jar files.
String installRoot = getInstallRoot(bsProps);
if (installRoot != null) {
System.setProperty("org.glassfish.embeddable.installRoot", installRoot);
}
// Required to add moduleJarURLs to support 'java -jar modules/glassfish.jar case'
List<URL> moduleJarURLs = getModuleJarURLs(installRoot);
ClassLoader cl = getClass().getClassLoader();
if (!moduleJarURLs.isEmpty()) {
cl = new StaticClassLoader(getClass().getClassLoader(), moduleJarURLs);
}
// Step 2. Setup the module subsystem.
Main main = new EmbeddedMain(cl);
SingleHK2Factory.initialize(cl);
ModulesRegistry modulesRegistry = AbstractFactory.getInstance().createModulesRegistry();
modulesRegistry.setParentClassLoader(cl);
// Step 3. Create NonOSGIGlassFishRuntime
GlassFishRuntime glassFishRuntime = new StaticGlassFishRuntime(main);
logger.logp(Level.FINER, getClass().getName(), "build", "Created GlassFishRuntime {0} with InstallRoot {1}, Bootstrap Options {2}", new Object[] { glassFishRuntime, installRoot, bsProps });
return glassFishRuntime;
}
use of org.glassfish.embeddable.GlassFishRuntime in project Payara by payara.
the class EmbeddedOSGiGlassFishRuntimeBuilder method build.
@SuppressWarnings({ "unchecked", "rawtypes" })
public GlassFishRuntime build(BootstrapProperties bootstrapProperties) throws GlassFishException {
configureBundles(bootstrapProperties);
provisionBundles(bootstrapProperties);
GlassFishRuntime glassFishRuntime = new EmbeddedOSGiGlassFishRuntime(getBundleContext());
Properties props = bootstrapProperties.getProperties();
Dictionary properties = new Properties();
for (final String name : props.stringPropertyNames()) {
properties.put(name, props.getProperty(name));
}
getBundleContext().registerService(GlassFishRuntime.class.getName(), glassFishRuntime, properties);
return glassFishRuntime;
}
use of org.glassfish.embeddable.GlassFishRuntime in project Payara by payara.
the class PayaraMicroImpl method bootStrap.
/**
* Boots the Payara Micro Server. All parameters are checked at this point
*
* @return An instance of PayaraMicroRuntime that can be used to access the
* running server
* @throws BootstrapException
*/
@Override
public PayaraMicroRuntime bootStrap() throws BootstrapException {
// First check whether we are already running
if (isRunning()) {
throw new IllegalStateException("Payara Micro is already running, calling bootstrap now is meaningless");
}
long start = System.currentTimeMillis();
// Build the runtime directory
try {
unPackRuntime();
} catch (IOException | URISyntaxException ex) {
throw new BootstrapException("Problem unpacking the Runtime", ex);
}
final String loggingProperty = System.getProperty("java.util.logging.config.file");
resetLogging(loggingProperty);
// If it's been enabled, watch the log file for changes
if (enableDynamicLogging) {
PayaraFileWatcher.watch(new File(loggingProperty).toPath(), () -> {
LOGGER.info("Logging file modified, resetting logging");
resetLogging(loggingProperty);
});
}
// Check a supported JDK version is being used
if (!JDK.isRunningLTSJDK()) {
LOGGER.warning("You are running the product on an unsupported JDK version and might see unexpected results or exceptions.");
}
runtimeDir.processDirectoryInformation();
// build the runtime
BootstrapProperties bprops = new BootstrapProperties();
bprops.setInstallRoot(runtimeDir.getDirectory().getAbsolutePath());
bprops.setProperty(Constants.PLATFORM_PROPERTY_KEY, Constants.Platform.PayaraMicro.toString());
GlassFishRuntime gfruntime;
try {
gfruntime = GlassFishRuntime.bootstrap(bprops, Thread.currentThread().getContextClassLoader());
GlassFishProperties gfproperties = new GlassFishProperties();
gfproperties.setProperty("-type", "MICRO");
gfproperties.setInstanceRoot(runtimeDir.getDirectory().getAbsolutePath());
gfproperties.setConfigFileReadOnly(false);
gfproperties.setConfigFileURI(runtimeDir.getDomainXML().toURI().toString());
try {
configureCommandFiles();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load command file", ex);
}
gf = gfruntime.newGlassFish(gfproperties);
configurePorts();
configureThreads();
configureAccessLogging();
configureHazelcast();
configurePhoneHome();
configureNotificationService();
configureHealthCheck();
configureRequestTracingService();
configureSecrets();
// Add additional libraries
addLibraries();
// boot the server
preBootCommands.executeCommands(gf.getCommandRunner());
callHandler(preBootHandler);
gf.start();
// Execute post boot commands
postBootCommands.executeCommands(gf.getCommandRunner());
callHandler(postBootHandler);
this.runtime = new PayaraMicroRuntimeImpl(gf, gfruntime);
// deploy all applications and then initialize them
deployAll();
// These steps are separated in case any steps need to be done in between
gf.getCommandRunner().run("initialize-all-applications");
postDeployCommands.executeCommands(gf.getCommandRunner());
long end = System.currentTimeMillis();
dumpFinalStatus(end - start);
return runtime;
} catch (Exception ex) {
try {
if (gf != null) {
gf.dispose();
}
} catch (GlassFishException ex1) {
LOGGER.log(Level.SEVERE, null, ex1);
}
throw new BootstrapException(ex.getMessage(), ex);
}
}
use of org.glassfish.embeddable.GlassFishRuntime in project solr-document-store by DBCDK.
the class Payara method getInstance.
static Payara getInstance(String port) throws GlassFishException {
if (glassfish == null) {
payaraPort = Integer.parseInt(port);
BootstrapProperties bootstrap = new BootstrapProperties();
GlassFishRuntime runtime = GlassFishRuntime.bootstrap(bootstrap);
GlassFishProperties glassfishProperties = new GlassFishProperties();
glassfishProperties.setPort("http-listener", payaraPort);
glassfish = runtime.newGlassFish(glassfishProperties);
glassfish.start();
runner = glassfish.getCommandRunner();
runner.setTerse(true);
}
return new Payara();
}
Aggregations