Contents
Editorial
Executive opinion
Hot topics
Business cases
Experts voice
Solutions
Quick Poll
Events
At a glance
PDF version
 

Subscribe to
Bull Direct:

Your email

Archives
April 2006
Experts voice

With EasyBeans: the simplest way to benefit from the power of Java EE 5.0!
By Florent Benoit, Systems Architect and Developer, Bull R&D

In this article Florent, who manages the EasyBeans project hosted by ObjectWeb, details the biggest challenges in the evolution of Enterprise Java Beans (EJB) and Bull/ObjectWeb’s contribution: EasyBeans.

 
Having first appeared about eight years ago, J2EE technology has now established itself as an essential industry standard in major business application development. A powerful yet complex technology, its use has nevertheless tended to be confined to developers ‘in the know’. So until now, many companies haven’t hesitated to use lightweight components such as Spring, Struts or Apache’s Hivemind to replace J2EE services. They also have recourse to Hibernate or JDO systems (Apache’s OJB) of database interfaces. With the next version to come on stream – Java EE 5.0 – J2EE is moving towards delivering significant solutions to these constraints and finally simplifying the deployment of distributed components, or Enterprise Java Beans (EJBs). Bull and the ObjectWeb consortium are playing their part in developing the J2EE specification, via the Java Community Process (JCP), and have decided to develop an initial, extremely open implementation of the new EJB3 specification, EasyBeans, in Open Source. The aim is to enable J2EE developers to increase the speed of projects and offer developers using other environments the opportunity to find out about all the power and openness offered by J2EE – with or without an application server – as simply as possible.
 

Today, the majority of major enterprise applications are moving towards being interoperable and centralized. In order to facilitate their development, implementation and operation, they are increasingly being brought together using application servers or application frameworks, which offer a robust technical infrastructure that enables IT departments to concentrate their efforts on the business functionality. The leading application servers on the market use J2EE technology (Java world), but other competing frameworks are available such as Microsoft’s.Net technology, Zope with the Python language and Ruby On Rails, not forgetting the PHP language.

J2EE: the standard platform for large-scale distributed applications
Nearly a decade after it was first developed, J2EE technology has now claimed the position as the industry standard: interoperable, standardized, supported by a majority of software publishers, it is particularly well suited to robust, distributed transactional applications. The main advantage of J2EE servers is their multi-platform architecture, linked to the use of the Java development language. The J2EE platform also enables applications to be ported from one server to another. What’s more, the entire application life cycle is covered, from development to assembly, implementation and administration.
The J2EE architecture is made up of a number of different parts. The business part and the database interface (‘persistence’) is developed on the server using EJBs (distributed transactional components), whose specification ensures the transactional integrity of the data being accessed, ACID properties ( Atomic, Consistent, Isolation, and Durable ) and the presentation part with Servlets/Java Server Pages (JSPs), which generate the HTML code that is posted on Web browsers (thin clients). There are also ‘thick clients’ with a much richer interface, but which require client-side libraries.
EJB components can support a variety of tasks, such as verifying a credit on an account, calculating a VAT rate or accessing a database of tariffs. They are designed to be portable and reusable on any kind of Java application server. In production, EJBs are executed in ‘containers’ managed by application servers. These containers perform the technical tasks and communications between EJBs, enabling developers to focus their efforts on the functional aspects of the code.

The limitations of J2EE: complexity
Although Java and J2EE have been extremely successful for a number of years – because they offer such a powerful solution for critical distributed applications – these technologies are nevertheless seen as complex and reserved only for experienced developers. One example is the creation of an EJB. Up to and including version 1.4 of J2EE, in order to create a business object or EJB, it was necessary to write XML files (a standard file and a specific file for each application server), as well as several classes and Java interfaces. And EJBs did not offer any simple mechanisms for accessing relational data and holding it in memory. Which is why a major development effort was required, holding back the widespread adoption of this sub-set of the J2EE specification, although a number of additional tools did start to appear that simplified the life of J2EE developers, such as XDoclet [http://www.xdoclet.org] for more rapid creation of EJBs and Hibernate [http://www.hibernate.org] to simplify persistence.
So until now, many organizations have chosen to use a pure Java framework to replace complex J2EE services. They substitute lightweight containers such as Spring, Struts or Apache’s Hivemind for EJBs, and also use persistence systems such as Hibernate or JDOs (Apache’s OJB for example).

Java EE 5 and EJB3: a much simpler approach to development
The forthcoming version of J2EE – Java EE 5.0 – has been designed to respond to these constraints and at last simplify the process of implementing EJBs. Thanks to the use of meta-data, the code is directly annotated without needed to pass through an external (XML) file. For example, to define an EJB the class declaration would be prefixed with ‘@Stateless’ if it is a stateless EJB. Deployment descriptors (XML) become obsolete, even though they are still supported. Persistence will involve all Java objects and will be just as easy to build thanks to the new annotation concept introduced as part of Java 5. In particular, EJB3s will offer a persistence model very like that used by Hibernate. This involves using standard objects or POJOs (Plain Old Java Objects). A basic object is created, values are attached to it, and finally – to make it persistent – it is sent to another object charged with managing persistence, known as an EntityManager: entityManager.persist (entityBean); and the object is then stored in a database. The EJB3 specification is in the last stage of being finalized; the official version is due to be launched at the annual JavaOne 2006 conference, being held this year in May. To implement the draft specification and enable developers to use it to simplify their developments, so far only proprietary or semi-proprietary solutions have appeared on the market in the last few months: Oracle EJB3 and JBoss EJB3.

EasyBeans: the first true Open Source implementation of EJB3
Having been involved in developing the J2EE specification (formerly Java EE) via the Java Community Process (JCP), and now that the EJB3 specification has been stabilized, Bull and ObjectWeb have decided to develop the first Open Source implementation of EJB3: EasyBeans. [http://www.easybeans.org]

EasyBeans is the first truly open-source implementation of the EBJ3.0 container. It is designed to interface with third-party solutions to ensure persistence, such as ObjectWeb’s own Speedo and Hibernate. Other implementations of the persistence element will be able to embed in EasyBeans (for example OpenJPA, which BEA has provided in Open Source format), with the EJB3 specification defining an API for exchanges between the two components (the container and the persistence provider).

EasyBeans has been specifically designed to be easy to use, to speed up development but also make it simple and modular, in response to the growing demand for lightweight containers.

An advanced technique: bytecode injection
One advanced technique used intensively by EasyBeans is ‘bytecode injection'. In the Java language, the source code of an object class is transformed into a.class file during compilation. This file contains the instruction set (bytecode) that the interpreter (JVM or Java Virtual Machine) will interpret and run. With the bytecode injection technique, it is possible to manipulate the object’s bytecode and so add to, modify or delete class attributes or methods, or even generate an entire class. This delivers much better performance than having to create a Java source file and then compile it, because you’re directly modifying the object. Apart from the performance considerations, this also enables greater dynamism (because there is no pre-implementation phase to carry out), but is also totally transparent to the user. This bytecode modification has been enabled with the assistance of ObjectWeb’s ASM project [http://asm.objectweb.org]. An example is shown below*.

A simple response to facilitate Java developments, with or without an application server
By implementing a stabilized version of the new EJB3 specification, EasyBeans should rekindle some interest in using EJBs, as it offers developers a way to create their distributed transactional applications that is both very simple and very powerful.
Naturally, EasyBeans is integrated into and available as part of the JOnAS application server, hosted by ObjectWeb and to which Bull is the major contributor. But it is also possible to use EasyBeans directly for more lightweight, standalone applications or those using partial J2EE servers such as Tomcat [http://tomcat.apache.org] (integration with Tomcat will be available within the next few weeks).
So EasyBeans offers J2EE developers the chance to speed up their projects, and allows other developers to discover all the power and openness of J2EE for the first time.

A complete explanatory guide is available on line: http://www.easybeans.org/GettingStarted/GettingStarted.html, as well as a user and developer guide enabling contributions to be made to the project.
The best way to find out more about EJB3 is to download EasyBeans and find out for yourself just how easy it is to use for development.
Project URL: http://www.easybeans.org
Downloads: http://www.easybeans.org/download.html
Documentation: http://wiki.easybeans.objectweb.org/xwiki/bin/Main/Documentation

*Using bytecode manipulation: a concrete example
With EJB3s, one of the new features is ‘dependency injection’. The bean requests the container that will run it to inject dependencies. Injecting a dependency involves initializing the attributes of a class with objects that access external resources such as databases or transactions. Before, the bean itself would have had to search for the resource.
An example of injection is the declaration of a variable enabling access to a particular database. This variable is of the Java javax.sql.DataSource type.
All that’s needed is to add an annotation to an attribute in the EJB3 code, and the container will then know that it has to inject the dependency.
For example: @Resource(name="database") private DataSource dataSource. With the annotation being @Resource.
So via the ASM tool, EasyBeans injects a new method into the bean, called for example injectedByEasyBeans(), and that method initializes the DataSource-type object. For every annotation that requires the injection of a dependency, an instruction is added to the method generated by EasyBeans. So the container only has to instantiate the object and then call the injectedByEasyBeans() method, and the bean will have all its attributes initialized. And no Java file has been generated, the object supplied by the developer

 

Contact  |  Site map  |  Legal  |  Privacy