Java s Enterprise JavaBeans

 <  Day Day Up  >  

Java's Enterprise JavaBeans

Yet another distributed networking option available to Java programmers is that of Enterprise JavaBeans (EJBs). EJBs provide a standard distributed component model. Do not confuse EJBs with components called JavaBeans. Standard JavaBeans are similar to controls used in the Microsoft model, and are not Enterprise JavaBeans. EJBs are a distributed technology based in part on RMI. Enterprise JavaBeans are considered RMI objects as well as a JavaBean component.

Defining EJBs is somewhat problematic , because the definition includes other terms that themselves need definitions. It is often helpful to get the definition straight from the horse's mouth. Sun defines Enterprise JavaBeans in the following manner.

The Enterprise JavaBeans specification defines an architecture for a transactional, distributed object system based on components. The specification mandates a programming model; that is, conventions or protocols and a set of classes and interfaces which make up the EJB API . The EJB programming model provides bean developers and EJB server vendors with a set of contracts that defines a common platform for development. The goal of these contracts is to ensure portability across vendors while supporting a rich set of functionality.

Enterprise JavaBeans include the following functionality:

  • Transaction processing

  • Security

  • Persistence

  • Resource-pooling facilities

Enterprise JavaBeans are actually components that live within an entity called an EJB container . The container services the EJB in a similar manner to the way a browser hosts a Java applet. The container manages the aspects mentioned previously, transaction processing, security, persistence, and resource-pooling faculties .

Figure 14.7 illustrates how the EJB container model integrates the preceding bullet items. Enterprise JavaBeans take the concept of distributed computing to a higher level than RMI. Because it encapsulates all the bullet points listed previously, the programmer is free to concentrate on solving business problems, as opposed to figuring out the code necessary to implement the various technologies such as security, transaction processing, and so on. EJBs provide a general-purpose infrastructure so that the developer can concentrate on the business logic.

Figure 14.7. The EJB container model.

graphics/14fig07.gif

Transaction Management

One EJB advantage is that of transaction management. EJBs manage transactions so that they can be rolled back at any time before the transaction is committed. A shopping cart example is a good illustration of this concept. If you are in the process of purchasing a product and the connection goes down, you'll want to make sure the system remains in a safe and secure state. The purchase should not be complete until the transaction is actually committed.


The EJB API is an extension to Java. The components of the EJB architecture are illustrated in Figure 14.8.

Figure 14.8. The EJB model.

graphics/14fig08.gif

The EJB container is basically the interface between the Enterprise JavaBean and the rest of the world. In many ways, it can be thought of as a proxy. If you have an application that requires the service of a particular EJB, the application must actually interface with the container ”not the EJB. A client never interfaces with an EJB directly. Again, this is where the public interface (public methods) comes into play. A client application would invoke public methods provided by the container, which would then manage the access to the EJB itself by invoking the EJB's methods . There are actually two types of containers:

  • Session containers

  • Entity containers

Session containers hold transient EJBs that are not persistent. Basically, the state of the EJBs is not saved. This is akin to creating a shopping cart EJB that will not survive (persist) if, for instance, you close the browser. There are many uses for session beans; however, there are obvious problems as well. Suppose you have a shopping cart open and then the connection to your machine breaks.

The EJB and Container Contract

Similar to the contracts discussed in Chapter 8, there is a contract between an Enterprise JavaBean and an EJB container. A communication mechanism is created to allow the Enterprise JavaBean and the EJB container to pass information back and forth.


Entity containers hold EJBs that do survive (persist). In short, the state of the EJBs is saved between calls to the container.

EJB servers are very similar to the concept of the CORBA ORB. The EJB server provides services such as the execution environment, transaction services, and so on. The EJB server is also responsible for making the EJB available on the network.

All this talk about EJBs is great, but they are not useful unless you can actually find them. This is a problem that affects many industries and marketing strategies. You can have the greatest product in the world, or in this case the greatest EJB in the world, but if nobody knows about the EJB, it is useless. So, the question is: How does an EJB client find the EJB it's looking for?

This is where the Java Naming and Directory Interface (JNDI) comes into play. By using the JNDI, an EJB client can find the desired services (via the EJB container), and then invoke the desired services provided by the EJB interface methods.

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net