Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction,...

28
© P. Devanbu, 2002 Enterprise Java Beans Enterprise Java Beans Enterprise Java Beans Taking IT easy with Middleware Taking IT easy with Middleware Premkumar Premkumar Devanbu, Devanbu, Center for Software Systems Research Center for Software Systems Research Dept. of Computer Science, Dept. of Computer Science, University of California, Davis, CA, USA. University of California, Davis, CA, USA.

Transcript of Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction,...

Page 1: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Enterprise Java BeansEnterprise Java BeansEnterprise Java BeansTaking IT easy with MiddlewareTaking IT easy with Middleware

PremkumarPremkumar Devanbu,Devanbu,Center for Software Systems ResearchCenter for Software Systems Research

Dept. of Computer Science, Dept. of Computer Science, University of California, Davis, CA, USA. University of California, Davis, CA, USA.

Page 2: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Outline

• Introduction, Motivation and Overview.

• Session Beans• Entity Beans• EJB Services: Naming, Transactions,

and Security. • Comparison of EJB and .NET

Page 3: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

Outline

• Introduction, Motivation and Overview.

• Session Beans• Entity Beans• EJB Services: Naming, Transactions,

and Security. • Comparison of EJB and .NET

Page 4: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Distributed IT Systems are ubiquitous

• Web e-business systems• Web Intranet systems (e.g.

personnel, registration, grading, etc at a University.)

• Government systems (e.g., taxation, welfare programs, research grants)

Page 5: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

……and challenging!!

• Networking• Administration• Fault-tolerance• Persistence• Transactions• Load handling

• Security• Resource

pooling/Caching Replacement

• Interoperability• Legacy sytems.• Logging/auditing

Page 6: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

They do have similarities!!

Application-level commonalities:

• Login/authentication• Pricing computations (can be complex!)• Session logic (e.g., shopping cart)• Tax Computations• Payment/Credit card

Page 7: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

They share infra-structure!Typical common elements: • Data-base management• Protocol handlers (TCP/IP)• Security (cryptography, key management).• Transaction management. • Load management/scheduling

…So component-based approach is very appealing!

….But! How to provide an environment for a component market to thrive?

Page 8: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

What we would like:• A common architectural style, with

good separation of concerns. • A operational infra-structure (i.e., a

container) that provides good services to components

• Well-defined, standardized, interfaces for components

• Tool support (automate the repetitive tasks)

…provided by EJB, .NET, CCM etc.

Page 9: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

We’ll start with:• A common architectural style, with good separation of concerns.

• A operational infra-structure (i.e., a container) that provides good services.

• Well-defined, standardized, interfaces

• Tool support (automate the repetitive tasks)

Page 10: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

The Architectural Style• Should be simple, yet general. • Should provide good separation of

concerns.– To support easier evolution– To support many different

vendors/systems• Simplify personnel/training issues.

Page 11: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Evolution of Container Style

…In the beginning: (Simple Client-Server)

ProprietaryProtocols

o Complex Clientso Complex Serverso Commitment to vendoro Hard to evolve. o Hard to administer

Page 12: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Evolution of Container Style

…Things get better (RDB/xDBC)

ProprietaryProtocols

o Data management separated.o Easier to scale database servero Application logic still complexo Hard to evolve applications o Still have Complex Clientso Hard to administer clients

Page 13: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Evolution of Container Style

…here come Servlets

WebBrowser

Only!

ServletsGo

Here!

HTTP

o Clients much simplero Trival to administero Servlet becomes very complex:

o GUIo Persistenceo Business Logic, etc.

Page 14: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Introducing The EJB Style….Servlet

ContainerEJB

Container

JDBCHTTP

o Business Logic handled by EJBs.o Database persistence also by

EJBs.o GUI concern handled by

servlets.

Page 15: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

What are these containers?

ServletContainer

EJBContainer

JDBCHTTP

Handle common functionality for all the contained things.

• Communications. • Threading, stopping/starting• Resource pooling• Global/session state

Page 16: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

What do containers do? Servlet

ContainerEJB

Container

JDBCHTTP

Servlet Container:• HTTP Protocol• Web Request/response • Threading• Servlet/session state• Cookies

EJB Container• Communications. • Threading/Start/Stop• Resource pooling• Transactions• Security• Data Persistence, etc.

Page 17: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Further refining….Servlet

ContainerEJB

Container

JDBCHTTP

Session Beans

Handle each user’s session, and contain the business logic.

Entity Beans

Handle the storage/retrievel of data, and any other data access and querying functionality.

J2EE framework includes both containers!

Page 18: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

What is anEnterprise Java Bean?

A server-side component that provides some unit of functionality, and is compliant with interfaces that allow it to operate with the J2EE container. Implemented as a collection of Java classes, that implement certain required interfaces.

Page 19: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Examples

A typical purchase transaction:• A shopping cart EJB• A credit card EJB (remote, at

Visa/Amex)• A shipping EJB• An inventory control EJB

Page 20: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

SERVLETS JSPs

Enterprise Java Beans

ConnectorsJ2EEServer

BusinessPartnerSystems

Legacy Systems

BusinessPartnerSystems

Databases

© P. Devanbu, 2002

Page 21: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

The EJB Universe

EJB Platform Implementation

Application

Tools

Application

Package

ToolsProvider

ApplicationIntegratorEJBsBean Provider

EJB PlatformVendors

DeploymentSpecialist

SystemOperator

© P. Devanbu, 2002

Page 22: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Moving ahead: • A common architectural style, with

good separation of concerns. • A operational infra-structure (i.e., a container) that provides good services.

• Well-defined, standardized, interfaces

• Tool support (automate the repetitive tasks)

…provided by EJB, .NET, CCM etc.

Page 23: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

A typical “old-style” component business method

Transfer(amount, account1, account2) {/* 1. Do security…authenticate account *//* 2. Signal beginning of transaction *//* 3. Access Database for account1 *//* 4. Access Database for account2 *//* 5. Update accounts 1 and 2 in memory *//* 6. Write out account1 to database *//* 7. Write out account2 to database *//* 8. Signal Commit of Transaction */}

Programmer must handle persistence, transactions, security…

Page 24: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

With Container-managed security, persistence and Transactions…

Transfer(amount, account1, account2) {

/* 1. Do security…authenticate account *//* 2. Signal beginning of transaction *//* 3. Access Database for account1 *//* 4. Access Database for account2 */

/* 5. Update accounts 1 and 2 in memory *//* 6. Write out account1 to database *//* 7. Write out account2 to database *//* 8. Signal Commit of Transaction */

}

All other Details automatically taken care of by container!!!

Page 25: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Is this Magic? No!• Container performs the services, under

instructions from deployment specialist!• Container performs services by

“intercepting” bean operations. OBSERVER pattern is used, along with DECORATOR.

• Programmer can customize some things by programming if so desired, and tools generate code in other cases. TEMPLATE pattern.

Page 26: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

How The Container intervenes

EJBEJBContainer

EJBRemoteobject

EJBContainerServices

Page 27: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

The process

• Write EJB, with just business logic.• Describe services required, in a separate

deployment descriptor. • Run a Tool, which generates “interceptor”

code that is run by the remote proxy. • The “interceptor” code handles all the

calls to the middleware-provided services.

Page 28: Enterprise Java Beansdevanbu/teaching/160/docs/short-ejb.pdf · Outline • Introduction, Motivation and Overview. • Session Beans • Entity Beans • EJB Services: Naming, Transactions,

© P. Devanbu, 2002

Advantages

• Application/business logic is much simpler.

• Separation of concerns. • Easy to change use of services

(transactions, security, persistence) without re-programming.