Class 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
    • 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 in Builder(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