Package org.glassfish.embeddable
Interface GlassFish
public interface GlassFish
Represents a GlassFish instance and provides the ability to:
- perform life cycle operations viz., start, stop and dispose.
- access
Deployerto deploy/undeploy applications. - access
CommandRunnerto perform runtime configurations. - access to available service(s).
/** Create and start GlassFish */GlassFishglassfish =GlassFishRuntime.bootstrap().newGlassFish(); glassfish.start(); /** Deploy a web application simple.war with /hello as context root. */Deployerdeployer = 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. */CommandRunnercommandRunner = glassfish.getService(CommandRunner.class); // Run a command create 'my-http-listener' to listen at 9090CommandResultcommandResult = 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();
- Author:
- Sanjeeb.Sahoo@Sun.COM
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Call this method if you don't need this GlassFish instance any more.Gets a CommandRunner instance, using which the user can run asadmin commands.Gets a Deployer instance to deploy an application.<T> TgetService(Class<T> serviceType) A service has a service interface and optionally a name.<T> TgetService(Class<T> serviceType, String serviceName) A service has a service interface and optionally a name.Get the current status of GlassFish.voidstart()Start GlassFish.voidstop()Stop GlassFish.
-
Method Details
-
start
Start GlassFish. When this method is called, all the lifecycle (aka startup) services are started. Calling this method while the server is inGlassFish.Status.STARTEDstate is a no-op.- Throws:
GlassFishException- if server can't be started for some unknown reason.
-
stop
Stop GlassFish. When this method is called, all the lifecycle (aka startup) services are stopped. GlassFish can be started again by calling the start method. Calling this method while the server is inGlassFish.Status.STARTEDstate is a no-op.- Throws:
GlassFishException- if server can't be started for some unknown reason.
-
dispose
Call this method if you don't need this GlassFish instance any more. This method will stop GlassFish if not already stopped. After this method is called, calling any method exceptgetStatus()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.- Throws:
GlassFishException
-
getStatus
Get the current status of GlassFish.- Returns:
- Status of GlassFish
- Throws:
GlassFishException
-
getService
A service has a service interface and optionally a name. For a service which is just a class with no interface, then the service class is the service interface. This method is used to look up a service.- Type Parameters:
T-- Parameters:
serviceType- type of component required.- Returns:
- Return a service matching the requirement, null if no service found.
- Throws:
GlassFishException
-
getService
A service has a service interface and optionally a name. For a service which is just a class with no interface, then the service class is the service interface. This method is used to look up a service.- Type Parameters:
T-- Parameters:
serviceType- type of component required.serviceName- name of the component.- Returns:
- Return a service matching the requirement, null if no service found.
- Throws:
GlassFishException
-
getDeployer
Gets a Deployer instance to deploy an application. Each invocation of this method returns a new Deployer object. Calling this method is equivalent to callinggetService(Deployer.class, null)- Returns:
- A new Deployer instance
- Throws:
GlassFishException
-
getCommandRunner
Gets a CommandRunner instance, using which the user can run asadmin commands. Calling this method is equivalent to callinggetService(CommandRunner.class, null)Each invocation of this method returns a new CommandRunner object.- Returns:
- a new CommandRunner instance
- Throws:
GlassFishException
-