To run the EasyBeans container, a JDK 5.0 is required. A JDK 1.4.x will not work.
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.
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.
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
.
As usual, JOnAS is launched with the jonas start
command. Note that a JDK 5.0 is required
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
.
The prototype is bundled with some examples. The first one is a stateless bean
Here are the steps for launching this example :
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.
$JONAS_BASE/ejb3s
directory. The bean was loaded automatically.
Creating container for archive /home/benoitf/jonasbases/jb_trunk/ejb3s/stateless.jar. Analyze elapsed during : 120 ms Enhancement elapsed during : 93 ms Binding bean org.objectweb.easybeans.examples.statelessbean.StatelessBean with interface org.objectweb.easybeans.examples.statelessbean.StatelessRemote into registry with jndi name org.objectweb.easybeans.examples.statelessbean.StatelessBean@Remote
ant run.client
run.client: [java] Calling helloWorld method... [java] Add 1 + 2... [java] Sum = '3'.
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. The signature of the @AroundInvoke
method when it is defined in the bean class, needs to be public Object xxxx(final InvocationContext invocationContext) throws Exception
, xxx being the name of the method.
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.
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.
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.
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.
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.
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.
On the client side, only the EJB3 libraries + bean's remote interface + client code is needed, no needs of the JOnAS***Stub.class, etc.
The generated code is done by using ASM which is faster than velocity + javac methods.
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.
This container is at an early stage and all functions are not yet implemented. Also the specification is still evolving and some parts will change in the final specification.
This prototype is provided as this and should not be used for a production environment. It demonstrates the new architecture of the EasyBeans container and the use of ASM for bytecode injection.
It is interesting to have the user feedback for the EOD aspect which is wanted by this new specification, EOD means Ease Of Development
As some requests found on the mailing list, on the client side, only the EJB3 libraries + bean's remote interface + client code is needed, no needs of the ***Stub.class, etc.
The generated code is done by using ASM which is faster than velocity + javac methods, so the "GenIC" step is very quick.
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.
The security is not yet managed
The deployment descriptors are not handled
No context are available by the beans (getEJBContext()).
The link with the persistence provider is very basic. So all persistence context types are not handled. For example, close() method should not be used on injected entity manager, etc.
Resource injection : Only one resource injection is handled, this is the persistence context (there is an example in the entitybean example). No @EJB or @Resource annotation is taken into account.
No passivation on stateful and no remove
No timeout available
No support for @RemoteHome or @LocalHome backward interfaces
No checks on the methods type. So if a user define an interceptor with an invalid signature, the generated bytecode will fail.
Some items are missing so please do not report them, we are aware of the limitations.