public interface GlassFish
Deployer
to deploy/undeploy applications. CommandRunner
to perform runtime configurations./** Create and start GlassFish */GlassFish
glassfish =GlassFishRuntime
.bootstrap().newGlassFish(); glassfish.start(); /** Deploy a web application simple.war with /hello as context root. */Deployer
deployer = glassfish.getService(Deployer.class); String deployedApp = deployer.deploy(new File("simple.war").toURI(), "--contextroot=hello", "--force=true"); /** Run commands (as per your need). Here is an example to create a http listener and dynamically set its thread pool size. */CommandRunner
commandRunner = glassfish.getService(CommandRunner.class); // Run a command create 'my-http-listener' to listen at 9090CommandResult
commandResult = commandRunner.run( "create-http-listener", "--listenerport=9090", "--listeneraddress=0.0.0.0", "--defaultvs=server", "my-http-listener"); // Run a command to create your own thread pool commandResult = commandRunner.run("create-threadpool", "--maxthreadpoolsize=200", "--minthreadpoolsize=200", "my-thread-pool"); // Run a command to associate my-thread-pool with my-http-listener commandResult = commandRunner.run("set", "server.network-config.network-listeners.network-listener." + "my-http-listener.thread-pool=my-thread-pool"); /** Undeploy the application */ deployer.undeploy(deployedApp); /**Stop GlassFish.*/ glassfish.stop(); /** Dispose GlassFish. */ glassfish.dispose();
Modifier and Type | Interface and Description |
---|---|
static class |
GlassFish.Status
Represents the status of
GlassFish . |
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Call this method if you don't need this GlassFish instance any more.
|
CommandRunner |
getCommandRunner()
Gets a CommandRunner instance, using which the user can run asadmin commands.
|
Deployer |
getDeployer()
Gets a Deployer instance to deploy an application.
|
<T> T |
getService(Class<T> serviceType)
A service has a service interface and optionally a name.
|
<T> T |
getService(Class<T> serviceType,
String serviceName)
A service has a service interface and optionally a name.
|
GlassFish.Status |
getStatus()
Get the current status of GlassFish.
|
void |
start()
Start GlassFish.
|
void |
stop()
Stop GlassFish.
|
void start() throws GlassFishException
GlassFish.Status.STARTED
state is a no-op.{@link
- IllegalStateException} if server is already started.GlassFishException
- if server can't be started for some unknown reason.void stop() throws GlassFishException
GlassFish.Status.STARTED
state is a no-op.{@link
- IllegalStateException} if server is already stopped.GlassFishException
- if server can't be started for some unknown reason.void dispose() throws GlassFishException
getStatus()
on the GlassFish object will cause an IllegalStateException to be thrown. When this method is called,
any resource (like temporary files, threads, etc.) is also released.GlassFishException
GlassFish.Status getStatus() throws GlassFishException
GlassFishException
<T> T getService(Class<T> serviceType) throws GlassFishException
T
- serviceType
- type of component required.GlassFishException
<T> T getService(Class<T> serviceType, String serviceName) throws GlassFishException
T
- serviceType
- type of component required.serviceName
- name of the component.GlassFishException
Deployer getDeployer() throws GlassFishException
getService(Deployer.class, null)
GlassFishException
CommandRunner getCommandRunner() throws GlassFishException
getService(CommandRunner.class, null)
Each invocation of this method returns a new CommandRunner object.GlassFishException
Copyright © 2018. All rights reserved.