Introducing Session Beans


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:

  • From a client perspective, a session bean is a nonpersistent object that implements some business logic running on a server.

    Note

    A session bean can be considered an extension of a client that resides on the server.


  • A session bean is not shared among multiple clients . It performs business logic on behalf of a single client.

  • Client access is mediated by the EJB container in which the bean is deployed.

  • The client of a session bean can be a remote client or a local client . Remote clients include Java programs (Java applications, applets, servlets, or JSPs) or non-Java clients, such as CORBA clients. Local clients include other EJBs deployed in the same JVM as the bean.

  • Session beans can be transaction aware.

  • They are not persistent, so they are relatively short lived within the EJB container. A bean's lifespan is typically less than or equal to its client.

  • They do not represent data in a data store. However, they can be used to access or update such data.

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 Beans

The 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.

graphics/20fig01.gif

The infrastructure services that the EJB container provides to a session bean can include the following:

  • Java Naming and Directory Interface (JNDI) registration of the bean when deployed

  • Life cycle and state management

  • Authentication and access control through declarative or programmatic security

  • Serializing method calls

  • Bean pooling

  • Transaction management

  • Persistence management

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.




BEA WebLogic Platform 7
BEA WebLogic Platform 7
ISBN: 0789727129
EAN: 2147483647
Year: 2003
Pages: 360

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