Search in sources :

Example 41 with GlassFish

use of org.glassfish.embeddable.GlassFish in project Payara by payara.

the class Util method deploy.

public static void deploy(String app, String serverId, List<String> deployParams) throws Exception {
    GlassFish glassfish = gfMap.get(serverId);
    if (glassfish == null) {
        throw new Exception("Embedded GlassFish [" + serverId + "] not running");
    }
    if (app == null) {
        throw new Exception("Application can not be null");
    }
    Deployer deployer = glassfish.getDeployer();
    final int len = deployParams.size();
    if (len > 0) {
        deployer.deploy(new File(app).toURI(), deployParams.toArray(new String[len]));
        System.out.println("Deployed [" + app + "] with parameters " + deployParams);
    } else {
        deployer.deploy(new File(app).toURI());
        System.out.println("Deployed [" + app + "]");
    }
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) File(java.io.File) GlassFishException(org.glassfish.embeddable.GlassFishException) Deployer(org.glassfish.embeddable.Deployer)

Example 42 with GlassFish

use of org.glassfish.embeddable.GlassFish in project Payara by payara.

the class EmbeddedOSGiGlassFishRuntime method shutdown.

public synchronized void shutdown() throws GlassFishException {
    // make a copy to avoid ConcurrentModificationException
    for (GlassFish gf : new ArrayList<GlassFish>(gfs)) {
        if (gf.getStatus() != GlassFish.Status.DISPOSED) {
            try {
                gf.dispose();
            } catch (GlassFishException e) {
                e.printStackTrace();
            }
        }
    }
    gfs.clear();
    shutdownInternal();
    System.out.println("Completed shutdown of GlassFish runtime");
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ArrayList(java.util.ArrayList) GlassFish(org.glassfish.embeddable.GlassFish)

Example 43 with GlassFish

use of org.glassfish.embeddable.GlassFish in project Payara by payara.

the class RestartServer method doExecute.

/**
 * Restart of the application server :
 *
 * All running services are stopped. LookupManager is flushed.
 *
 * Client code that started us should notice the special return value and restart us.
 */
protected final void doExecute(AdminCommandContext context) {
    try {
        // unfortunately we can't rely on constructors with HK2...
        if (registry == null) {
            throw new NullPointerException(new LocalStringsImpl(getClass()).get("restart.server.internalError", "registry was not set"));
        }
        init(context);
        // get the GlassFish object - we have to wait in case startup is still in progress
        // This is a temporary work-around until HK2 supports waiting for the service to
        // show up in the ServiceLocator.
        GlassFish gfKernel = glassfishProvider.get();
        while (gfKernel == null) {
            Thread.sleep(1000);
            gfKernel = glassfishProvider.get();
        }
        if (!supervised) {
            // do it now while we still have the Logging service running...
            reincarnate();
        }
        prepareToExit();
        // else we just return a special int from System.exit()
        gfKernel.stop();
    } catch (Exception e) {
        context.getLogger().severe(strings.get("restart.server.failure", e));
    } finally {
        stopLock.unlock();
    }
}
Also used : LocalStringsImpl(com.sun.enterprise.universal.i18n.LocalStringsImpl) GlassFish(org.glassfish.embeddable.GlassFish)

Example 44 with GlassFish

use of org.glassfish.embeddable.GlassFish in project Payara by payara.

the class StopServer method doExecute.

/**
 * Shutdown of the server :
 *
 * All running services are stopped.
 * LookupManager is flushed.
 */
protected final void doExecute(ServiceLocator habitat, ServerEnvironment env, boolean force) {
    try {
        KernelLoggerInfo.getLogger().info(KernelLoggerInfo.serverShutdownInit);
        // Don't shutdown GlassFishRuntime, as that can bring the OSGi framework down which is wrong
        // when we are embedded inside an existing runtime. So, just stop the glassfish instance that
        // we are supposed to stop. Leave any cleanup to some other code.
        // get the GlassFish object - we have to wait in case startup is still in progress
        // This is a temporary work-around until HK2 supports waiting for the service to
        // show up in the ServiceLocator.
        GlassFish gfKernel = habitat.getService(GlassFish.class);
        while (gfKernel == null) {
            Thread.sleep(1000);
            gfKernel = habitat.getService(GlassFish.class);
        }
        // gfKernel is absolutely positively for-sure not null.
        gfKernel.stop();
    } catch (Throwable t) {
    // ignore
    }
    if (force) {
        System.exit(0);
    } else {
        deletePidFile(env);
    }
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish)

Aggregations

GlassFish (org.glassfish.embeddable.GlassFish)44 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)29 Test (org.junit.Test)27 Deployer (org.glassfish.embeddable.Deployer)24 File (java.io.File)23 PrintStream (java.io.PrintStream)21 CommandRunner (org.glassfish.embeddable.CommandRunner)18 CommandResult (org.glassfish.embeddable.CommandResult)17 JarFile (java.util.jar.JarFile)12 GlassFishException (org.glassfish.embeddable.GlassFishException)6 IOException (java.io.IOException)4 URI (java.net.URI)4 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ArrayList (java.util.ArrayList)2 InitialContext (javax.naming.InitialContext)2 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)2 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1