/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* 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
* 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.
*/
/**
* Instances of server are embedded application servers, capable of attaching various containers
* (entities running users applications).
*
* @author Jerome Dochez
*/
public class Server {
/**
* Builder for creating embedded server instance. Builder can be used to configure
* the logger, the verbosity and the embedded file system which acts as a
* virtual file system to the embedded server instance.
*/
public static class Builder {
boolean loggerEnabled;
boolean verbose;
/**
* Creates an unconfigured instance. The habitat will be obtained
* by scanning the inhabitants files using this class's classloader
*
* @param id the server name
*/
this.serverName = id;
}
/**
* Enables or disables the logger for this server
*
* @param enabled true to enable, false to disable
* @return this instance
*/
return this;
}
/**
* Sets the log file location
*
* @param f a valid file location
* @return this instance
*/
loggerFile = f;
return this;
}
/**
* Turns on of off the verbose flag.
*
* @param b true to turn on, false to turn off
* @return this instance
*/
this.verbose = b;
return this;
}
/**
* Set the jmx port number. Also enables the jmx connector. This applies
* only when the default configuration is being used.
*
* @param portNumber jmx port number.
* @return this instance
*/
this.jmxPort = portNumber;
return this;
}
/**
* Sets the embedded file system for the application server, used to locate
* important files or directories used through the server lifetime.
*
* @param fileSystem a virtual filesystem
* @return this instance
*/
this.fileSystem = fileSystem;
return this;
}
/**
* Uses this builder's name to create or return an existing embedded
* server instance.
* The embedded server will be using the configured parameters
* of this builder. If no embedded file system is used, the embedded instance will use
* a temporary instance root with a default basic configuration. That temporary instance
* root will be deleted once the server is shutdown.
*
* @return the configured server instance
*/
}
/**
* Uses this builder's name to create or return an existing embedded
* server instance.
* The embedded server will be using the configured parameters
* of this builder. If no embedded file system is used, the embedded instance will use
* a temporary instance root with a default basic configuration. That temporary instance
* root will be deleted once the server is shutdown.
*
* @param properties extra creation properties
*
* @return the configured server instance
*/
synchronized(servers) {
return s;
}
throw new IllegalStateException("An embedded server of this name already exists");
}
}
}
private final static class ContainerStatus {
private boolean isStopped() {
return status==0;
}
private boolean isStarted() {
return status==1;
}
}
private final static class Container {
boolean started;
}
}
private final boolean loggerEnabled;
private final boolean verbose;
private final int jmxPort;
if (installRoot != null) {
}
}
}
if (instanceRoot != null) {
}
}
if (fs.autoDelete) {
}
}
// TODO :: Support modification of jmxPort
}
try {
if(properties == null) {
properties = new Properties();
}
fsBuilder.autoDelete(true);
}
// Add the neccessary inhabitants.
throw new RuntimeException(ex);
}
}
/**
* Returns the list of existing embedded instances
*
* @return list of the instanciated embedded instances.
*/
return names;
}
/**
* Returns the embedded server instance of a particular name
*
* @param name requested server name
* @return a server instance if it exists, null otherwise
*/
}
// todo : have the same name, and make it clear we use the type string().
/**
* Get the embedded container configuration for a container type.
* @param type the container type (e.g. Type.ejb)
* @return the embedded configuration for this container
*/
}
/**
* Get the embedded container builder for a container type identified by its
* name.
* @param name the container name, which is the name used on the @Service annotation
* @return the embedded builder for this container
*/
@SuppressWarnings("unchecked")
}
/**
* Get an embedded container configuration. The type of the expected
* configuration is passed to the method and is not necessarily known to
* the glassfish embedded API. This type of configuration is used for
* extensions which are not defined by the core glassfish project.
*
* The API stability of the interfaces returned by this method is outside the
* scope of the glassfish-api stability contract, it's a private contract
* between the provider of that configuration and the user.
*
* @param configType the type of the embedded container configuration
* @param <T> type of the embedded container
* @return the configuration to configure a container of type <T>
*/
}
/**
* Adds a container of a particular type using the default operating
* configuration for the container.
*
* @param type type of the container to be added (like web, ejb).
* @throws IllegalStateException if the container is already started.
*/
throw new IllegalStateException("Cannot add container to a started embedded instance");
}
synchronized(sniffers) {
}
}
} else {
}
}
}
}
return sniffers;
}
}
}
if (b!=null) {
} else {
return new Container(new EmbeddedContainer() {
if (s!=null) {
}
return sniffers;
}
}
public void start() throws LifecycleException {
}
public void stop() throws LifecycleException {
}
});
}
}
public void start() throws LifecycleException {
if (!c.started) {
c.started=true;
}
}
}
public void stop() throws LifecycleException {
if (c.started) {
c.started=false;
}
}
}
}));
}
// todo : clarify that adding containers after the server is created is illegal
// todo : makes the return of those APIs return void.
/**
* Adds a container to this server.
*
* Using the configuration instance for the container of type <T>,
* creating the container from that configuration and finally adding the
* container instance to the list of managed containers
*
* @param info the configuration for the container
* @param <T> type of the container
* @return instance of the container <T>
* @throws IllegalStateException if the container is already started.
*/
throw new IllegalStateException("Cannot add containers to an already started embedded instance");
}
return container;
}
return null;
}
/**
* Returns a list of the currently managed containers
*
* @return the containers list
*/
for (Container c : containers) {
}
return copy;
}
/**
* Creates a port to attach to embedded containers. Ports can be attached to many
* embedded containers and some containers may accept more than one port.
*
* @param portNumber port number for this port
* @return a new port abstraction.
* @throws IOException if the port cannot be opened.
*/
}
/**
* Returns the configured habitat for this server.
*
* @return the habitat
*/
return habitat;
}
/**
* Returns the server name, as specified in {@link Server.Builder#Builder(String)}
*
* @return container name
*/
return serverName;
}
/**
* Returns the embedded file system used to run this embedded instance.
*
* @return embedded file system used by this instance
*/
return fileSystem.get();
}
/**
* Starts the embedded server, opening ports, and running the startup
* services.
*
* @throws LifecycleException if the server cannot be started propertly
*/
try {
}
} catch (GlassFishException e) {
throw new LifecycleException(e); // TODO(Sahoo): Proper Exception Handling
}
}
}
/**
* stops the embedded server instance, any deployed application will be stopped
* ports will be closed and shutdown services will be ran.
* EmbeddedFileSystem will be released, meaning that any managed directory will
* be deleted rendering the EmbeddedFileSystem unusable.
*
* @throws LifecycleException if the server cannot shuts down properly
*/
try {
}
if (glassfishRuntime != null) {
}
} finally {
synchronized(servers) {
}
}
}
/**
* Returns the embedded deployer implementation, can be used to
* generically deploy applications to the embedded server.
*
* @return embedded deployer
*/
}
}