Getting Started with Enterprise Java Beans
This is the second part of a two part series introducing the Enterprise Java Bean. In part one I introduced the EJB concept and how it is used to encapsulate business logic and I talked about the two flavors of EJBs: Session beans and Message Driven beans. In this part, I will introduce the idea of bean access and talk about the three modes of access.
Three Bean Access Modes
EJBs can be classed into three access modes depending on the access afforded to the client.
The default mode is local access. This means the bean cannot be accessed over the network but only from within the container itself. The remote mode means that an EJB can be accessed by an external application and web service mode means that the EJB can be accessed by the client using the web service as the protocol.
Access mode is specified by the annotation.
The management mode determines who is responsible for configuring the beans services. By default, the container manages the beans configuration and this is the mode that is most commonly used. The container makes intelligent default configurations based on convention.
However, the developer can take back this control and manage the beans configuration within the bean class itself. This means that the beans transitions characteristic, security and so on are in the hands of the developer. This is done by using service annotations.
The configuration of a bean is made via meta-data passed to the appropriate annotation.
Concurrency can be configured via annotations such as @Lock which controls read and write operations and access timeout period can be explicitly configured via the @AccessTimeout annotation.
The scope of a transaction can be controlled via the @TransactionAttribute and @Transactional annotation.
Security options can also be defined. For example, @PermitAll can be used to specify that all security roles are allowed to invoke the annotated method and @RolesAllowed to specify the security roles permitted to access the method.
Client access can be controlled by the @Remote and @Local annotations and special behavior can be given to beans that make them asynchronous and execute based on a cron-style timed schedule.
EJB Access Summary
To bring all this together I have summarizes what we have been talking about in a table that shows the EJB’s different component types against client access and relationship.
If you like reading about Java EE, I have published further posts about Java EE. Here is a list of just some of the topics that might be interesting to you:
- Java EE: Past, Present, and Future
- Introduction to JSF
- What are JAX-RS annotations?
- What is @Context annotation used for?
- Working with JAX-RS @Consumes and @Produces
- Bean validation failure management
If you want to improve your knowledge of Java EE then you should try my Lynda.com video training courses. They cover a wide range of Java EE APIs:
- RESTful Service with JAX-RS 2.0
- WebSocket Programming with Java EE
- JSON Processing with Java EE and
- Learning Java Enterprise Edition