EJB Architecture and Design

R. Praveen.

What is EJB?
„ An EJB is just a collection of Java classes and XML file, bundled into a single unit. The Java classes must follow certain rules and provide certain callback methods. „ EJB is just a specification. It is not a product. „ EJBs are reusable components.

What is EJB?
„ EJB is a widely-adopted server-side component architecture for J2EE. „ EJB components are designed to encapsulate business logic, and to protect the application developer from having to worry about system level issues.

Contents Services provided by EJB container Circumstances of EJB component usage How an EJB component looks like? View of an EJB component by client programmer and EJB developer „ Mechanisms by which EJB container provides its services „ „ „ „ „ Rules an EJB developer must follow and how to use EJBs in a web architecture? .

no System-level programming „ System-level services (i. "plumbing") such as transactions. threading. persistence. Life-cycle.e.Key features of EJB technology „ EJB components are server-side components written entirely in the Java programming language „ EJB components contain business logic only . security. are automatically managed for the EJB component by the EJB server . etc.

portable. work with any client. the remote interface. distributed. multi-tier.Key features of EJB technology „ EJB architecture is inherently transactional. the implementation class and the XML deployment descriptor . „ Components are declaratively customized „ There are four major parts to every bean: the home interface. scalable and secure „ EJB components are fully portable across any EJB server and any OS.

„ JavaBeans has tier of execution at Client and EJB has at Server (specifically business logic tier) .EJB vs JavaBeans „ The JavaBeans architecture is meant to provide a format for general-purpose components whereas the EJB architecture provides a format for encapsulation and management of business logic.

. Java application etc. The EJB runtime environment provides services of Persistence. declarative transactions and security. connection pooling and lifecycle services.EJB vs JavaBeans „ In JavaBeans the runtime execution environment provides services like Java libraries.

Varieties of Beans „ Session Beans ¥ Stateful session bean ¥ Stateless session bean „ Entity Beans ¥ With container-managed persistence ¥ With bean-managed persistence „ Message-Driven Beans .

Why use EJBs in your design? „ EJB specification provides enterprise-level services. . so that they are free to concentrate on business logic. that is. „ EJB’s API was designed to keep the application programmer from having to provide systemslevel services. it provides software services that are fundamental to an organization’s purpose.

Why use EJBs in your design? „ A requirement of any of the services provided by an EJB container like transactions. security. . persistence. scalability. future growth possibilities is an appropriate reason to use EJB in the design of the application.

EJB Architecture Client Application Logic J2EE Application Server RDBMS Data EJB Container Client Application Java Mail JDBC Corba JMS JTA RMI Session Bean Entity Bean Mail .

Roles in EJB Development „ EJB provider .a person who develops EJB Components „ EJB Deployer .a person responsible for deploying EJB’s in EJB server „ Application Server/ EJB Container Vendor .one who provides application server on which the application is deployed .

one who combine the EJB components with other software to make a complete application „ System administrator .one who manages the application after it has been deployed into a target environment.Roles in EJB Development „ Application assembler . .

Roles in EJB Development EJB Provider Application Assembler App Server/ EJB Container Provider Deployer System Administrator .

The component lives in the container and the container provides the services for the component.EJB Container and its Services „ A container is an execution environment for a component. „ Similarly. a container lives in an application server. which provides an execution environment for it and other containers. .

EJBs created with application development tools will encapsulate data access in components. .Services provided by an EJB container „ Persistence ¥ Ex: simple connection pooling. automatic persistence. etc.

Services provided by an EJB container „ „ „ „ „ „ „ „ Declarative transactions Data caching Declarative Security Error Handling Component Framework for Business Logic Scalability and Fall-Over Portability Manageability .

there are clearly defined responsibilities between the various parts of an application using EJB component namely the client. security. „ Second. transactions are separate from the Java files that implement the business logic of the component.How the Container Provides Services There are three basic ideas: „ First. persistence. . The definition of these responsibilities is formally known as a contract. the services that the container provides are defined in such a way that they are orthogonal to the component. In other words. the EJB container and the EJB component.

the container puts itself between the client and the component on every single business method call. the container interposes on each and every call to an EJB component so that it can provide its services.How the Container Provides Services „ Third. . In other words.

Contracts EJB Container/Application Server Enterprise JavaBean Client .

the bean provider must implement the container callbacks defined in the javax.ejb. ejbPostCreate().Rules for the bean programmer „ The developer of the EJB component must implement the business methods in the implementation class „ The bean provider must implement the ejbCreate().SessionBean interface .ejbRemove() methods and the ejbFind<METHOD>() methods if the bean is an entity with bean managed persistence „ The bean provider must define the enterprise bean’s home and remote interfaces „ For session beans.

Rules for the bean programmer „ For entity beans.ejb. the provider must implement the container callbacks defined in the javax.EntityBean interface „ The bean provider must not use programming practices that would interfere with the container’s runtime management of the enterprise bean instances .

the client makes a call on the RMI stub „ This RMI stub interposes on the method call in order to marshal parameters and send the information across the network „ A skeleton on the server side unmarshals the parameters and delivers them to the EJB Container .Interposition : method call to an EJB Container from a remote client „ First.

Interposition diagram Client RMI Stub Network RMI Stub Container generated class EJB Interposition class .

persistence. callbacks and returns data or exception to the remote client . the container will do some more work with transactions.Interposition : from EJB Container to EJBs „ The container will examine the security credentials of the caller of the method „ It will start or join with any required transactions „ It will make any necessary calls to persistence functions „ It will trigger various callbacks to allow the EJB Component to acquire resources „ Only after all this is done will the actual business method be called „ Once it is called.

Working with EJBs The Enterprise JavaBeans specification is written for three audiences: „ The Client developer „ The EJB developer „ The EJB container developer .

There are two possible types. They are java servlets and JSPs which also access the EJB components via the RMI-IIOP protocol.EJB Clients „ EJB Clients are applications that access EJB components in EJB containers. The second category of application clients are components in the web container. The first category is application clients which are stand-alone applications accessing the EJB components using the RMI-IIOP protocol. .

.The Client Developer’s View „ The client has a smaller set of concerns then a bean developer with regard to using EJBs. he need to know : ¥ how to find or create a bean. ¥ how to use its methods and ¥ how to release its resources „ The client need not worry about the implementation of the EJB. Basically. callbacks that the EJB container will make on the EJB or nature of the services provided to the EJB.

rather than a bean type. The home interface is not associated with a particular bean. just with a type of bean. and removing EJBs. „ Remote Interface : It is for business methods. Logically. The remote interface also provides some infrastructure methods associated with a bean instance. finding.EJB’s interface „ Home Interface : It is primarily for the life cycle operations of the bean: creating. it represents a particular bean on the server. .

Sample client application pseudo code „ A client programmer will acquire an EJB’s home interface through JNDI. and they use this home interface to : Create or find instance of bean Execute methods Reference (Handle) Remove bean .

The XML file called the deployment descriptor. contains the structural information about the bean. the home interface. . remote interface. business logic class file and the XML file.The Bean Programmer’s view „ Main responsibility is write business logic and structure the code in a particular structure. declares the bean’s external dependencies and specifies certain information about how services such as transaction and security work. The structure has 4 files.

class .xml orderMgmt\ OrderManagement.class OrderManagementBean.class OrderManagementHome.Structure of JAR file META -INF\ ejb-jar.

„ You cannot set the socket factory used by ServerSocket or Socket „ You cannot use the object substitution features of the serialization protocol .What you can’t do in an EJB component? „ You cannot use Reflection API to access information inaccessible to you. „ You cannot create a class loader or replace a security manager.

What you can’t do in an EJB component? „ use Threads or the Threading API „ use the AWT „ Act as a Network Server „ „ „ „ „ use Read/Write static fields use java.io package Load a native library use “this” as an Argument or Return value use Loopback Calls .

Translates user-interface events into changes to the model and defines the way the user-interface reacts to those events. „ Controller : This is the component that responds to user input. There can be different presentations of a single model. „ View : This is the presentation component or the user-interface component. It can serve multiple views. .EJB Components on the Web Three classes of objects in MVC architecture: „ Model : This is the data and business-logic component.

Sign up to vote on this title
UsefulNot useful