Enterprise JavaBeans

   

Java™ 2 Primer Plus
By Steven Haines, Steve Potts

Table of Contents
Chapter 26.  Web Architecture


The combination of HTML, JSP, JavaScript and servlets provides a number of quality options for communicating with a user's browser. This approach provides us with many of the benefits of a traditional LAN-based client/server system without the expense and limitations. This puts the View layer of our architecture in pretty good shape.

In the Controller layer, things can be improved beyond what we have explained thus far. We stated earlier in this chapter that often, Java classes are better suited for the logic that is needed by the Controller and the Model layers than either servlets or JSPs. What is the best form for these classes to take?

If an application lists scalability as a primary requirement, it is a candidate for the use of Enterprise JavaBeans (EJB). EJBs are classes that have been created according to a fairly strict pattern. They are not instantiated directly by other classes and servlets. EJBs reside in special pieces of software called Application Servers, or EJB Containers. They are instantiated by making a request to the container for an EJB to be instantiated.

These servers provide a variety of services for the classes that they host.

  • Life-cycle Management The EJB container is responsible for creating and destroying instances of your class (called an EJB), based on the demand.

  • Availability Some EJB containers can be clustered so that they can provide near 100% availability by redirecting a request to a different container if the first container is unable to respond.

  • Reliability EJB containers are capable of handling most errors without closing the container. They can retry a request that did not complete.

  • Security EJB containers can provide authorization as well as encryption/decryption services.

  • Transaction Support EJB transaction is managed at the container level, enabling you to create multi-EJB transactions.

  • Distribution Services EJB can call other EJBs, even when they are located on another server.

  • Threading EJBs run in their own threads automatically.

  • Persistence EJBs can be written so that they automatically update a database when they are changed.

There are two varieties of EJBs, Session Beans and Entity Beans. Session Beans are expected to maintain state for only one session or instantiation. Entity Beans represent databases and they are expected to maintain state across multiple sessions just like a database does.

The downside to the EJB architecture is the cost. Instead of being a free download from a vendor, you normally purchase the container. Prices vary, but it is not unusual to spend thousands or tens of thousands of dollars on license fees. By the time you pay for training, you have a sizeable amount of money invested. This investment is recouped in both the development and testing phase, however. Development is faster because the container provides so many of the programming tasks. Testing is easier because there is less code to test. Figure 26.9 shows the effect of developing with EJBs on the MVC architecture diagram.

Figure 26.9. EJBs occupy both the Controller layer and the Model layer of the MVC architecture.

graphics/26fig09.gif

The use of EJBs instead of ordinary Java classes in the Controller and Model layers of the MVC architecture can improve your system in many ways. The cost/benefit analysis only works for fairly large systems that have a strong scalability requirement.


       
    Top
     



    Java 2 Primer Plus
    Java 2 Primer Plus
    ISBN: 0672324156
    EAN: 2147483647
    Year: 2001
    Pages: 332

    Similar book on Amazon

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