DOC PREVIEW
UMD CMSC 433 - Enterprise Applications: EJB and J2EE

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1CMSC 433 – Programming LanguageTechnologies and ParadigmsSpring 2006Enterprise Applications:EJB and J2EE2Enterprise Applications• Examples– E-Bay– Amazon– Testudo• What distinguishes them from otherapplications? What do they have incommon? How can building them be madeeasier?23Features of Enterprise Apps• Persistent data– Databases store essential business information– Need to worry about integrity, transactions• Many interfaces– Web clients– Web services– Legacy applications4More Features• Distribution and scaling– Demands on successful app grow over time– Should be possible to scale up• Multiple machines• Geographic distribution• Resiliency to failure– One machine failure cannot shut down app– …app failure = $$$ lost35Enterprise Apps and Java• Extensive support enterprise apps in Java– EJB, JSP, JDBC, BMP, CMP, JDO, WSDP, …• Focus of this lecture: How do we buildthese systems?6Multi-tier Architecture47Key Properties of a Database• A transaction is a set of consistent changesto a database– Ex: balance := balance - $100; dispense $100• ACID transactions– Atomicity -- actions all occur or none occur– Consistency -- respect domain invariants– Isolation -- no interference with other actions– Durability -- persistent even if system fails8Database Possibilities• ACID transactions are well-understood– Hard to implement correctly– …but good implementations available• Relational databases are the standard• Scale up to very large data sets• Handle transactions and failure well• But don’t interact that well with Java• SQL for queries• Awkward to construct, use correctly59Persistent Objects• Represent persistent state with objects– Reads and writes become actions on the database– Largely transparent to object clientFoo foo = …foo.data = … // database write… = foo.data; // database read10Enterprise Java Beans (EJB)• A system for persistent objects– …and many other things• A bean is a class that implements a featureof your application– AccountInfo, Order, ShoppingCart, …• Beans live in containers– Containers often implement security,persistence, etc611Kinds of Beans• Entity beans– Represent persistent data• BMP - bean-managed persistence– Bean contains code to contact database• CMP - container-managed persistence– AppServer gives mapping to database– Beans are more portable– Cached in memory• Data in database is materialized as the bean12Kinds of Beans (cont’d)• Session beans– Represents a task carried out by a user– Stateful• Tracks state across method calls• Useful when actions need to be carried out insequence• Ex: Client logs in to app, so need to track client id• Not durable: Go away after timeout or crash– Stateless• Handles one, isolated request from client• Ex: Send an e-mail confirmation, verify credit card713Kinds of Beans (cont’d)• Message-driven beans– Listens for asynchronous messages (observer)• …we won’t talk about these14Assumptions• We’ll assume all calls to EJBs are remote– In practice, people use entity beans locally• Clients never talk directly to a bean– Instead they go through stubs (proxy pattern)– Enforces security, transactions815Beans Provide Two Interfaces• Remote or component interface– Actions for business logic• Home interface– Factory design pattern (create, destroy, find)16Bean Interfaces917You Provide• Component and home interface– How clients interact with bean• Bean implementation class– Does not implement component/home interface– Client cannot directly access bean; must usecontainer• Deployment descriptor (in XML)– Tells container how to manage the bean18Container Provides• Home implementation and stubs• Component implementation and stubs• Deployment of beans with featuresspecified by deployment descriptor– Reflection used to find bean methods• Ex: Will look for deposit() method in EJB1019Example: Hello World• Step 1: The Bean classExample from Head-First EJBimport javax.ejb.*;public class AdviceBean implements SessionBean { private String[] adviceStrings = {"test", "test1", "test2"}; public String getMessage() {System.out.println("in get advice");int random = (int) (Math.random() * adviceStrings.length);return adviceStrings[random]; } public void ejbCreate() { System.out.println("ejb create"); } …}20Example: Hello World• Step 2: The interfacesimport javax.ejb.*;import java.rmi.RemoteException;public interface Advice extends EJBObject { public String getMessage() throws RemoteException;}public interface AdviceHome extends EJBHome { public Advice create() throws CreateException, RemoteException;}1121Example: Hello World• Step 3: The deployment descriptor<?xml version="1.0" encoding="UTF-8"?><ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"><display-name>Ejb1</display-name><enterprise-beans><session> <ejb-name>Advisor</ejb-name> <home>AdviceHome</home> <remote>Advice</remote> <ejb-class>AdviceBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> <security-identity><use-caller-identity/></security-identity></session></enterprise-beans></ejb-jar>22Example: Hello World• Step 4: Put it together– Package up all files into ejb-jar.jar• jar cMf ejb-jar.jar Advice.class AdviceBean.classAdviceHome.class META-INF/ejb-jar.xml– Deploy it• cp ejb-jar.jar ~/java/jboss/server/default/deploy1223Example: Hello World• Step 5a: Write the clientpublic class AdviceClient { public static void main(String[] args) throws Exception {new AdviceClient().go(); } public void go() throws Exception {Context ic = new InitialContext();Object o = ic.lookup("Advisor");AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);Advice advisor = home.create();System.out.println(advisor.getMessage()); }}24Example: Hello World• Step 5b: Specify some extra propertiesFile jndi.properties: java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces• Step 6: Run it– java AdviceClient13CMSC 433 – Programming LanguageTechnologies and ParadigmsFall 2005XMLMay


View Full Document

UMD CMSC 433 - Enterprise Applications: EJB and J2EE

Documents in this Course
Trace 1

Trace 1

62 pages

Reflection

Reflection

137 pages

Testing

Testing

25 pages

Paradigms

Paradigms

10 pages

Testing

Testing

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Trace 1

Trace 1

46 pages

Jini

Jini

4 pages

Final

Final

15 pages

Java RMI

Java RMI

13 pages

Testing

Testing

16 pages

Load more
Download Enterprise Applications: EJB and J2EE
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Enterprise Applications: EJB and J2EE and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Enterprise Applications: EJB and J2EE 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?