Package org.glassfish.internal.embedded
Class Server
- java.lang.Object
-
- org.glassfish.internal.embedded.Server
-
@Contract public class Server extends Object
Instances of server are embedded application servers, capable of attaching various containers (entities running users applications).- Author:
- Jerome Dochez
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Server.Builder
Builder for creating embedded server instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContainer(ContainerBuilder.Type type)
Adds a container of a particular type using the default operating configuration for the container.<T extends EmbeddedContainer>
TaddContainer(ContainerBuilder<T> info)
Adds a container to this server.<T extends ContainerBuilder<?>>
TcreateConfig(Class<T> configType)
Get an embedded container configuration.ContainerBuilder<EmbeddedContainer>
createConfig(String name)
Get the embedded container builder for a container type identified by its name.ContainerBuilder<EmbeddedContainer>
createConfig(ContainerBuilder.Type type)
Get the embedded container configuration for a container type.Port
createPort(int portNumber)
Creates a port to attach to embedded containers.Collection<EmbeddedContainer>
getContainers()
Returns a list of the currently managed containersEmbeddedDeployer
getDeployer()
Returns the embedded deployer implementation, can be used to generically deploy applications to the embedded server.EmbeddedFileSystem
getFileSystem()
Returns the embedded file system used to run this embedded instance.String
getName()
Returns the server name, as specified inBuilder(String)
static Server
getServer(String name)
Returns the embedded server instance of a particular namestatic List<String>
getServerNames()
Returns the list of existing embedded instancesvoid
start()
Starts the embedded server, opening ports, and running the startup services.void
stop()
stops the embedded server instance, any deployed application will be stopped ports will be closed and shutdown services will be ran.
-
-
-
Method Detail
-
getServerNames
public static List<String> getServerNames()
Returns the list of existing embedded instances- Returns:
- list of the instanciated embedded instances.
-
getServer
public static Server getServer(String name)
Returns the embedded server instance of a particular name- Parameters:
name
- requested server name- Returns:
- a server instance if it exists, null otherwise
-
createConfig
public ContainerBuilder<EmbeddedContainer> createConfig(ContainerBuilder.Type type)
Get the embedded container configuration for a container type.- Parameters:
type
- the container type (e.g. Type.ejb)- Returns:
- the embedded configuration for this container
-
createConfig
public ContainerBuilder<EmbeddedContainer> createConfig(String name)
Get the embedded container builder for a container type identified by its name.- Parameters:
name
- the container name, which is the name used on the @Service annotation- Returns:
- the embedded builder for this container
-
createConfig
public <T extends ContainerBuilder<?>> T createConfig(Class<T> configType)
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.- Type Parameters:
T
- type of the embedded container- Parameters:
configType
- the type of the embedded container configuration- Returns:
- the configuration to configure a container of type
-
addContainer
public void addContainer(ContainerBuilder.Type type)
Adds a container of a particular type using the default operating configuration for the container.- Parameters:
type
- type of the container to be added (like web, ejb).- Throws:
IllegalStateException
- if the container is already started.
-
addContainer
public <T extends EmbeddedContainer> T addContainer(ContainerBuilder<T> info)
Adds a container to this server. Using the configuration instance for the container of type, creating the container from that configuration and finally adding the container instance to the list of managed containers - Type Parameters:
T
- type of the container- Parameters:
info
- the configuration for the container- Returns:
- instance of the container
- Throws:
IllegalStateException
- if the container is already started.
-
getContainers
public Collection<EmbeddedContainer> getContainers()
Returns a list of the currently managed containers- Returns:
- the containers list
-
createPort
public Port createPort(int portNumber) throws IOException
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.- Parameters:
portNumber
- port number for this port- Returns:
- a new port abstraction.
- Throws:
IOException
- if the port cannot be opened.
-
getName
public String getName()
Returns the server name, as specified inBuilder(String)
- Returns:
- container name
-
getFileSystem
public EmbeddedFileSystem getFileSystem()
Returns the embedded file system used to run this embedded instance.- Returns:
- embedded file system used by this instance
-
start
public void start() throws LifecycleException
Starts the embedded server, opening ports, and running the startup services.- Throws:
LifecycleException
- if the server cannot be started propertly
-
stop
public void stop() throws LifecycleException
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
-
getDeployer
public EmbeddedDeployer getDeployer()
Returns the embedded deployer implementation, can be used to generically deploy applications to the embedded server.- Returns:
- embedded deployer
-
-