EasyBeans Logo

Getting started with the embedded EasyBeans for JOnAS J2EE server.

Installing the EasyBeans container in a JOnAS 4.7.x server. (Tested on a 4.7.3)

JDK 5.0

To run the EasyBeans container, a JDK 5.0 is required. A JDK 1.4.x will not work.

Resource Adapter

The EasyBeans container is provided as a .rar file named ow_easybeans_for_jonas.rar which allows to add or remove it in a few steps.
The .rar file needs to be copied into $JONAS_BASE/rars or $JONAS_BASE/rars/autoload directory. By copying the file in $JONAS_BASE/rars/autoload, this allows to start the EasyBeans container when JOnAS is starting.
Note : JONAS_BASE could be replaced by JONAS_ROOT if JONAS_BASE is not defined.

DataSource/JDBC

A datasource with the default name jdbc_1 needs to be present, else the entity bean example will not work. Note that a fresh install of JOnAS is providing this datasource by default.

Examples

The examples provided in this prototype need to be copied in the $JONAS_ROOT/examples/ directory. The resulting directory will be $JONAS_ROOT/examples/ejb3s with subfolders like statelessbean.

Deploying the EasyBeans container in a JOnAS server.

Launching JOnAS

As usual, JOnAS is launched with the jonas start command. Note that a JDK 5.0 is required

Deploying EasyBeans container

If ow_easybeans_for_jonas.rar is in $JONAS_BASE/rars/autoload directory, no configuration is needed, the EasyBeans container has been started when JOnAS was started.

If ow_easybeans_for_jonas.rar is in $JONAS_BASE/rars directory, this module needs to be deployed by using either the JOnAS Admin console (http://localhost:9000/jonasAdmin) or the command line. In this case, the command is the following : jonas admin -a ow_easybeans_for_jonas.rar.

Trying examples.

Stateless Bean

Trying the example

The prototype is bundled with some examples. The first one is a stateless bean

Here are the steps for launching this example :

  1. ant needs to be launched in $JONAS_ROOT/examples/ejb3s/statelessbean directory. This will compile the source code and copy the archive into the $JONAS_BASE/ejb3s/stateless.jar/ directory.
  2. On the server side, some traces will be printed. This is because the EJB3 container has detected a new module in the $JONAS_BASE/ejb3s directory. The bean was loaded automatically.
    Creating container for archive /home/benoitf/jonasbases/jb_trunk/ejb3s/stateless.jar.
         
  3. Then, the client can be executed by running the command ant run.client
    If the client is executed without errors, the output will be :
     run.client:
         [java] Calling helloWorld method...
         [java] Add 1 + 2...
         [java] Sum = '3'.
          

Understanding the example

This example shows the use of JDK 5.0 annotations, the EJB3 interceptors and the EJB3 callbacks.

The SessionBean class is annotated with @Stateless. This means that this class will be used as a stateless session bean.

The method trace is annotated with @AroundInvoke EJB3 annotation. This method will be called at each call on a business method. The business methods are defined in the interface implemented by the SessionBean class.

As a new feature of the EJB3, the interface doesn't need to extend the Remote interface. On the client side, there is no need to do a PortableRemoteObject.narrow() call.

Customizing the example

Some annotations are commented in the session bean example. To discover some new features like interceptors in other classes or the EJB3 callbacks, the comments can be removed and the example compiled again.

New methods can be added in the interface and implemented in the bean class, then the only step to do is to call ant in $JONAS_ROOT/examples/ejb3s/statelessbean directory. The EJB3 container will detect the changes and reload the bean.

Stateful Bean

Trying the example

As for the stateless session bean, the example needs to be compiled and deployed by calling ant in the $JONAS_ROOT/examples/ejb3s/statefulbean directory.

Once the bean is detected by the container and loaded, the client can be launched with ant run.client command.

The output will be :

run.client:
     [java] org.objectweb.jotm.Current <init>
     [java] INFO: JOTM 2.0.11
     [java] Start a first transaction
     [java] First request on the new bean
     [java] Second request on the bean
     [java] Commit the transaction
     [java] Start a second transaction
     [java] Buy 50 amount.
     [java] Rollback the transaction
     [java] after rollback, value = 30
     [java] Request outside any transaction
     [java] Check that value = 30
     [java] ClientStateful OK. Exiting.
      

Understanding the example

The @Stateful annotation is used to mark the bean as a stateful session bean.

State of the stateful session bean is notified by the transactions (default = REQUIRED), as the bean implements the SessionSynchronization interface.

Entity Bean

Trying the example

The example needs to be compiled and deployed by calling ant in the $JONAS_ROOT/examples/ejb3s/entitybean directory.

Once the bean is detected by the container and loaded, the client can be launched with ant run.client command.

Note that Hibernate traces will be displayed as it will manage the Employee entity class.

Understanding the example

This example shows the use of an entity bean and using EJB3 persistence provider which is in this prototype Hibernate. In a next version, the ObjectWeb Speedo product will provide an EJB3 persistence provider, so users will have the choice between these providers.

The Entity class is a POJO class annotated with @Entity. The entities class are managed by the persistence provider, and in this case, by Hibernate.

Message Driven Bean

Trying the example

As usual, ant command needs to be launched in the $JONAS_ROOT/examples/ejb3s/messagedrivenbean directory.

Once the bean is detected by the container and loaded, the client can be launched with ant run.client command.

The output on the server side will be :

      Receiving a message named '((org.objectweb.joram.client.jms.TextMessage...'. with the content 'Message0
      Receiving a message named '((org.objectweb.joram.client.jms.TextMessage...'. with the content 'Message1
      Receiving a message named '((org.objectweb.joram.client.jms.TextMessage...'. with the content 'Message2
      Receiving a message named '((org.objectweb.joram.client.jms.TextMessage...'. with the content 'Message3
      Receiving a message named '((org.objectweb.joram.client.jms.TextMessage...'. with the content 'Message4
      

Understanding the example

The @MessageDriven annotation is used to mark the bean as a message driven bean.

The client send 5 messages on the SampleQueue queue object that are received by the bean and displayed on the output.

Some aspects of EasyBeans design.

Proxy

On the client side, only the EJB3 libraries + bean's remote interface + client code is needed, no needs of the JOnAS***Stub.class, etc.

Bytecode enhancement

The generated code is done by using ASM which is faster than velocity + javac methods.

Automatic class (re)loading

It detects automatically the changes in the class made by the user and reload the bean. This can be tried on the examples provided in this prototype : Change the source code of a class, recompile and the EJB3 container will reload the bean.

Known Limitations.

The security is not yet managed

Some part of the deployment descriptors are not handled. env-entry are handled for example

The extended persistence context is not implemented. The Transaction-Scoped Persistence Context (default) has to be used.

No passivation on stateful

No timeout available

No support for @RemoteHome or @LocalHome backward interfaces

MDB support is partial : No MDB context injection or interceptors

Bugs or comments can be reported on JIRA Issue web site or to the EasyBeans mailing-list available at EasyBeans Mailing-List

Speedo is a product available at http://speedo.objectweb.org and Hibernate is a product available at http://www.hibernate.org

Valid XHTML 1.1