What is J2EE? Introduction to J2EE. What are Enterprise Apps? Agenda. What are Enterprise Apps? What is J2EE?

What is J2EE? Enterprise Application Development using J2EE Shmulik London Introduction to J2EE Enterprise Application Development Using J2EE / © Shm...
Author: Jonas Lane
1 downloads 0 Views 2MB Size
What is J2EE? Enterprise Application Development using J2EE Shmulik London

Introduction to J2EE Enterprise Application Development Using J2EE / © Shmulik London 2004 Interdisciplinary Center Herzeliza Israel

Agenda • What is J2EE? • Enterprise Applications • J2EE Concepts – J2EE Container, Container services, Container component contract, ...

• Multi-tier Architecture • J2EE technologies • Sample Applications Enterprise Application Development Using J2EE / © Shmulik London 2004

What is J2EE? • J2EE is a framework for writing enterprise applications • An industry standard coordinated by Sun Microsystems together with industry leaders – IBM, Oracle, BEA, SAP, Compaq, ... (JCP see JSR151) Enterprise Application Development Using J2EE / © Shmulik London 2004

• J2EE was designed for Enterprise Applications.. not for general purpose – it is complex because EA are complex – for many applications it is an overkill – EA can benefit a lot from using J2EE

• In order to appreciate J2EE and use it properly it is important to understand what are EA Enterprise Application Development Using J2EE / © Shmulik London 2004

What are Enterprise Apps? • These are the applications that drive banks, insurance companies, online stores, market places, B2B, B2C, Supply chain, …

They’re what makes the world go round… Enterprise Application Development Using J2EE / © Shmulik London 2004

What are Enterprise Apps? • EA can be very different from one another, however they have common characteristics (not all exhibit all characteristics) • Think about the EA behind

Enterprise Application Development Using J2EE / © Shmulik London 2004

1

EA characteristics

EA characteristics

High volume, scalable, distributed • Some EA serve thousands of users concurrently • For new systems you would like a scalable architecture that scale with the business

Data taken from JavaOne 2003 / Session 3264 A Billion Hits a Day

Enterprise Application Development Using J2EE / © Shmulik London 2004

Scalability Exemplified •

(Data from 2002) – 69 Million Registered users – 380 Million dynamic hits / day! (assume 12h ⇒ >8,000 per second) – system need to scale with business:

Registered Users Growth over years (Sep 04 – 95 Million) Enterprise Application Development Using J2EE / © Shmulik London 2004

EA characteristics

heterogeneous

Transactional • The core of EA is processing transactions – They must be able to process transactions consistently and efficiently – Often distributed transactions involving different databases and other type of resources Enterprise Application Development Using J2EE / © Shmulik London 2004

Transaction Example • Consider a reservation of tickets for a show • After to specify the details of the reservation, the following tasks should be performed: – A place should be reserved for you – You should be charged for the reservation – A ticket (receipt) should be issued to you

• All these tasks must succeed or not occur at all Enterprise Application Development Using J2EE / © Shmulik London 2004

Transaction Example Checkout

• An EA is rarely a single software designed by a common team – It is a collection of interoperating software systems designed over years by deferent teams with different technologies – New components are added due to merger/acquisitions, business trends, introduction of new technologies... Enterprise Application Development Using J2EE / © Shmulik London 2004

Send receipt

Reserve chair

Process CC

otherwise, customer won’t be let in

otherwise, customer won’t find a place

otherwise, theater owner unhappy

Enterprise Application Development Using J2EE / © Shmulik London 2004

2

EA characteristics

Robust, non-stop, fault-tolerant, secure • Often should be available 24/7 • Automatic recovery from crashes – fast, no data loss or integrity loss • Manage sensitive data, different levels of access, adhere to federal regulations Enterprise Application Development Using J2EE / © Shmulik London 2004

Sources: InternetWeek 4/3/2000 + Fibre Channel: A Comprehensive Introduction, R. Kembel 2000, p.8. ”...based on a survey done by Contingency Planning Research."

Direct Downtime Costs (hour) Brokerage operations $6,450,000 Credit card authorization $2,600,000 Ebay $225,000 Amazon.com22 hour outage, June 1999 ⇒ $180,000 estimated loss several million $ Package shipping services $150,000 Home shopping channel $113,000 Catalog sales center $90,000 Airline reservation center $89,000 Cellular service activation $41,000 On-line network fees $25,000 ATM service fees $14,000 Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise App Challenges Secure

Transactional

Distributed

Multi Faces

Non-Stop 24/7

Scaleable

Fault Tolerant

Heterogeneous Web Front

How do you develop something that addresses all these challenges??

Localized

Complex

Traceable

Configurable Robust

This picture is taken from www.compugeeks.us/

Enterprise Application Development Using J2EE / © Shmulik London 2004

J2EE Container • In order to attack these challenges J2EE introduces the concept of a J2EE Container • The ‘application’ consist of a set of components that live inside a container • The container itself is distributed and can span several machines Enterprise Application Development Using J2EE / © Shmulik London 2004

Separation of concerns • The container allows for separation

of concerns: – the container provide a set of services such as transaction management, distributed communication, etc. – the components use these services in a manner that allows them to concentrate on the business logic they perform Enterprise Application Development Using J2EE / © Shmulik London 2004

Example – online catalog • Suppose your application is an online store and you want to implement a product catalog • Many users access your catalog concurrently each issuing a query • Consider the implementation of such a catalog... 1 1) To simplify matters we assume that the data in the catalog doesn’t change Enterprise Application Development Using J2EE / © Shmulik London 2004

3

Example – online catalog • For good response you must process multiple request concurrently – this requires multithreading – each request processing requires resources (socket, db connection), you need to limit the number of concurrent request processing to avoid server crash – you want to cache results for similar requests Enterprise Application Development Using J2EE / © Shmulik London 2004

Example – online catalog • You want to achieve scale with several machines – you need to balance the load between the machines – if a machine fails (crash, network..) you would like to rerun the requests it was handling on a different machine

Enterprise Application Development Using J2EE / © Shmulik London 2004

Example – online catalog • With J2EE you write a component with a single method that process a single request. The Container will: – manage several copies of your component on each machine – load balance request processing – rerun requests in case a machine fails* – pool database connections and bound number of threads/sockets... Enterprise Application Development Using J2EE / © Shmulik London 2004

Container Services • Concurrency, load balancing, failover, resource pooling • Transactions • Persistence • Distributed Objects • Messaging • Naming • Security Enterprise Application Development Using J2EE / © Shmulik London 2004

Container – component contract • In the previous example we used the load-balancing service of the container implicitly – there was no need for a load-balancing API • However, we do need to denote to the container that the request processing should be subject to load-balancing, failover, etc. Enterprise Application Development Using J2EE / © Shmulik London 2004

Container component contract • We denote our use of a service in several ways – Extending certain class/interface – Use annotations – Follow naming conventions – Use descriptors files – in some cases programmatically

Enterprise Application Development Using J2EE / © Shmulik London 2004

4

Annotations @Entity @Table(name="USERS") public class User implements Serializable { private Long id; private String username; private String password; @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; }

Application Servers • In the same way the JVM provide an abstraction for Java that allows it to be implemented on different platforms, the J2EE Container provide an abstraction that allows different application servers to host J2EE applications

. . .

Enterprise Application Development Using J2EE / © Shmulik London 2004

Annotations @Retention(RetentionPolicy.RUNTIME) public @interface Monitored { String description(); double lowerLimit() default 0; double upperLimit() default 0; }

public class MachineA { ... @Monitored(description=“productionRate”,lowerLimit=20,…) public double getProductionRate() { return currentRate; }

Enterprise Application Development Using J2EE / © Shmulik London 2004

Container component contract • The rules that summarize the interaction between the component and the container (around the use of the container services) is referred to as the container component contract.

Enterprise Application Development Using J2EE / © Shmulik London 2004

Application Servers • Each application server vendor has its own implementation of the container • In the past it was thought that the container would be separated from the application server

Enterprise Application Development Using J2EE / © Shmulik London 2004

Common Application Servers BEA WebLogic IBM WebSphere JBoss Sun Microsystems SunOne Oracle

Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Application Development Using J2EE / © Shmulik London 2004

5

J2EE Specification

Client-Server Applications

• J2EE is a standard defined by Sun Microsystems jointly with industry leaders • The J2EE Specifications specify

Client

Server

– container services – component types – included APIs – naming conventions – ... Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Application Development Using J2EE / © Shmulik London 2004

Multi-tiered Application

Multi-tier architecture

Presentation Layer

• J2EE applications has a multi-tier architecture • The system is divided into 3 or more layers

Data Layer

GUI Client

RDBMS

Legacy System

WEB Client

– presentation layer – business logic layer(s) – enterprise information systems layer

ERP

Mobile Device

Business components CRM

WEB Service

Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Information Systems

Enterprise Application Development Using J2EE / © Shmulik London 2004

Mainframe

.. in J2EE terminology Presentation Layer

Mainframe

Business Logic Layer

Business Logic Layer

Swing App. / Applet

Data Layer

RDBMS

Browser

JSP / Servlet

Mobile Device

JSP / Servlet

Legacy System

ERP Enterprise beans CRM Enterprise Information Systems Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Application Development Using J2EE / © Shmulik London 2004

6

J2EE technologies

Enterprise Java Beans

– Web technologies – Servlets, JSP, web-services – EJB (Enterprise Java Beans) – Additional APIs

• EJB is a server-side component architecture targeted at business logic and persistence • It defines components called Enterprise Beans • There are several types of Enterprise Beans – Session Beans (stateless/stateful), Entity Beans, Message Driven Beans

Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Application Development Using J2EE / © Shmulik London 2004

• J2EE include the following elements

Servlets & JSP • Most EA have a Web-interface • In J2EE Servlets & JSP are used for implementing Web-interfaces • There are other technologies some build top of JSP and/or Servlets – Struts, Velocity, Tapestry, ...

Enterprise Application Development Using J2EE / © Shmulik London 2004

J2EE APIs • • • • • • •

EJB • JavaMail & JAF JDBC • JAXP Servlets & JSP • JCA JMS • JAAS JNDI • JAX-RPC, JAXM JTA Java IDL Enterprise Application Development Using J2EE / © Shmulik London 2004

Web Services

Sample applications

• Some EA expose some of their functionality to be accessed in an automated way to allow B2B or custom clients • This can be done via web-services

• We present two examples of J2EE applications to make the previous concepts more concrete • Please bear in mind that these are sterile ‘classroom’ examples that cannot manifest the complex nature of most enterprise applications

– e.g. Amazon, eBay, Google, ...

• An evolving technology, expected to play central role in the future Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Application Development Using J2EE / © Shmulik London 2004

7

Java Pet Store

Course Project Design Presentation Layer

Business Logic Layer

Data Layer

JSP

RDBMS

JSP

Controller Servlet Entity Beans Session Façade

Enterprise Application Development Using J2EE / © Shmulik London 2004

Enterprise Application Development Using J2EE / © Shmulik London 2004

Pet Store Design

Designing Enterprise Applications with the JavaTM 2 Platform, Enterprise Edition / Nicholas Kassem and the Enterprise Team, pp. 250

Enterprise Application Development Using J2EE / © Shmulik London 2004

Course Project

Internet

J2ME Client

J2ME Client

J2EE Server

Enterprise Application Development Using J2EE / © Shmulik London 2004

8