A session bean is a synchronous Enterprise JavaBean (EJB) type that enables you to model real-world business logic in the form of a reuseable and portable J2EE component. Hence, a session bean resides completely within the context of an EJB container (WebLogic Server). The following are the general characteristics of session beans:
In the J2EE Application Programming Model, session beans are used as process or control objects specific to a client, so they are a candidate J2EE technology for representing business logic and rules and for controlling workflow between other EJB types (entity and message-driven beans). To learn more about the J2EE Application Programming Model, see Chapter 5, "The J2EE Architecture and APIs," p. 171 . Session beans can typically be used for processing credit card numbers , trading stocks, implementing shopping carts, and computing advanced algorithms. Overall, a session bean can be used to house rules governing tasks in a business application. Session beans are also intended to be relatively coarse-grained business objects, such as purchase orders, sales orders, or insurance claims. Fine-grained objects, such as line items on a purchase order, should not be modeled as session beans. This has more to do with session beans being remote objects and less to do with any functional limitations. The Value Proposition of Session BeansThe value and importance of session beans come from the communication interface between clients and session beans. Session beans consist of a bean class and two interfaces ”the home interface and the remote interface. These interfaces provide the thin client to a bean, whereas the bean class, which implements the javax.ejb.SessionBean interface, carries out the business logic. This implementation model allows clients to use the remote interface as a proxy to the EJB and, therefore, reduces the resource consumption and complexity that clients have to bear. In addition, the bean developer benefits by being able to focus primarily on coding business logic, while the EJB container provides the environment (bean classes and interfaces) in which the bean is implemented. As shown in Figure 20.1, at a high level, the EJB container transparently intercepts client calls to a bean's method, injects management and control infrastructure services to the invocation, and then calls the bean's method. Figure 20.1. The relationship between the container and session bean.
The infrastructure services that the EJB container provides to a session bean can include the following:
Developers, therefore, do not have to be concerned about implementing these infrastructure services or the underlying details of how the client finds the bean or communicates with the bean. On the whole, bean developers implement business logic via methods in the session bean class, and the EJB container provides functionality for remote access, security, concurrency, transactions, and other infrastructure services the bean requires to achieve its desired behavior. Note The goal of the session bean model is to make developing a session bean as simple as developing the same functionality directly in a client. |