Search in sources :

Example 1 with GlassFishRuntime

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;
}
Also used : ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) URLClassLoader(java.net.URLClassLoader) Main(com.sun.enterprise.module.bootstrap.Main) URL(java.net.URL)

Example 2 with 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;
}
Also used : Dictionary(java.util.Dictionary) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) Properties(java.util.Properties) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties)

Example 3 with 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);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) BootstrapException(fish.payara.micro.BootstrapException) GlassFishException(org.glassfish.embeddable.GlassFishException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ValidationException(fish.payara.micro.cmd.options.ValidationException) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) BootstrapException(fish.payara.micro.BootstrapException) JarFile(java.util.jar.JarFile) File(java.io.File) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 4 with GlassFishRuntime

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();
}
Also used : BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Aggregations

GlassFishRuntime (org.glassfish.embeddable.GlassFishRuntime)4 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)3 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)2 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 Main (com.sun.enterprise.module.bootstrap.Main)1 BootstrapException (fish.payara.micro.BootstrapException)1 ValidationException (fish.payara.micro.cmd.options.ValidationException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Dictionary (java.util.Dictionary)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1