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 following table describes the parts of an EJB:
For more information about using EJBs, see Chapter 14, "EJB Programming Techniques".
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 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:
javax.ejb.EJBLocalHome, as the following example shows:
...
public interface SimpleHome extends EJBHome {
��// Returns the remote interface
��public Simple create() throws RemoteException, CreateException;
}
...
javax.ejb.EJBObject, as the following example shows:...
public interface Simple extends EJBObject {
public String getMessage() throws RemoteException;
}
...
java.rmi.RemoteException.
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 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:
javax.ejb.EJBLocalHome, as the following example shows:
...
public interface SimpleLocalHome extends EJBLocalHome {
public SimpleLocal create() throws CreateException;
}
...
javax.ejb.EJBLocalObject, as the following example shows:...
public interface SimpleLocal extends EJBLocalObject {
public String getMessage();
}
...
java.rmi.RemoteException.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 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:
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.
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
Comments
dugsmith said on Apr 19, 2003 at 2:15 PM :