Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Case Study on the J2EE Platform CPSC550 Graduate Student Seminar Presentation by Jeffrey A. Brown.

Similar presentations


Presentation on theme: "A Case Study on the J2EE Platform CPSC550 Graduate Student Seminar Presentation by Jeffrey A. Brown."— Presentation transcript:

1 A Case Study on the J2EE Platform CPSC550 Graduate Student Seminar Presentation by Jeffrey A. Brown

2 History

3 Mainframe To Enterprise Dumb Terminal Mainframe All programs and data reside on the same machine. –Scheme for handling many concurrent users efficiently was needed. SOLUTION: transaction processor Model #1 Client Database Server Model #2 Applications run on the client machine. –Typically contains both presentation and business rules logic. –Changes in business logic requires redistribution of client code. Client Database Server Middle Tier Model #3 Database server ultimate repository of information. Client remains responsible for presentation logic. Middle tier server responsible for business rules logic.

4 Transaction Processor Solves the following business needs: –Guarantees transactional integrity. Several statements executed together as a logical unit. Either all statements execute successfully or none are executed. Uses BEGIN, COMMIT, and ROLLBACK primitives. –Manages the execution of programs and the sharing of resources. Can maintain a pool of running program instances. –Hands instances out to users as needed. –Size of pool based on current user load. Allows a system to support many more concurrent users than possible if providing duplicate resources for each user.

5 From The Java Language: An Overview: What is Java? http://java.sun.com/docs/overviews/java/java-overview-1.html Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, dynamic language.

6 Designed to support applications on the network. Supports various levels of network connectivity. –URL class allows access to remote objects on the Internet. –Socket class supports creation of distributed clients and servers using reliable stream network connections. –DatagramPacket and DatagramSocket are used to send and receive datagrams. Java is Network-Savvy “Java offers the promise that the network will become the computer.”

7 Designed to support multiple threads of execution that can handle different tasks. Improves interactive performance of GUI apps. Provides built-in language support... –Thread class in java.lang package. used to start/run/stop/query threads. –Includes set of synchronization primitives... synchronized keyword. wait() and notify() methods. Java is Multithreaded “Java makes programming with threads much easier...”

8 Goal

9 The Goal of J2EE Enterprise application development is hard! J2EE comes to the rescue by simplifying enterprise application development!

10 Definitions

11 J2EE Definitions JavaServer Pages (JSP) –Provides the ability to “put snippets of Java code directly into a text-based document. A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, WML, and XML, and JSP elements, which determine how the page constructs dynamic content.” Servlets –Provides the ability to “define HTTP-specific servlet classes. A servlet class extends the capabilities of servers that host applications accessed by way of a request-response programming model.”

12 Selected J2EE Component Definitions Java Messaging Service (JMS) –“A messaging standard that allows J2EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.” Enterprise JavaBeans (EJB) –Components that implement the business logic of an enterprise application. They execute within a “container” which provides numerous services that simplify their development.

13 Selected J2EE Component Definitions Java Naming and Directory Interface (JNDI) –“Provides naming and directory functionality. It provides applications with methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes”. Remote Method Invocation (RMI) –Provides the ability for “an object running in one Java Virtual Machine (JVM) to invoke methods on an object running in another JVM. RMI provides for remote communication between programs written in the Java programming language”.

14 Selected J2EE Component Definitions Java API for XML – Remote Procedure Call (JAX-RPC) –“Uses the SOAP standard and HTTP so client programs can make XML-based remote procedure calls (RPCs) over the Internet. JAX-RPC also supports WSDL so you can import and export WSDL documents”. SOAP with Attachments API for Java (SAAJ) –Provides “a low-level API upon which JAX-RPC depends. It enables the production and consumption of messages that conform to the SOAP 1.1 specification and SOAP with Attachments note”.

15 Selected J2EE Component Definitions Java API for XML - Registries (JAXR) –Provides ability to “access business and general- purpose registries over the Web. JAXR supports the ebXML Registry/Repository standards and the emerging UDDI specifications. By using JAXR, developers can learn a single API and get access to both of these important registry technologies”. Java Management Extension (JMX) –Provides the tools “for building distributed, Web- based, modular and dynamic solutions for managing and monitoring devices, applications, and service- driven networks”.

16 Selected J2EE Component Definitions Common Object Request Broker Architecture (CORBA) –An open, vendor-independent architecture and infrastructure created by the Object Management Group (OMG) that allows a CORBA-based program from any vendor, on almost any computer, operating system, programming language, and network, can interoperate with another CORBA-based program from the same or another vendor, on almost any other computer, operating system, programming language, and network. A paraphrase taken from the CORBA FAQ See http://www.omg.org/gettingstarted/corbafaq.htm

17 Features

18 Features of J2EE The J2EE platform provides support for the following features: –Distributed processing. –Component life-cycle management. –Transaction processing. –Pooling of numerous resource types. –Security management. –Data persistence. –Interoperability with legacy systems.

19 Structure

20 J2EE Platform Architecture Diagram

21 How To Use

22 Enterprise Beans Overview Enterprise Bean Entity Bean Stateful or Stateless? Persistence? Bean Managed Transaction Support? Container Managed TX_NOT_SUPPORTED TX_BEAN_MANAGED TX_REQUIRED TX_REQUIRED_NEW TX_SUPPORTS TX_MANDATORY Models business concepts that can be expressed as nouns. Responsible for managing processes or tasks. Message-Driven Bean Session Bean Processes Asynchronous Messages

23 EJB Architectural Structure EJB Server EJB Container EJB developer EJB container EJB home Home interface Remote interface EJB object bean class Client EJB home stub EJB remote stub

24 EJB Classes and Interfaces Remote interface –defines the bean’s business methods. extends javax.ejb.EJBObject which extends java.rmi.Remote. Home interface –defines the bean’s life cycle methods. creating, removing, and finding beans. extends javax.ejb.EJBHome which extends java.rmi.Remote. Bean class –implements the bean’s business methods. Primary key class –provides a pointer into the database (entity beans only)

25 An Entity Bean Example package com.titan.cabin; import java.rmi.RemoteException; public interface Cabin extends javax.ejb.EJBObject { public String getName() throws RemoteException; public void setName(String str) throws RemoteException; public int getDeckLevel() throws RemoteException; public void setDeckLevel(int level) throws RemoteException; public int getShip() throws RemoteException; public void setShip(int sp) throws RemoteException; public int getBedCount() throws RemoteException; public void setBedCount(int bc) throws RemoteException; } Cabin bean remote interface

26 An Entity Bean Example package com.titan.cabin; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.FinderException; public interface CabinHome extends javax.ejb.EJBHome { public Cabin create(int id) throws CreateException, RemoteException; public Cabin findByPrimaryKey(CabinPK pk) throws FinderException, RemoteException; } Cabin bean home interface

27 An Entity Bean Example package com.titan.cabin; import javax.ejb.EntityContext; public class CabinBean implements javax.ejb.EntityBean { public int id; public String name; public int deckLevel; public int ship; public int bedCount; public CabinPK ejbCreate(int id){ this.id = id; return null; } Cabin bean class

28 An Entity Bean Example public void ejbPostCreate(int id){ // Do nothing. Required. } public String getName(){ return name; } public void setName(String str){ name = str; } public int getShip(){ return ship; } public void setShip(int sp) { ship = sp; } Cabin bean class (cont.)

29 An Entity Bean Example public int getBedCount(){ return bedCount; } public void setBedCount(int bc){ bedCount = bc; } public int getDeckLevel(){ return deckLevel; } public void setDeckLevel(int level ){ deckLevel = level; } public void setEntityContext(EntityContext ctx){ // Not implemented. } public void unsetEntityContext(){ // Not implemented. } Cabin bean class (cont.)

30 An Entity Bean Example public void ejbActivate(){ // Not implemented. } public void ejbPassivate(){ // Not implemented. } public void ejbLoad(){ // Not implemented. } public void ejbStore(){ // Not implemented. } public void ejbRemove(){ // Not implemented. } Cabin bean class (cont.)

31 An Entity Bean Example package com.titan.cabin; public class CabinPK implements java.io.Serializable { public int id; public int hashCode( ){ return id; } public boolean equals(Object obj){ if(obj instanceof CabinPK) return (id == ((CabinPK)obj).id); return false; } public String toString(){ return String.valueOf(id); } } Cabin bean primary key class

32 An Session Bean Example package com.titan.travelagent; import java.rmi.RemoteException; import javax.ejb.FinderException; public interface TravelAgent extends javax.ejb.EJBObject { // String elements follow the format "id, name, deck level" public String [] listCabins(int shipID, int bedCount) throws RemoteException; } TravelAgent bean remote interface

33 An Session Bean Example package com.titan.travelagent; import java.rmi.RemoteException; import javax.ejb.CreateException; public interface TravelAgentHome extends javax.ejb.EJBHome { public TravelAgent create() throws RemoteException, CreateException; } TravelAgent bean home interface

34 An Session Bean Example package com.titan.travelagent; import com.titan.cabin.Cabin; import com.titan.cabin.CabinHome; import com.titan.cabin.CabinPK; import java.rmi.RemoteException; import javax.naming.InitialContext; import javax.naming.Context; import java.util.Properties; import java.util.Vector; import javax.ejb.EJBException; public class TravelAgentBean implements javax.ejb.SessionBean { public void ejbCreate() { // Do nothing. } TravelAgent bean class

35 An Session Bean Example public String [] listCabins(int shipID, int bedCount) throws EJBException{ try { javax.naming.Context jndiContext = new InitialContext(); Object obj = jndiContext.lookup("ejb/CabinHome"); CabinHome home = (CabinHome) javax.rmi.PortableRemoteObject.narrow(obj, CabinHome.class); Vector vect = new Vector(); CabinPK pk = new CabinPK(); Cabin cabin; for(int i = 1; ; i++){ pk.id = i; try { cabin = home.findByPrimaryKey(pk); } TravelAgent bean class (cont.)

36 An Session Bean Example catch(javax.ejb.FinderException fe){ break; } // Check to see if the bed count and ship ID match. if (cabin.getShip() == shipID && cabin.getBedCount() == bedCount){ String details = i+","+cabin.getName()+","+cabin.getDeckLevel(); vect.addElement(details); } String [] list = new String[vect.size()]; vect.copyInto(list); return list; } TravelAgent bean class (cont.)

37 An Session Bean Example catch(javax.naming.NamingException ne){ throw new EJBException(ne); } catch(java.rmi.RemoteException re){ throw new EJBException(re); } private javax.naming.Context getInitialContext() throws javax.naming.NamingException{ Properties p = new Properties(); //... Specify the JNDI properties specific to the vendor. return new javax.naming.InitialContext(p); } public void ejbRemove(){} public void ejbActivate(){} public void ejbPassivate(){} public void setSessionContext(javax.ejb.SessionContext cntx){} } TravelAgent bean class (cont.)

38 An EJB Client Example package com.titan.travelagent; import com.titan.cabin.CabinHome; import com.titan.cabin.Cabin; import com.titan.cabin.CabinPK; import javax.naming.InitialContext; import javax.naming.Context; import javax.naming.NamingException; import javax.ejb.CreateException; import java.rmi.RemoteException; import java.util.Properties; public class Client { public static int SHIP_ID = 1; public static int BED_COUNT = 3;

39 An EJB Client Example public static void main(String [] args){ try { Context jndiContext = getInitialContext(); Object obj = jndiContext.lookup("ejb/TravelAgentHome"); TravelAgentHome home = (TravelAgentHome) javax.rmi.PortableRemoteObject.narrow(obj, TravelAgentHome.class); TravelAgent reserve = home.create(); // Get a list of all cabins on ship 1 with a // bed count of 3. String list [] = reserve.listCabins(SHIP_ID,BED_COUNT); for(int i = 0; i < list.length; i++){ System.out.println(list[i]); } } catch(java.rmi.RemoteException re){re.printStackTrace();} catch(Throwable t){t.printStackTrace();} }

40 An EJB Client Example static public Context getInitialContext() throws Exception { Properties p = new Properties(); //... Specify the JNDI properties specific to the vendor. return new InitialContext(); }

41 J2EE: Applications

42 Web Application Using J2EE UI Tier Middle Tier (Business Logic) EIS Tier Web Container Business Interface Implementation DBMS Legacy System Servlets / Web Tier Classes J2EE Container

43 Web Application Using J2EE Strengths of this approach: –Simplicity –Speed –Easy to test –Scales well Weaknesses of this approach: –Only supports web interface –Can’t use EJB transaction support –No built-in support for concurrent programming

44 Distributed Application Using J2EE UI Tier Middle Tier (Business Logic) EIS Tier DBMS Legacy System Web Container Business Interface Business Delegate Servlets / Web Tier Classes EJB Container Session EJB Entity EJB RMI J2EE Container

45 Distributed Application Using J2EE Strengths of this approach: –Supports all J2EE client types –Provides a shared middle tier –Permits distribution of application components across different physical servers Weaknesses of this approach: –Complex –Performance overhead –Hard to test and debug

46 J2EE: Significant Points

47 J2EE Significant Points J2EE simplifies enterprise development but it's still much harder than developing with POJO –Use XDoclet or EJBGen for help –Harder to test and debug EJBs than POJO Distributed or not distributed? –Use local interfaces with non-distributed approach Would be nice if EJB container could determine whether to use local or remote interfaces based on context! Design for scalability from start to finish –Keep state requirements small to non-existent Stateless components much more scalable!

48 J2EE: Summary

49 J2EE Summary J2EE helps simplify the development of enterprise applications. J2EE platform consists of numerous components including: –JSP, Servlets, EJB, and JMS J2EE provides helpful underlying services including: –life-cycle management, transaction processing, resource pooling, security, and data persistence. J2EE can be used to create distributed applications.

50 References

51 Java 2 Platform Enterprise Edition Specification, v1.4 http://java.sun.com/j2ee/j2ee-1_4-fr-spec.pdf The J2EE 1.4 Tutorial http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html Enterprise JavaBeans, 3rd Edition Richard Monson-Haefel, O'Reilly & Associates, ISBN 0596002262 Enterprise Javabeans: Developing Component-Based Distributed Applications Thomas C. Valesky, Addison-Wesley, ISBN 0201604469 Expert One-on-One J2EE Design and Development Rod Johnson, WROX Press, ISBN 0764543857 Core J2EE Patterns: Best Practices and Design Strategies Deepak Alur, et. al., Prentice Hall, ISBN 0130648841


Download ppt "A Case Study on the J2EE Platform CPSC550 Graduate Student Seminar Presentation by Jeffrey A. Brown."

Similar presentations


Ads by Google