Monday, 26 August 2013

EJB in Snippet

                                        EJB

Enterprise Java Beans (EJB) is architecture for server-side component based distributed applications written in Java.

EJB defines how server-side components are written and provides a standard architectural contract between the components and the application servers and containers that manage them.

                                Power of EJB

EJB component model simplifies development of business components that are transactional, scalable, and portable. Enterprise JavaBean servers reduce the complexity of developing business components by providing automatic support for system-level services, such as transactions, security, and database connectivity, thus allowing the developers to concentrate on developing the business logic.

                                Why EJBs?

è Numerous Web sites are up and running using Java without any EJB technology.
è Developers have been using servlet/JSP models and managing transactions themselves using commit and rollback functionality that is built into JDBC without the help of application servers.
è The application developers are confronted with many challenges such as managing concurrency, persistence and transactions.

These problems are solved by using enterprise beans

The use of enterprise beans allow developers to focus on the business logic and release them from coding infrastructure and middle-ware logic, and developers become more productive and efficient.

As with most other technologies, enterprise beans do not provide the unique solution to all problems. Using enterprise beans has advantages and disadvantages. However, the advantages outweigh the disadvantages, especially for more complex applications that require a sophisticated robust and distributed persistent model.


Main EJB framework components

There are six main framework components of EJB technology:

·        EJB server—provides the actual primary services to all EJBs. An EJB server may host one or more EJB containers. It is also called generically an Enterprise Java Server (EJS). Jboss Application Server is an EJS. Containers are transparent to the client—there is no client API to manipulate the container, and there is no way for a client to tell in which container an enterprise bean is deployed.

The EJB specification outlines seven services that must be provided by an EJB server: Primary Services

_ Naming A client can invoke an enterprise bean by looking up the name of the bean in a centralized naming space called a naming service, and this is accessed via the Java Naming and Directory Interface (JNDI) API. The container is responsible for registering the (unique) lookup name in the JNDI namespace when the server starts up, and binding the appropriate object type into the JNDI namespace.

_ Transaction A transaction is defined as a set of tasks that must execute together; either all must work or all must be undone. The EJB container handles the transaction operations, as well as the coordination activities between the transactions of the beans. The EJBs transaction behavior is described in the deployment descriptor

_ Security The EJB container provides a security domain for enterprise beans. The container is responsible for enforcing the security policies defined at deployment time whenever there is a method call, through access control lists (ACL). An ACL is a list of users, the groups they belong to, and their rights, and it ensures that users access only those resources and perform only those tasks for which they have been given permission.

_ Persistence The container is also responsible for managing the persistence of a bean (all storage and retrieval of data) by synchronizing the state of the bean instance in memory with the respective record in the data source. Concurrent access to the data from multiple clients is managed through the concurrency and transaction services (entity beans only).

_ Concurrency Concurrency is defined as access by two or more clients to the same bean, and the container manages concurrency according to the rules of the bean type.

_ Life cycle the container is responsible for controlling the life cycle of the deployed components. As EJB clients start giving requests to the container, the container dynamically instantiates, destroys, and reuses the beans as
appropriate.
_ Messaging The container must provide for asynchronous messaging.


EJBs do not interact directly with the EJB server, but rather, do so
through the EJB container, which acts as a broker to the services provided by the EJB server. So, from the EJB’s perspective, it appears that the EJB container is in fact providing those services.

·        EJB container—The EJB container is a system that functions as a runtime environment for enterprise beans by managing and applying the primary services that are needed for bean management at runtime. In addition to being an intermediary to the seven services above provided by the EJB server, the EJB container will also provide for EJB instance life-cycle management, and EJB instance identification. EJB containers create bean instances, manage pools of instances, and destroy them.

·        EJB component—The EJB components refer to the beans themselves, and include all the classes, interfaces, and constructs that make up the enterprise bean. There are three types of enterprise beans: entity, session, and message-driven beans.

·        EJB interfaces and EJB bean—the interfaces for client access (EJB home and EJB object) and the EJB bean class.

·        EJB deployment descriptor—the descriptor defines the runtime quality of service settings for the bean when it is deployed. Many of the settings of an EJB, such as the transactional settings, are defined in the deployment descriptor. The deployment descriptor is an external entity from the bean, and therefore decouples the bean component itself from the runtime characteristics.
EJB client—A client that accesses EJBs.