J2EEOnline J2EEOnline

Distributed Objects   «Prev  Next»
Lesson 4What are the Container services?
Objective Describe the Services provided by the EJB Container and Server.

Describe the Services provided by the EJB Container and Server

The container provides services to the bean as part of its contract. These services are described briefly below.
  1. factory,
  2. lifecycle,
  3. state management,
  4. security,
  5. naming, and
  6. transactions

Bean factory

The client of a bean requests the bean factory to create a bean instance with some initial set of values. Each type of bean, not each instance, has its own factory.

Lifecycle of EJB

The lifecycle of the bean starts when the bean instance is created, ends when the instance is removed, and includes all the states in between.

State management

Most beans have state. The container maintains the bean instance's state appropriately, even if the instance is stored on secondary storage or if the underlying data in the database changes.

Container adds Security Checks

The container verifies that requests to the bean instance are valid based on information about the client that is associated with every message. The container can add additional security checks if these are built into the container by its vendor. More on this topic later.

Naming of Service Bean

The container is responsible for adding the name of the service the bean provides to the local Name Service. EJBs use JNDI (Java Naming and Directory Interface). The container will upload the stub and associate it with the name that the client looks up in JNDI. The only way the client can get access to the bean is to lookup the bean in JNDI and download the stub.

Container starts Transactions

The container intercepts all messages to methods of the bean and looks to see whether the method requires a transaction. If it does, then the container will start a transaction and propagate it to any transactional resources (such as databases and other beans) the bean uses.
Each of the above will be explained in detail as we explore how to actually program the different aspects of client and a bean.

Container Services - Quiz

Click the Quiz link below to test your understanding of EJB architecture.
Container Services - Quiz
In the next lesson, Session Enterprise JavaBeans will be discussed.