16
Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise (Part A) Ladan Tahvildari Ladan Tahvildari Assistant Professor Assistant Professor Dept. of Elect. & Comp. Eng. Dept. of Elect. & Comp. Eng. University of Waterloo University of Waterloo Abstract views (PIM, Written in UML) Domain-specific Models (PSM, Written in UML with extra notation) Implementations From Abstractions to Implementations Abstract system architecture Enterprise Middleware Architecture OO: simple Java: EJB, JMS, JSP .NET: COM+, ASP Safety Critical Architecture C Embedded System Architecture CORBA

Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

Component-Based Software Engineering

ECE493-Topic 4Winter 2006

Lecture 16– Java Enterprise(Part A)

Ladan TahvildariLadan TahvildariAssistant ProfessorAssistant Professor

Dept. of Elect. & Comp. Eng.Dept. of Elect. & Comp. Eng.University of WaterlooUniversity of Waterloo

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 22

Abstract views(PIM,Written in UML)

Domain-specific Models(PSM,Written in UML with extra notation)

Implementations

From Abstractions to Implementations

Abstract systemarchitecture

EnterpriseMiddlewareArchitecture

OO:simple

Java: EJB,

JMS, JSP

.NET: COM+,ASP

Safety CriticalArchitecture

C

EmbeddedSystem

Architecture

CORBA

Page 2: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 33

Java Enterprise Services

Sun Microsystems provides specifications for a comprehensive suite of technologies to solve large scale distributed system problems

This suite is the Java 2 Enterprise Edition, commonly known as J2EE which offers a suite of software specification to:– Design, develop, assemble and deploy enterprise

applications

Discuss the architecture of J2EE and how it can be used to develop distributed multi-tiered

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 44

J2EE Technology Architecture

Serverplatform JTS JMAPI JNDI JMS JDBCJAXP JAAS …

Enterprise Java Beans Components

Java Serverpages Servlets

Application clients Web clients

IIOP,others

html

Page 3: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 55

J2EE Suite

XML Technology– The Java API for XML Processing (JAXP)– The Java API for XML-based RPC (JAX-RPC)– SOAP with Attachments API for Java (JAAS)– The Java API for XML Registries (JAXR)

Web Technology– Java Servlets– JavaServer Pages (JSP)

Enterprise Java Bean (EJB) Technology– Session beans– Entity beans– Message-driven beans

Platform Services– Transactions– Java Message Service

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 66

J2EE-Based Application

The J2EE APIs enable distributed systems and applications through the following: – Unified application model across tiers with enterprise beans

– Simplified response and request mechanism with JSP pages and servlets

– Reliable security model with JAAS

– XML-based data interchange integration with JAXP

– Simplified interoperability with the J2EE Connector Architecture

– Easy database connectivity with the JDBC API

– Enterprise application integration with message-driven beans and JMS, JTA, and JNDI

Page 4: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 77

Enterprise Application Model

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 88

Distributed Multi-tiered Applications

Services, clients (people and application) and data are distributed geographically across many platforms and many machines.

Multiple tiers:– Client-tier (browser or client-application)– Web-tier (web-server: Java Server Pages)– Business-tier (logic; Examples: Enterprise Java Beans)– Enterprise-Information-System (EIS) tier (database)

Page 5: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 99

J2EE Clients

Web Clients– Dynamic web pages with HTML, rendered by web browsers

– Can include applets

– Communicates with server typically using HTTP

Application Clients– User interface using GUI components such as Swing

– Directly accesses the business logic tier

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1010

Web-tier Components

Client can communicate with the business tier either directly or through servlets of JSP that are located in the web-tier

Web-tier can help in pre-processing and allows distribution of the functionality

Servlets are special classes to realize the request-response model (get, post of HTTP)

JSP is a developer-friendly wrapper over the servlet classes

Page 6: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1111

Business-tier Components

This is defined by the logic that pertains to the (business) application that is being developed

Enterprise Java Beans (EJB) can be used to implement this tier

This tier receives the data from the web-tier and processes the data and sends it to the EIS-tier and takes the data from the EIS and sends it to the web-tier

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1212

Enterprise Information System Tier

In general this corresponds to the database (relational database) and other information management system

The other information management systems may include Enterprise Resource Planning (ERP) and legacy system connected through open database connectivity

Page 7: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1313

Enterprise Java Beans

Enterprise Java Beans ( EJB ) is

– a middleware component model for Java

– a specification for creating server-side, scalable, transactional, multi-user and secure enterprise-level applications

Presented by Sun in the 1999, they are easier than other technologies as RMI or CORBA

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1414

Application Server - Architecture

Presentation

• HTML Application • Java Application

Business Logic

Data Access

Page 8: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1515

J2EE Application Server

Java 2 Enterprise Edition standardizes interfaces for Application Server components

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1616

Java versus .NET for the Enterprise

Activation/Passivate (on stateful beans)JIT Activation

Java Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJB

Session Beans (Stateless, Stateful)

Entity Beans

Message-Driven Beans

COM+ Components

Java.NET

Page 9: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1717

EJB Overview

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1818

Types of Enterprise Java Beans

• Session BeansStatefulStateless

• Entity BeansBean-Managed Persistence (BMP)Container-Managed Persistence (CMP)Enterprise Java Beans Query Language

• Message-Driven BeansSession bean with Java Messaging features

Page 10: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 1919

Session Beans

For transient functionsRepresents “conversational” stateTypically one per requestData is non-persistentLifetime is limited by the client’s– once the client exits, the session bean and data are gone

Simple and easy to programLight-weight

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2020

Stateful Session Bean’s Life Cycle

The client invoke the create methodThe EJB container :– Instantiates the bean – Invokes the setSessionContext – Invokes ejbCreate

The bean is ready,. While in the ready state– EJB container may passivate the bean moving it from memory to

secondary storage – A client may invoke a business method – EJB container may activate a bean,moving it back to the ready

stage, and then calls the bean's ejbActivate method– A client may invoke the remove method and the container calls the

bean's ejbRemove method

Page 11: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2121

Stateful Session Bean’s Life Cycle

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2222

Stateless Session Bean’s Life Cycle

The client invoke the create method

The EJB container :– Instantiates the bean

– Invokes the setSessionContext

– Invokes ejbCreate

The bean is ready. While in the ready state– A client may invoke a business method

– A client may invoke the remove method and the container calls the bean's ejbRemove method

– It’s never passivate

Page 12: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2323

Stateless Session Bean’s Life Cycle

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2424

Types of Enterprise Java Beans

• Session BeansStatefulStateless

• Entity BeansBean-Managed Persistence (BMP)Container-Managed Persistence (CMP)Enterprise Java Beans Query Language

• Message-Driven BeansSession bean with Java Messaging features

Page 13: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2525

Entity Bean

“Transactional” in behavior

Can be shared among clients

Persistent: data exists permanently after client quits

Corresponds to a row of a relational database

The persistence (storing into the database) can be done:– automatically by the “container” (CMP) or

– explicitly by the bean (BMP)

In BMP, you write the code for database access calls– This may be additional responsibility but it gives control to the

bean developer.

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2626

Entity Bean’s Life CycleThe EJB container:

– Creates the instance– Calls the setEntityContext

The entity bean moves to a pool of available instances

While in the pool:– Instance is not associated with any particular object identity – All instances in the pool are identical – EJB container may assign an identity to an instance when moving it to the ready

stage invoking the ejbActivate method – A client may invoke the create method

• EJB container calls ejbCreate and ejbPostCreate

– EJB container may remove the instance invoking unsetEntityContext

While in the ready state: – A client may invoke entity bean's business methods– A client may invoke the remove method

• EJB container calls the ejbRemove method

– EJB container may invoke the ejbPassivate method

Page 14: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2727

Entity Bean’s Life Cycle

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2828

Types of Enterprise Java Beans

• Session BeansStatefulStateless

• Entity BeansBean-Managed Persistence (BMP)Container-Managed Persistence (CMP)Enterprise Java Beans Query Language

• Message-Driven BeansSession bean with Java Messaging features

Page 15: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 2929

Message-Driven Bean

A message driven bean is an enterprise bean that allows J2EE applications to process messages asynchronouslyIt acts as a JMS listener, which is similar to an event listener except that it receives messages instead of events.The messages can be sent by any J2EE component:

– an application client– another enterprise bean– a web component– a non-J2EE system using JMS

Retain no data or conversational state

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 3030

Message Driven Bean’s Life CycleEJB container creates a pool of message-driven bean instances

For each instance, the EJB container instantiates the bean :– It calls the setMessageDrivenContext – It calls the instance's ejbCreate

Like a stateless session bean,it’s never passivated, It has only two states: – Nonexistent – Ready to receive messages

While in the ready state : – EJB container may call onMessage – EJB container may call the ejbRemove

Page 16: Component-Based Software Engineering › ... › ECE493-T4 › Lecture16-J2EE-PartA … · Component-Based Software Engineering ECE493-Topic 4 Winter 2006 Lecture 16– Java Enterprise

February 28, 2006February 28, 2006 ECE493ECE493--T4T4 3131

Message Driven Bean’s Life Cycle