|
Glassfish example source code file (GlassFish.java)
The Glassfish GlassFish.java source code/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.embeddable;
/**
* Represents a GlassFish instance and provides the ability to:
*
* <ul>
* <li> perform life cycle operations viz., start, stop and dispose.
* <li> access {@link Deployer} to deploy/undeploy applications.
* <li> access {@link CommandRunner} to perform runtime configurations.
* <li> access to available service(s).
* </ul>
*
* <p/> Usage example:
*
* <style type="text/css">
.ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
.s0 { color: rgb(128,128,128); }
.s1 { }
.s2 { color: rgb(0,0,255); }
.s3 { color: rgb(128,128,128); font-weight: bold; }
.s4 { color: rgb(255,0,255); }
</style>
*
* <pre>
<span class="s0">
/** Create and start GlassFish */</span>
{@link GlassFish} glassfish = {@link GlassFishRuntime}.bootstrap().newGlassFish();
glassfish.start();
</span>/** Deploy a web application simple.war with /hello as context root. */
{@link Deployer} deployer = glassfish.getService(Deployer.</span>class);
String deployedApp = deployer.deploy(</span>new File("simple.war").toURI(),
</span>"--contextroot=hello", "--force=true");
</span>/** Run commands (as per your need). Here is an example to create a http listener and dynamically set its thread pool size. */
{@link CommandRunner} commandRunner = glassfish.getService(CommandRunner.</span>class);
<span class="s0">// Run a command create 'my-http-listener' to listen at 9090
{@link CommandResult} commandResult = commandRunner.run(
</span>"create-http-listener", "--listenerport=9090",
</span>"--listeneraddress=0.0.0.0", "--defaultvs=server",
</span>"my-http-listener");
</span>// Run a command to create your own thread pool
commandResult = commandRunner.run(</span>"create-threadpool",
</span>"--maxthreadpoolsize=200", "--minthreadpoolsize=200",
</span>"my-thread-pool");
</span>// Run a command to associate my-thread-pool with my-http-listener
commandResult = commandRunner.run(</span>"set",
</span>"server.network-config.network-listeners.network-listener." +
</span>"my-http-listener.thread-pool=my-thread-pool");
</span>/** Undeploy the application */
deployer.undeploy(deployedApp);
</span>/**Stop GlassFish.*/
glassfish.stop();
</span>/** Dispose GlassFish. */
glassfish.dispose();
* </pre>
*
* @author Sanjeeb.Sahoo@Sun.COM
*/
public interface GlassFish {
/**
* Start GlassFish.
* When this method is called, all the lifecycle (aka startup) services are started.
* Calling this method while the server is in {@link Status#STARTED} state is a no-op.
*
* @throws {@link IllegalStateException} if server is already started.
* @throws GlassFishException if server can't be started for some unknown reason.
*/
void start() throws GlassFishException;
/**
* 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 in {@link Status#STARTED} state is a no-op.
*
* @throws {@link IllegalStateException} if server is already stopped.
* @throws GlassFishException if server can't be started for some unknown reason.
*/
void stop() throws GlassFishException;
/**
* 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 except {@link #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.
*/
void dispose() throws GlassFishException;
/**
* Get the current status of GlassFish.
*
* @return Status of GlassFish
*/
Status getStatus() throws GlassFishException;
/**
* 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.
* @param serviceType type of component required.
* @param <T>
* @return Return a service matching the requirement, null if no service found.
*/
<T> T getService(Class
Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish GlassFish.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.