Oracle GlassFish Server 3.0.1 Add-On Component Development Guide

Implementing the Container Interface

The org.glassfish.api.container.Container interface is the contract that defines a container implementation. Classes that implement Container can extend or replace the functionality in GlassFish Server by allowing applications to be deployed and run within the GlassFish Server runtime.

The Container interface consists of two methods, getDeployer and getName. The getDeployer method returns an implementation class of the org.glassfish.api.deployment.Deployer interface capable of managing applications that run within this container. The getName method returns a human-readable name for the container, and is typically used to display messages belonging to the container.

The Deployer interface defines the contract for managing a particular application that runs in the container. It consists of the following methods:

getMetaData

Retrieves the metadata used by the Deployer instance, and returns an org.glassfish.api.deployment.MetaData object.

loadMetaData

Loads the metadata associated with an application.

prepare

Prepares the application to run in GlassFish Server.

load

Loads a previously prepared application to the container.

unload

Unloads or stops a previously loaded application.

clean

Removes any artifacts generated by an application during the prepare phase.

The DeploymentContext is the usual context object passed around deployer instances during deployment.


Example 7–1 Example Implementation of Container

This example shows a Java programming language class that implements the Container interface and is capable of extending the functionality of GlassFish Server.

package com.example.containers;
contains
@Service(name="com.example.containers.MyContainer")
public class MyContainer implements Container {
	public String getName() {
		return "MyContainer";
	}

	public Class<? extends org.glassfish.api.deployment.Deployer> getDeployer() {
		return MyDeployer.class;
	}
}


Example 7–2 Example Implementation of Deployer

package com.example.containers;

@Service
public class MyDeployer {

	public MetaData getMetaData() {
		return new MetaData(...);
	}

	public <V> v loadMetaData(Class<V> type, DeploymentContext dc) {
		...
	}

	public boolean prepare(DeploymentContext dc) {
		// performs any actions needed to allow the application to run, 
		// such as generating artifacts
		...
	}

	public MyApplication load(MyContainer container, DeploymentContext dc) {
		// creates a new instance of an application
		MyApplication myApp = new MyApplication (...);
		...
		// returns the application instance
		return myApp;
	}

	public void unload(MyApplication myApp, DeploymentContext dc) {
		// stops and removes the application 
		...
	}

	public void clean (DeploymentContext dc) {
		// cleans up any artifacts generated during prepare()
		...
	}
}