Java Tutorial - Java Scipt : Architectural Considerations

Java Tutorial - Java Scipt :

Architectural Considerations


EJBs form the basis for distributed components in an enterprise application and are the worker bees of the J2EE world. Most of the heavy lifting in terms of business logic is done here. By design, they allow the developers to focus on coding the business logic, while being able to declaratively manage the aspects to be delegated to the container. Most important among these containermanaged aspects are transactions, security, and distributed deployment. The life cycle of an EJB is also left in the hands of the EJB container and is rigidly set within the EJB specification. There are different types of EJBs defined by the specification. Each type was created to address a preexisting domain of problems and through real-world use; general consensus has emerged regarding where each is most applicable. Among the types of EJBs to choose from are:

·         Stateless session beans
·         Stateful session beans
·         Container-managed persistence beans
·         Bean-managed persistence beans
·         Message-driven beans

In this chapter, we cover each of these types of EJBs as well as where they fit into the enterprise architecture. First, though, we will focus on the entire EJB layer as a whole. Java is built upon the object-oriented programming model, and this is evident in the way problems are solved in Java. EJBs try to extend this object model to distributed, enterprise-level applications, but the design of EJBs is component based. This means that certain object-oriented programming paradigms we take for granted are not available. For example, the notion of inheritance is not supported on the EJB level, although this can often be worked around by deferring the EJB classes and interfaces to the last child or by using aggregation. EJBs are also limited in the things they are allowed to do. These restrictions are chiefly designed to allow the EJB container to retain management over the EJBs. For this reason, EJBs are not allowed to use any threading or synchronization. In fact, they aren’t even technically allowed to access the file system! In reality, these rules are not enforced, but it is dangerous to work outside the specification. Breaking the EJB contract can and will lead to errors because the EJB container
will assume certain operating parameters. Luckily, though, there is often a better solution that fits more within the spirit of enterprise applications. A large body of literature exists on the topic of EJBs. It is a large and complicated
topic that has already been covered in great detail in many other places. Yet, as an evolving technology the EJB specification continues to grow and will surely be the subject of much future discussion. For these reasons, we
do not cover EJBs in an exhaustive manner. We do, however, provide some overview of interesting subsets within the EJB domain. Our primary goal is to get you familiar with the open source EJB containers. Any EJB examples and related topics exist to aid in achieving that goal.