Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.

Similar presentations


Presentation on theme: "1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services."— Presentation transcript:

1 1 J2EE Components

2 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services such as connection pooling, security, and life-cycle management (middle-ware services).

3 3 EJB development EJB partitions the responsibility of EJB deployment to up to six different parties. The bean provider provides reusable components that companies can purchase and use to solve business problems. The bean provider provides reusable components that companies can purchase and use to solve business problems. The container provider supplies the low-level runtime execution environment needed for EJB execution. The container provider supplies the low-level runtime execution environment needed for EJB execution. The server provider supplies the application server logic to contain, manage, and deploy components. The server provider supplies the application server logic to contain, manage, and deploy components. The application assembler is the application architect. The application assembler is the application architect. The deployer takes prewritten components and installs them The deployer takes prewritten components and installs them in application servers. The system administrator oversees the well-being of a deployed system. The system administrator oversees the well-being of a deployed system.

4 4 Parties involved in EJB

5 5 EJB Containers and Servers The EJB container. The EJB container provides the infrastructure where enterprise beans can run. There can be many beans running within a container. EJB containers are responsible for managing the beans running within them. Containers interact with EJBs by calling some required methods that the bean must expose. Containers may also provide access to a legacy system. The EJB server. The EJB server provides a runtime environment for one or more containers. EJB servers manage low-level system resources, allocating resources to containers as they are needed.

6 6 EJB Containers and Servers

7 7 Server/Container services Implicit distributed transaction management. EJB transaction support is compliant with JTA (Java Transaction API). Implicit distributed transaction management. EJB transaction support is compliant with JTA (Java Transaction API). Implicit security ( ). Implicit security (authorise and authenticate users, secure deployments). Implicit resource (sockets, threads, db connections) management and component life cycle. Implicit resource (sockets, threads, db connections) management and component life cycle. Implicit persistence. Implicit persistence. Implicit remote accessibility. Implicit remote accessibility. Implicit component location transparency. Implicit component location transparency.

8 8 EJB Types EJB specification defines two different kinds of enterprise beans: session beans and entity beans. A session bean represents work being performed for client code that is calling it. Session beans are business process objects. They implement business logic, rules, and workflow. A session bean could perform price quoting, order entry, database operations, etc. Session beans are called “session” because they live for the lifetime of the client code tha t ’s invoking the bean. If client code contacted a session bean to perform order entry logic, the application server is responsible for creating an instance of that session bean component. When the client disconnects, the application server may destroy the bean instance.

9 9 EJB Types In certain application scenarios, business process components are manipulating data in some underlying data storage, such as a relational database. An entity bean is a component that represents such persistent data. Entity beans model bank accounts, orders, order line items, stock portfolios, and so on. Entity beans represent real data objects, such as customers, products, or employees. Entity beans do not contain business process logi c— they simply model data. Session beans handle the business processes. Session beans might use entity beans to represent the data they use.

10 10 Session Beans Session beans are usable by one client at a time—that is, they are not shared between clients. When a client is using a session bean, that client is the only client dealing with that session bean. On the other hand, the state of entity beans is shared among many clients. The EJB server is responsible for managing the lifetime of beans. The client does not directly instantiate beans - the EJB container does this automatically. The EJB container destroys session beans when needed. This allows beans to be pooled and reused for multiple clients. There are two subtypes of session beans— stateful session beans and stateless session bean s.

11 11 Stateful Session Beans Some business processes can be performed in a single method request, e.g., computing the price of goods or verifying a credit card account. Other business processes are more drawn out and can last across multiple method requests and transactions. A stateful session bean is designed to service business processes that span multiple method requests or transactions. Stateful session beans retain state on behalf of an individual client. If a stateful session bea n ’s state is changed during a method invocation, that same state will be available to that same client upon the following invocation.

12 12 Entity Beans Entity beans provide is an object-oriented in-memory view of data in an underlying data store. The traditional way for applications to deal with data is to work with relational tables in a database, reading and writing that data as needed. Entity beans are object representations of this underlying data. Data in a relational store can be treated as real objects.

13 13 Entity Beans Entity beans have a lifecycle much longer than a clien t ’s session depending on how long the data sits in the database.

14 14 Relationship between EJB types In the EJB distributed object architecture, session beans can be used to provide a high- level interface f a çade to business processes, masking the lower-level entity bean subsystems used behind the scenes.

15 15 Relationship between EJB types

16 16 Entity Bean persistence A bean-managed persistent entity bean is an entity bean that must be persisted by hand in the underlying information store (e.g., the RDBMS). The component developer must write code to translate in-memory fields into an underlying store. Container-Managed Persistent Entity Beans. EJB 1.1 containers must provide automatic persistence for entity beans. The container/server performs every function of the componen t ’s data access layer including saving, loading, and finding component data.

17 17 Container/Server tasks Scalability is enhanced when an application server intelligently manages needed resources across a variety of deployed components. Resources could be threads, sockets, database connections, etc. In the EJB world, the container is responsible for providing all resource management services behind the scenes. The EJB container is also responsible for controlling the life cycle of the deployed EJBs. The EJB container dynamically instantiates, destroys, and reuses beans as appropriate. If a client requests a certain type of bean that does not exist in memory yet, the container may instantiate a new in-memory instance. If a bean already exists in memory, it may not be appropriate to instantiate a new bean - especially if the system is low on memory. Instead, a bean could be re-assigned from one client to another. It might also make sense to destroy some beans that are not being used anymore. This is called instance poolin g.

18 18 The EJB Object When a client wants to use an instance of an enterprise bean class, the client never invokes the method directly on an actual bean instance. Rather, the invocation is intercepted by the EJB container and then delegated to the bean instance. The EJB container is acting as a layer of indirection between the client code and the bean. This layer of indirection manifests itself as a single network-aware object, called the EJB objec t. The EJB object is an object that knows about networking, transactions, security, etc. It is an intelligent object that knows how to perform intermediate logic that the EJB container requires before a method call is serviced by a bean class instance.

19 19 EJB Remote Interface

20 20 Remote Interface Bean clients invoke methods on EJB objects, rather than the beans themselves. To achieve this, EJB objects must clone every business method that bean classes expose. To accomplish this duplication, there is a special interface that a bean provider writes. This interface duplicates all the business logic methods that the corresponding bean class exposes. This interface is called the remote interfac e.

21 21 Methods of EJB Objects getEJBHome(): Retrieves a reference to the corresponding home object. getPrimaryKey() Returns the primary key for this EJB object. A primary key is used only for entity beans. remove() Destroys this EJB object. When the client code is done using an EJB object, you should call this method. The system resources for the EJB object can then be reclaimed. Note: For entity beans, remove() also deletes the bean from the underlying persistent store. getHandle() Acquires a handle for this EJB object. IsIdentical() Tests whether two EJB objects are identical.

22 22 Home Objects To acquire a reference to an EJB object, client code asks for an EJB object from an EJB object factory. This factory is responsible for instantiating (and destroying) EJB objects. The EJB specification calls such a factory a home object. The main responsibilities of home objects are to do the following: Create EJB objects Find existing EJB objects (for entity bean s ) Remove EJB objects

23 23 Home Objects & Interfaces

24 24 Deployment Descriptors Deployment descriptors enable EJB containers to provide implicit middleware services to enterprise bean components. Deployment descriptors are used to describe the requirements of beans: Bean management and life-cycle requirements. E.g., whether the bean is a session or entity bean, and the home interface that generates the beans. Persistence requirements (entity beans only). Authors of entity beans use the deployment descriptors to inform the container about whether the bean handles its persistence on its own or delegates the persistence to the EJB container. Transaction requirements, Security requirements.

25 25 JNDI-based access to Home Object


Download ppt "1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services."

Similar presentations


Ads by Google