Chapter 3: EAServer Components
The Enterprise JavaBeans (EJB) technology defines a model for the development and deployment of reusable Java server components, called EJB components.
An EJB component is a nonvisual server component with methods that typically provide business logic in distributed applications. A remote client, called an EJB client, can invoke these methods, which typically results in database updates. Since EAServer uses CORBA as the basis for the EJB component support, EJB components running in EAServer can be called by any other type of EAServer client or component, and even CORBA clients using ORBs from other vendors that are compatible with CORBA 2.3.
The EJB architecture looks like this:
EJB server The EJB server contains the EJB container, which provides the services required by the EJB component. EAServer is an EJB server.
EJB client An EJB client usually provides the user-interface logic on a client machine. The EJB client makes calls to remote EJB components on a server and needs to know how to find the EJB server and how to interact with the EJB components. An EJB component can act as an EJB client by calling methods in another EJB component.
An EJB client does not communicate directly with an EJB component. The container provides proxy objects that implement the components home and remote interfaces. The component’s remote interface defines the business methods that can be called by the client. The client calls the home interface methods to create and destroy proxies for the remote interface.
EJB container The EJB specification defines a container as the environment in which one or more EJB components execute. The container provides the infrastructure required to run distributed components, allowing client and component developers to focus on programming business logic, and not system-level code. In EAServer, the container encapsulates:
The client runtime and generated stub classes, which allow clients to execute components on a remote server as if they were local objects.
The naming service, which allows clients to instantiate components by name, and components to obtain resources such as database connections by name.
The EAServer component dispatcher, which executes the component’s implementation class and provides services such as transaction management, database connection pooling, and instance lifecycle management.
EJB component implementation The Java class that runs in the server implements the bean’s business logic. The class must implement the remote interface methods and additional methods for lifecycle management.
You can implement three types of EJB components, each for a different purpose:
Stateful session beans
Stateless session beans
A stateful session bean manages complex processes or tasks that require the accumulation of data, such as adding items to a Web catalog’s shopping cart. Stateful session beans have the following characteristics:
They manage tasks that require more than one method call to complete, but are relatively short-lived. For example, a session bean might manage the process of making an airline reservation.
They typically store session state information in class instance data, and do not survive server crashes unless they are run in a cluster that has persistent storage enabled for the component.
There is an affinity between each instance and one client from the time the client creates the instance until it is destroyed by the client or by the server in response to an expired instance timeout limit.
For example, if you create a session bean on a Web server that tracks a user’s path through the site, the session bean is destroyed when the user leaves the site or idles beyond a specified time
A stateless session bean manages tasks that do not require the keeping of client session data between method calls. Stateless session beans have the following characteristics:
Method invocations do not depend on data stored by previous method invocations.
There is no affinity between a component instance and a particular client. Each call to a client’s proxy can invoke a different instance.
From the client’s perspective, different instances of the same component are identical.
Unlike stateful session beans, stateless session beans can be pooled by the server, improving overall application performance.
An entity bean models a business concept that is a real-world object. For example, an entity bean might represent a scheduled airplane flight, a seat on the airplane, or a passenger’s frequent-flyer account. Entity beans have the following characteristics:
Each instance represents a row in a persistent database relation, such as a table, view, or the results of a complex query.
The bean has a primary key that corresponds to the database relation’s key, and is represented by a Java datatype or class.
Each EJB component has a transaction attribute that determines how instances of the component participate in transactions. In EAServer, you set the transaction attribute in the Transaction tab of the Component Properties dialog box.
When you design an EJB component, you must decide how the bean will manage transaction demarcation: either programmatically in the business methods, or by the container, based on the value of the transaction attribute in the deployment descriptor.
A session bean can use either bean-managed transaction demarcation or container-managed transaction demarcation; you cannot create a session bean where some methods use container-managed demarcation and others use bean-managed demarcation. An entity bean must use container-managed transaction demarcation.
The EJB container provides services to EJB components. The services include transaction and persistence support.
Transaction support An EJB container must support transactions. EJB specifications provide an approach to transaction management called declarative transaction management. In declarative transaction management, you specify the type of transaction support required by your EJB component. When the bean is deployed, the container provides the necessary transaction support.
Persistence support An EJB container can provide support for persistence of EJB components. An EJB component is persistent if it is capable of saving and retrieving its state. A persistent EJB component saves its state to some type of persistent storage (usually a file or a database). With persistence, an EJB component does not have to be re-created with each use.
An EJB component can manage its own persistence (by means of the logic you provide in the bean) or delegate persistence services to the EJB container. Container-managed persistence means that the data appears as member data and the container performs all data retrieval and storage operations for the EJB component. See Chapter 27, “Creating Entity Components,” in the EAServer Programmer’s Guide.
|Copyright © 2005. Sybase Inc. All rights reserved.|