July 29, 2004
Here's a new idea for an open source project I'd like to start. It could be
called CCI (Container Client Interface). It would aim at providing a simple
Java API to start/stop/configure/deploy Java containers (In the first version
the goal would be to support J2EE containers). This Java API could then be used
by lots of other projects (Ant tasks, Maven plugins, IDE plugins, Cactus, etc).
The inspiration comes from the Cactus project, which already provides an extensive
API to perform such tasks. The goal is to refactor the Cactus Ant API, remove
anything related to Cactus and make it a standalone project called CCI
Here's an integraton test showing what the API could look like:
public void testStartWithOneWarDeployed()
{
Container container = new Resin3xContainer();
container.setHomeDir("/apps/resin-3.0.8");
container.setPort(8080);
container.setInstallDir(new File("target/resin3x"));
WAR war = new WAR("src/testinput/simple.war");
URL pingURL = new URL("http://localhost:" + PORT + "/simple/index.html");
war.setPingURL(pingURL);
container.addDeployable(war);
ContainerRunner runner = new DefaultContainerRunner(container);
runner.start();
assertTrue("Container not started yet!", new HttpUtils().ping(pingURL));
runner.stop();
assertFalse("Container not stopped yet!", new HttpUtils().ping(pingURL));
}
As you can see there are several main Objects/Interfaces:
- Container: This the main object that provides the API to
start/stop the container.
- WAR: A WAR archive to be deployed in the container. Inherits
from Deployable. There will be other types later on (WAR,
EAR, RAR)
- ContainerRunner: Athough a container can be start ed without
a container runner, the container runner provides advanced feature like starting
the container in a different thread, verifying if the container is already
started, waiting till the container is started, waiting till the container
is stopped, etc.
Note that the ping URLs are the URLs that will be pinged by the ContainerRunner
object to ensure the container has finished starting. Thus, after container.start()
has finished executing you can be sure the container is started and the archives
have been deployed and are ready for servicing requests. A better solution in
the future will be to use JMX to ensure the container has finished starting.
However, all containers do not yet support this feature.
A shorthand code version to start Resin 3.0.8 could look like:
Container container = new Resin3xContainer("/apps/resin-3.0.8");
container.setInstallDir("target/resin3x");
container.addDeployable(new WAR("src/testinput/simple.war"));
container.start();
This is just a taste of what he CCI API could look like. Let me know what you
think!
About the author
Vincent Massol
vmassol@pivolis.com
Blog: http://blogs.codehaus.org/people/vmassol/
Vincent Massol is the creator of the Jakarta Cactus framework. In addition to being an active member of the Maven development team, he has also written the JUnit in Action book. After having spent four years as a technical architect on several major projects (mostly J2EE), Vincent is now the co-founder and CTO of Pivolis, a company specialized in applying agile methodologies to offshore software development. A consultant and lecturer during the day and open source developer at night, Vincent currently lives in Paris, France. He can be contacted through his blog at http://blogs.codehaus.org/people/vmassol/.
|