本文整理了Java中org.glassfish.embeddable.GlassFish
类的一些代码示例,展示了GlassFish
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GlassFish
类的具体详情如下:
包路径:org.glassfish.embeddable.GlassFish
类名称:GlassFish
[英]Represents a GlassFish instance and provides the ability to:
Usage example:
/** 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 9090
CommandResult 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();
[中]表示GlassFish实例,并提供以下功能:
*执行生命周期操作,即:。,启动、停止和处置。
*访问Deployer以部署/取消部署应用程序。
*访问CommandRunner以执行运行时配置。
*访问可用服务。
用法示例:
/** 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 9090
CommandResult 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();
代码示例来源:origin: org.glassfish.main.ejb/ejb-container
/**
* Construct new EJBContainerImpl instance
*/
EJBContainerImpl(GlassFish server) throws GlassFishException {
this.server = server;
this.server.start();
this.habitat = server.getService(ServiceLocator.class);
deployer = server.getDeployer();
state = RUNNING;
cleanup = new Cleanup(this);
}
代码示例来源:origin: org.glassfish.main.core/glassfish
public void run() {
try {
if (gf != null) {
gf.stop();
gf.dispose();
}
} catch (Exception ex) {
}
}
});
代码示例来源:origin: org.glassfish.common/internal-api
/**
* Starts the embedded server, opening ports, and running the startup
* services.
*
* @throws LifecycleException if the server cannot be started propertly
*/
public synchronized void start() throws LifecycleException {
if(glassfish != null) {
try {
if (glassfish.getStatus() != GlassFish.Status.STARTED) {
glassfish.start();
}
} catch (GlassFishException e) {
throw new LifecycleException(e); // TODO(Sahoo): Proper Exception Handling
}
logger.finer("GlassFish has been started");
}
}
代码示例来源:origin: org.glassfish.main.core/glassfish
System.out.println("command = " + command);
if ("start".equalsIgnoreCase(command)) {
if (gf.getStatus() != GlassFish.Status.STARTED || gf.getStatus() == GlassFish.Status.STOPPING || gf.getStatus() == GlassFish.Status.STARTING)
gf.start();
else System.out.println("Already started or stopping or starting");
} else if ("stop".equalsIgnoreCase(command)) {
if (gf.getStatus() != GlassFish.Status.STARTED) {
System.out.println("GlassFish is not started yet. Please execute start first.");
continue;
gf.stop();
} else if (command.startsWith("deploy")) {
if (gf.getStatus() != GlassFish.Status.STARTED) {
System.out.println("GlassFish is not started yet. Please execute start first.");
continue;
Deployer deployer = gf.getService(Deployer.class, null);
String[] tokens = command.split("\\s");
if (tokens.length < 2) {
System.out.println("Deployed = " + name);
} else if (command.startsWith("undeploy")) {
if (gf.getStatus() != GlassFish.Status.STARTED) {
System.out.println("GlassFish is not started yet. Please execute start first.");
continue;
Deployer deployer = gf.getService(Deployer.class, null);
String name = command.substring(command.indexOf(" ")).trim();
deployer.undeploy(name);
代码示例来源:origin: org.glassfish.main.ejb/ejb-container
if (l.instance_root != null && !l.reuse_instance_location) {
server.start();
EmbeddedSecurity es = server.getService(EmbeddedSecurity.class);
ServiceLocator habitat = server.getService(ServiceLocator.class);
server.stop();
archiveFactory = server.getService(ArchiveFactory.class);
Sniffer sniffer = server.getService(Sniffer.class, "Ejb");
ejbAnnotations = sniffer.getAnnotationTypes();
} catch (Exception e) {
代码示例来源:origin: org.glassfish.main.core/glassfish
gf.start();
CommandRunner cr = gf.getCommandRunner();
gf.stop();
gf.dispose();
} catch (Exception ex) {
代码示例来源:origin: stackoverflow.com
glassFish.start();
deployer = glassFish.getDeployer();
ScatteredArchive archive = new ScatteredArchive("glassfish-ejb-validation", Type.JAR);
archive.addClassPath(new File("target", "classes"));
glassFish.stop();
glassFish.dispose();
代码示例来源:origin: eclipse-ee4j/glassfish
@Override
public void start() throws GlassFishException {
decoratedGf.start();
}
代码示例来源:origin: eclipse-ee4j/glassfish
setGlassFishProperties(gfProps, fs);
glassfish = glassfishRuntime.newGlassFish(gfProps);
glassfish.start();
habitat = glassfish.getService(ServiceLocator.class);
ServiceLocatorUtilities.addOneConstant(habitat, this);
fileSystem = habitat.getServiceHandle(
"GlassFish Status = {1}", new Object[]{glassfish, glassfish.getStatus()});
} catch (Throwable ex) {
throw new RuntimeException(ex);
代码示例来源:origin: stackoverflow.com
String port = System.getenv("PORT");
GlassFishProperties gfProps = new GlassFishProperties();
gfProps.setPort("http-listener", Integer.parseInt(port));
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(gfProps);
glassfish.start();
Deployer deployer = glassfish.getDeployer();
File file = new File("YourSimpleMavenWebapplication.war");
deployer.deploy(file);
代码示例来源:origin: org.glassfish.main.core/glassfish
@Override
public void stop() throws GlassFishException {
decoratedGf.stop();
}
代码示例来源:origin: com.googlecode.jeeunit/jeeunit-glassfish
private void shutdownInternal() throws GlassFishException {
if (glassFish != null) {
glassFish.getDeployer().undeploy(getApplicationName());
glassFish.stop();
glassFish = null;
}
}
代码示例来源:origin: stackoverflow.com
//Start GF
GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap();
GlassFish gf = gfRuntime.newGlassFish();
gf.start();
//Deploy application with EJBs
Deployer deployer = gf.getService(Deployer.class);
String deployedApp = deployer.deploy(new File(...), "--force=true");
//Create InitialContext
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(props);
//Lookup EJBs
ic.lookup(...)
//Stop GF
gf.stop();
gfRuntime.shutdown();
//CORBA stuck thread, have to kill it manually
System.exit(0);
代码示例来源:origin: eclipse-ee4j/glassfish
@Override
public Deployer getDeployer() throws GlassFishException {
return decoratedGf.getDeployer();
}
代码示例来源:origin: eclipse-ee4j/glassfish
@Override
public <T> T getService(Class<T> serviceType, String serviceName) throws GlassFishException {
return decoratedGf.getService(serviceType, serviceName);
}
代码示例来源:origin: org.glassfish.main.core/glassfish
public void stop(BundleContext context) throws Exception {
if (nonEmbedded) {
System.out.println("We are in non-embedded mode, so " + context.getBundle() + " has nothing to do.");
return;
}
try {
// gf can be null - especially in non-embedded mode.
if (gf != null && gf.getStatus() != GlassFish.Status.DISPOSED) {
gf.dispose(); // dispose calls stop
}
} finally {
gf = null;
}
if (gfr != null) { // gfr is non-null only if this activator has bootstrapped, else it's null.
gfr.shutdown();
gfr = null;
}
}
代码示例来源:origin: org.glassfish.fighterfish/osgi-javaee-base
while ((status = gf.getStatus()) != GlassFish.Status.STARTED) {
if (status == GlassFish.Status.DISPOSED) return;
try {
events = gf.getService(Events.class);
listener = new EventListener() {
public void event(Event event) {
代码示例来源:origin: org.glassfish.main.core/glassfish
@Override
public void dispose() throws GlassFishException {
decoratedGf.dispose();
}
代码示例来源:origin: org.glassfish.main.core/glassfish
@Override
public Status getStatus() throws GlassFishException {
return decoratedGf.getStatus();
}
代码示例来源:origin: org.glassfish.main.core/glassfish
@Override
public CommandRunner getCommandRunner() throws GlassFishException {
return decoratedGf.getCommandRunner();
}
}
内容来源于网络,如有侵权,请联系作者删除!