View comments | RSS feed

EJB Basics

EJB provides a component architecture for building distributed, component-based applications. It is an important part of the Java 2 Enterprise Edition (J2EE) architecture; EJBs written using only features in the EJB specification are portable across J2EE application servers.

Enterprise is an important word in the abbreviation. EJB is an architecture for enterprise-level applications, and the EJB programming model is best suited for experienced server-side Java developers who understand the EJB application programming interface (API). However, the EJB specification requires that an application server provide a variety of EJB container services. These services allow you to concentrate on developing your business logic. In addition, JRun simplifies the EJB development process by providing functionality such as stubless open-directory deployment, the Enterprise Deployment Wizard, and XDoclet support.

The parts of an EJB

The following table describes the parts of an EJB:
Part
Description
Home interface
Provides methods that control EJB lifecycle operations, including creating, removing, and locating an EJB instance. There are two types of home interfaces:
  • Remote home Used by remote clients.
  • Local home Used by clients running in the same JRun server.
Component interface
Defines the business methods that are exposed to EJB clients. There are two types of component interfaces:
  • Remote Used by remote clients.
  • Local Used by clients running in the same JRun server.
Bean implementation
Contains the methods that perform business logic. Also contains callback methods that EJB developers implement as necessary.
Deployment descriptor
Specifies the declarative semantics that describe an EJB and the services it requires.

For more information about using EJBs, see Chapter 14, "EJB Programming Techniques".

EJB clients

EJB clients can use remote and local access, as follows:

The application deployer must ensure that the client classpath includes the compiled interfaces for all EJBs that it accesses.

Note:   In the original EJB specifications, clients were required to use remote method invocation (RMI) to access beans and their methods. As EJB best practices matured, design patterns emerged that optimized performance by colocating EJB clients and the EJB container in the same application server instance. These clients were still subjected to RMI overhead, however, and many application servers provided options to optimize colocated clients. In the latest EJB specification, application servers are required to support both local and remote interfaces.

Remote beans

Remote EJBs run in a different JVM from their clients. By running remotely, EJBs allow access from clients located anywhere on the network.

You enable remote capabilities by defining remote interfaces for a bean, as follows:

You also must include remote and remote-home elements when defining the EJB in the ejb-jar.xml file, as the following example shows:

...
<session>
  <display-name>Simple</display-name>
  <ejb-name>Simple</ejb-name>
  <home>SimpleHome</home>
  <remote>Simple</remote>
  <ejb-class>SimpleBean</ejb-class>
  <session-type>Stateless</session-type>
  <transaction-type>Container</transaction-type>
</session>
...

For more information on coding remote and local EJB clients, see Chapter 14, "EJB Programming Techniques".

Local beans

Local EJBs run in the same server as their clients. By running locally, EJBs avoid the overhead of RMI calls.

The typical scenario involves a stateless session bean acting as a client to one or more local entity beans.

You enable local capabilities by defining local interfaces for a bean, as follows:

You can implement remote and local interfaces for an EJB, however, this is not a typical use-case.

You must also include local and local-home elements when defining the EJB in the ejb-jar.xml file, as the following example shows:

...
<session>
  <display-name>SimpleLocal</display-name>
  <ejb-name>SimpleLocal</ejb-name>
  <local-home>SimpleLocalHome</local-home>
  <local>SimpleLocal</local>
  <ejb-class>SimpleLocalBean</ejb-class>
  <session-type>Stateless</session-type>
  <transaction-type>Container</transaction-type>
</session>
...

For more information on coding remote and local EJB clients, see Chapter 14, "EJB Programming Techniques".

The deployment descriptor

The EJB deployment descriptor is an XML-format text file containing elements that define the components, functionality, and services required by one or more EJBs. Many developers manage the deployment descriptor by coding manually using a text editor. Additionally, JRun provides the Enterprise Deployment Wizard and XDoclet support to automatically generate deployment descriptor elements. The EJB deployment descriptor must be named ejb-jar.xml and must be in a META-INF directory, relative to the interfaces and bean implementation, as the following example shows:

This image shows how the META-INF/ejb-jar.xml files defines the EJBs.

For more information, see Chapter 14, "EJB Programming Techniques". You can also use a JRun-specific deployment descriptor to implement JRun-specific functionality. This is described in Chapter 14 and JRun Assembly and Deployment Guide.

Comments


dugsmith said on Apr 19, 2003 at 2:15 PM :
The statement: "Remote home interface extends javax.ejb.EJBLocalHome" is incorrect, it should say "Remote home interface extends javax.ejb.EJBHome"

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/jrun/4/Programmers_Guide/introejb2.htm