1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed...

25
1 J2EE Components J2EE Components

Transcript of 1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed...

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

1

J2E

E C

omp

onen

tsJ2

EE

Com

pon

ents

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

2

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

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

3

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

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

4

Parties involved in EJB

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

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.

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

6

EJB Containers and Servers

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

7

Server/Container services• Implicit distributed transaction management. EJB transaction Implicit distributed transaction management. EJB transaction support is compliant with JTA (Java Transaction API).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 Implicit resource (sockets, threads, db connections) management and component life cycle.and component life cycle.

• Implicit persistence.Implicit persistence.

• Implicit remote accessibility.Implicit remote accessibility.

• Implicit component location transparency.Implicit component location transparency.

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

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 that’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.

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

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 logic—they simply model data. Session beans handle the business processes. Session beans might use entity beans to represent the data they use.

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

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

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

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 bean’s state is changed during a method invocation, that same state will be available to that same client upon the following invocation.

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

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.

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

13

Entity Beans• Entity beans have a lifecycle much longer than a client’s session depending on howlong the data sits in the database.

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

14

Relationship between EJB types

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

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

15

Relationship between EJB types

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

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 component’s data access layer including saving, loading, and finding component data.

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

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

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

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

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

19

EJB Remote Interface

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

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

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

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.

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

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 beans)• Remove EJB objects

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

23

Home Objects & Interfaces

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

24

Deployment Descriptors

• Deployment descriptors enable EJB containers to provideimplicit 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.

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

25

JNDI-based access to Home Object