/** * 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); }
/** * 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"); } }
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);
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) {
gf.start(); CommandRunner cr = gf.getCommandRunner(); gf.stop(); gf.dispose(); } catch (Exception ex) {
glassFish.start(); deployer = glassFish.getDeployer(); ScatteredArchive archive = new ScatteredArchive("glassfish-ejb-validation", Type.JAR); archive.addClassPath(new File("target", "classes")); glassFish.stop(); glassFish.dispose();
@Override public void start() throws GlassFishException { decoratedGf.start(); }
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);
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);
@Override public void stop() throws GlassFishException { decoratedGf.stop(); }
private void shutdownInternal() throws GlassFishException { if (glassFish != null) { glassFish.getDeployer().undeploy(getApplicationName()); glassFish.stop(); glassFish = null; } }
//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);
@Override public Deployer getDeployer() throws GlassFishException { return decoratedGf.getDeployer(); }
@Override public <T> T getService(Class<T> serviceType, String serviceName) throws GlassFishException { return decoratedGf.getService(serviceType, serviceName); }
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; } }
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) {
@Override public void dispose() throws GlassFishException { decoratedGf.dispose(); }
@Override public Status getStatus() throws GlassFishException { return decoratedGf.getStatus(); }
@Override public CommandRunner getCommandRunner() throws GlassFishException { return decoratedGf.getCommandRunner(); } }