Browse DevX
Sign up for e-mail newsletters from DevX


Exploring Geronimo's GBean Framework : Page 2

Apache Geronimo is a general runtime execution environment and certified J2EE application server that you can configure to satisfy many different infrastructure requirements.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The Lifecycle of a GBean
Geronimo GBeans handle lifecycle events and maintain states and association dependencies. Geronimo's IoC execution environment revolves around a web of GBeans and relies on being able to query the current state of each GBean. In addition, the execution environment must be able to save the state of each GBean and restore that state as needed. This need is met by the GBean framework's persistence sub-system.

Table 1 shows all the possible lifecycle states a GBean might be in at any given time:

Table 1: The table shows all the possible lifecycle states of a Gbean along with a short description of each.
Lifecycle State Description
Loaded The GBean has been loaded by the Geronimo kernel.
Unloaded The GBean has been unloaded by the Geronimo kernel.
Note: The following states all stem from the JSR 77 StateManageable model.
Starting (from the JSR 77 StateManageable model) The GBean has been requested to start, and is in the process of starting.
Running (from the JSR 77 StateManageable model) This state indicates that the GBean is operational.
Stopping (from the JSR 77 StateManageable model) This state indicates that the GBean has been requested to stop, and is in the process of stopping.
Stopped (from the JSR 77 StateManageable model) This state indicates that the GBean has stopped and can be restarted.
Failed (from the JSR 77 StateManageable model) This state indicates that the GBean has unexpectedly stopped.

The GBean Persistence Framework
The GBean persistence framework enables storing and retrieving GBeans along with their current state to and from permanent storage. You can define each GBean attribute as persistent or non-persistent. Persistent attributes retain their state/value across all instances of the GBean, while non-persistent attributes retain their state/value only during the lifetime of a specific Gbean instance.

By default, the framework persists GBeans persisted to permanent storage in Java serialized format, but Geronimo provides support for third-party storage providers to handle the actual GBean storage.

A Geronimo deployment plan defines a collection of services that can be loaded into a Geronimo execution environment. The components in a deployment plan include information needed to locate classes, parent/child relationships, and a hierarchy of GBean definitions to be loaded. The GBean definitions and the state of all GBeans will be serialized to permanent storage when the artifact defined by the deployment plan is stored.

When a stored deployment artifact is restarted, the persistence framework de-serializes any stored GBeans and restores them to their pre-saved state. After restoring the GBeans, the framework restores their dependencies and references, and then restarts the GBeans.

The GBean Dependency and Reference Manager
When the Geronimo kernel targets a GBean to be loaded, it first loads any dependencies (ancillary GBeans of the target GBean). The GBean dependency manager looks for dependencies declared in a GBean's deployment plan and attempts to load these before loading the target GBean.

After loading and launching a GBean's dependencies, the dependency manager generates references to these dependencies and connects them to the both target GBean and its dependencies. References are proxies to the actual object, ensuring a loose coupling between the target GBean and its dependencies.

It injects these references into a GBean using either getter/setter method injection or constructor-based injection. The following code illustrates how a GBean specifies a reference (BeanRef1) that is to be injected by means of the GBeans constructor:

public class TestGBean implements GBeanLifecycle { private final String AnotherGBean beanRef1; static { GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(TestGBean.class.getName(), TestGBean.class); // attributes infoBuilder.addReferance("BeanRef1", AnotherGBean.class); // operations infoBuilder.setConstructor(new String[] { "BeanRef1" }); GBEAN_INFO = infoBuilder.getBeanInfo(); } public TestGBean(AnotherGBean beanRef1) { this. beanRef1= beanRef1; } ... }

Exposing GBean Meta-information
GBeans provide information to the kernel about their publicly-available attributes, operations, and notifications via the GBeanInfo getGBeanInfo() method. This method returns an instance of the GBeanInfo class; which, by convention, is created within a static initialization block, similar to the following:

public class TestGBean implements GBeanLifecycle { private static final GBeanInfo GBEAN_INFO; static { GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(TestGBean.class.getName(), TestGBean.class); boolean isPersistent = true; // attributes infoBuilder.addAttribute("message", String.class, isPersistent); infoBuilder.addAttribute("createtime", long.class, isPersistent); infoBuilder.addOperation("setMessage", new Class[]{String.class}); infoBuilder.addOperation("getMessage"); infoBuilder.addOperation("setCreatetime", new Class[] {long.class}); infoBuilder.addOperation("getCreatetime"); GBEAN_INFO = infoBuilder.getBeanInfo(); } public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } ... }

If you use a non-default constructor—or if attributes, references, or callable operations are needed—then the GBEAN_INFO static initializer needs to call the methods setConstructor(), addAttribute(), addReference(), and addOperation(), respectively. The example instance doesn't have any special constructors, operations, attributes, or references, so these calls aren't required.

Attributes and references must be compliant with the following naming conventions:

  • Attributes must start with a lower case first character.
  • References must start with an upper case first character.
This simple naming convention should simplify the configuration of a GBean. Keeping this basic framework architecture and conventions in mind, to help fill in the details, the rest of this article shows you how to build an example GBean, integrate it into the Geronimo framework, deploy it to Geronimo, and test it.

Thanks for your registration, follow us on our social networks to keep up-to-date