Introduction to EJB (Part 2)
Introduction to EJB (Part 2)
We continue this series on an introduction to EJBs in Java EE. In this post, we take a look at the various access modes that exist when using EJBs.
Join the DZone community and get the full member experience.Join For Free
Secure your Java app or API service quickly and easily with Okta's user authentication and authorization libraries. Developer accounts are free forever. Try Okta Instead.
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. I also 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 bean 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 metadata passed to the appropriate annotation.
Concurrency can be configured via annotations such as @Lock, which controls read and write operations. The access timeout period can be explicitly configured via the @AccessTimeout annotation.
The scope of a transaction can be controlled via the @TransactionAttribute and @Transactional annotations.
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 summarized 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:
Published at DZone with permission of Alex Theedom , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.