Home > Documentation > Reference > Geronimo Architecture > GBeans > Developing and Deploying a Geronimo GBean |
Geronimo is a system framework that can be used to build a variety of tailored infrastructure services, with GBean providing it with a loosely-coupled and configurable runtime environments. GBean is an implementation of Inversion of Control (IoC), or the dependency injection, which allows the automatic injection of references as they become available. This tutorial is organized as follows:
The Geronimo kernel is a framework for kernel services, and controls the basic server components with the following services:
The basic server componenets, namely security, logging, transactions, and naming, work with the kernel services to build Java EE server components, such as Tomcat, Jetty, and OpenEJB. All these components, cooperate with the kernel to support Java EE applications.
Almost everything in Geronimo is a GBean: containers, connectors, adapters, applications and so on. A GBean is an atomic unit in Geronimo, consisting of the implementation classes (.jar) and a plan.
The plan is a configuration file through which a GBean relies on the kernel for IoC and dependency injection at runtime. Dependencies on other GBeans can be configured through the attributes and references in plans. Geronimo's configuration builders construct GBeans out of these plans, group them as configurations, and store them in the configuration store.
A configuration is a logically coupled collection of one or more GBeans and a classloader. The configurations are loaded with the server. The configuration store is the standard Geronimo storage mechanism.
Applications that run in a Java EE container, described by custom deployment descriptors and Java classes, will be parsed and converted into GBeans by the configuration builders of the Geronimo Deployer. These GBeans are also stored in the configuration store.
A GBean can be in any of the three states: stored, loaded, or running.
To participate in the life cycle operations, GBeans implement a GBeanLifecycle interface. This interface defines three methods, doStart()
, doStop()
and doFail()
.
doStart()
method is used to start the GBean, and implement the GBean operations. It should not be used when the GBean is in a failed state.doFail()
method is executed when the GBean fails to start, run or stop. It marks the GBean as failed, and always calls doStop() to stop it.doStop()
menthods stops the GBean.
The class for a GBean should implement specific methods to support each feature of the GBean:
For developing a GBean, you at least have to go through the following steps:
The sample GBean SimpleServerGBean simply starts a socket on the Geronimo server, and retrieves the name of the GBean and the socket port. The following code snippet implements the Plain Old Java Object (POJO) section:
In the following code snippet, the GBean exposes its attributes, operations, interfaces and constructor for the GBEAN_INFO static initializer.
The SimpleServerGBean Gbean is simple to start up and shutdown. During startup, it simply accepts an incoming socket connection requests, and sends out the echo message. When being stopped, the GBean closes the resouces that it consumes.
For this sample, we still need a class to test the SimpleServerGBean. This section creates a socket and sends a connection request to the SimpleServerGBean. After the connection has been established, it sends out messages and retrieves the echo message from the simpleServerGBean server instance.
Before deploying your GBean, you still have to compile the GBean class and build a proper .jar file. Maven is used to build Geronimo, so it can be used to build your GBean project. You have to write a pom.xml
file. See Maven website for more information about the file.
In the POM file above,
Follow these steps to deploy your GBean to Geronimo.
GroupId/ArtifactId/Version/ArtifactId-Version.Type
<GERONIMO_HOME>/repository/org/apache/geronimo/sample/simpleServer/1.0/simpleServer-1.0.jar
GroupID/ArtifactID/Version/Type
. In this example, The module ID will be org.apache.geronimo.sample/simpleServer/1.0/car
.org.apache.geronimo.sample/simpleServer/1.0
.Note: If a GBean implementation (possibly a .jar) already exisits in the Geronimo server, you only need to develop a deployment plan and deploy it to the server for the GBean instance to work.
Other GBeans can be used in a GBean by injecting Reference methods. For instance, the GBean SimpleServerGBean can make use of another GBean named EchoMessageGBean with its POJO class and GBeanInfo implemented like the following:
This EchoMessageGBean does not implement GbeanLifecycle for simplicity. It only exposes an interface EchoMessageInterface which retrieves predefined echo messages.
To reference the EchoMessageGBean in SimpleServerGBean, the following steps have to be taken:
The GBean SimpleServerGBean can reference different instances of EchoMessageGBean. For instance, the SimpleServerGBean listens on port 7778 instead, and gets messages from the instance msgAppender2.
When we deploy this plan (The .jar file does not have to be changed), the test class which starts a socket on port 7778 will gets the reponse from server 2.
When Geronimo starts, the <GERONIMO_HOME>/bin/server.jar
is executed with org.apache.geronimo.cli.daemon.DaemonCLI
as the main class. This will boot the Geronimo kernel, and load initial GBeans from module j2ee-system-2.1.3.car
into the kenel.
Bookmark this on Delicious Digg this | Privacy Policy - Copyright © 2003-2011, The Apache Software Foundation, Licensed under ASL 2.0. |