
Session: L12 Hitchhikers Guide to JEE Gary Ben-Israel National Institute for Testing & Evaluation May 10, 2007 9:20 a.m. – 10:20 a.m. Platform: Cross Platform 1 Agenda • What is Java Enterprise Edition • The Web container • The EJB Container 2 2 Agenda • What is Java Enterprise Edition • Definition • The three tier model • UI Design • The Web container • The EJB Container 3 3 What is Java Enterprise Edition Java Platform, Enterprise Edition (Java EE) • Is the industry standard for developing portable, robust, scalable and secure server-side Java applications. • Built on the solid foundation of Java SE • Provides web services, component model, management, and communications APIs • Is the industry standard for implementing enterprise class service-oriented architecture (SOA) and Web 2.0 applications. 4 4 JEE three tier model 5 5 UI Design • UI Solutions • Rich Client Vs. Thin Client 6 6 UI Solutions • Rich Client (Desktop Applications) • Thin Client (Classic web Applications) Both address similar missions: Event handling Layouting Data Binding Input validation Navigation flow I18N (Internationalization) Serialization L10N (Localization) 7 7 Rich Client Vs. Thin Client ☺ Asynchronous Synchronous Uninterrupted user UI reloaded and rendered interaction with each request ☺ Client-side logic may be Client-side logic may be implemented in Java implemented in Javascript Requires Installation ☺Runs anywhere Multiple client With a browser deployments 8 8 Agenda • What is Java Enterprise Edition • The Web container • The framework universe • Why so many? • Framework categories • AJAX • The EJB Container 9 9 The framework universe is vastly hugely mind-bogglingly big Wicket WebObjects Chrysalis OpenEmcee FacesFreeway Struts JPublish (OpenLaszlo) Scope JSPWidget JSF Stripes VRaptor Warfare Caramba WebWork ThinkCap JX Swinglets JWAA Xopolon Spring MVC OXF wingWeb Helma Tapestry Canyamo Verge Jacuard Cocoon Anvil XUI Macaw And Turbine Jaffa Japple JOSSO many Expresso Millstone ZK XAMJ Maverick Jucas Bishop Smile More… Echo2 (FreeMarker) SwingWeb Chiba Sofia (Velocity) Weblets JBanana JATO Common Controls Baracuda Jeenius Rialto Folium Action Framework JWarp Dinamica Click Shocks Genie EchoPoint JAT TeaServlet Avatar SWF MyFaces wingS Dovetail Hijax Facelets Bento Cameleon OpenXava WebOnSwing jStateMachine JFormulator RIFE DWR jZonic Melati Trails Thinlet qooXdoo10 Struts Ti 10 Why so many? • Different needs • A bad case of NIH syndrome • It’s fun writing • The de-facto standard isn’t good enough • No framework is good enough (we got to have more!) 11 11 Framework categories • Action-Based frameworks • Struts, WebWork (Struts 2), Spring-MVC • Component oriented frameworks • Wicket, Tapestry, Facelets (JSF), Echo2, ZK, Zimbra, Millstone • Template Engines integration • FreeMarker, Velocity, JSP, Tiles, Tapestry, Facelets (JSF) • Full Stack frameworks • RIFE • CRUD applications frameworks (Influenced by Ruby on Rails) • Trails, FacesFreeway, Struts Ti, RIFE-CRUD 12 12 AJAX Basics Asynchronous Javascript + XML(HttpRequest) Not a single technology but a methodology • Built on two standards: • XMLHttpRequest • DOM (XHTML) • Relies on Javascript availability 13 13 Classic web 14 14 AJAX layer added 15 15 AJAX: to the server and back again 16 16 AJAX Consequences Mostly great but… • May increase server load • User interaction is innately synchronous • May require specialized, “dirty” model behavior • No common user experience (the Feel in L&F) 17 17 The EJB Container • Entity beans • Session beans • Message Driven Beans • Resource Management and Primary Services 18 18 Entity Beans Entity beans in Java Persistence 1.0 specification are available only as plain old java objects (POJOs). To implement an entity bean you need to define a bean class and decide what field you will use as the identifier (primary key) of that identifier. In Java persistence, entity beans are not components like their EJB 2.1 counterparts. Application code works directly with the bean. So how is an entity queried? How is it stored? Is some magic involved? NO. Interaction with entity beans is done via a new service called the EntityManager. No Magic. No bytecode manipulation. No special proxies. Just Plain Java. 19 Unlike other EJB types entities can be allocated, serialized and sent across the network like any other POJO. Entity beans model real world objects. These objects are usually persistent records in some kind of database. In Java persistence application code works directly with the entity bean and does not interact through a component interface as you would with an EJB Session bean. 19 Entity bean example import javax.presistence; @Entity @Table(name=“CABIN”) public class Cabin { private int id; private string name; @Id @GeneratedValue @Column(name=“CABIN_ID”) public int getId() { return id } public void setId(int pk) { this.id = pk; } @Column(name=“CABIN_NAME”) public string getName() { return name; } public void setName(string str) { this.name = str; } } 20 20 Session beans • Definition • Interfaces • Stateful and Stateless session beans 21 21 Definition • Session beans are server side components that can be accessed using a variety of distributed object protocols. They are an extension of the client application that manage processes or tasks. • Example: A ship entity provides methods for doing things directly to a ship, but it doesn’t say anything about the context under which those actions are taken. • Session beans act as agents that manage business processes or tasks for the client. • Session beans are not persistent. They work with entity beans, data, and other resources to control workflow. 22 Booking passengers on a ship requires a ship entity, but also requires a lot of things that have nothing to do with the ship itself. We’ll need to know about passengers, ticket rates, schedules, and so on. 22 Interfaces To implement a session bean you need to define their interfaces. • Remote interface The remote interface defines a session bean’s business methods, which can be accessed from applications outside the EJB container. • Local interface The local interface defines a session bean’s business methods that can be used by other beans in the same EJB container. • Endpoint interface The endpoint interface defines business methods that can be accessed from applications outside the EJB container via SOAP. 23 The session bean class contains business logic and must have at least one remote, local or endpoint interface. bean class may also have more then one interface of a given type. The EJB container usually determines whether a session bean is remote and/or local by the interfaces it implements. The session bean class must also be tagged with the @javax.ejb.stateful or @javax.ejb.stateless annotation so that the EJB container knows what session bean type it is. 23 Stateful and Stateless session beans Session beans can be either stateful or stateless • Stateful session beans maintain conversational state when used by a client. Conversational state is not written to a database. It’s information that is kept in memory during the conversation and is lost when the conversation ends. • Stateless session beans do not maintain any conversational state. Each method is completely independent and uses only data passed in it’s parameters. Stateless session beans provide better performance and consume fewer resources then entity and stateful session beans. 24 Conversational state is kept only as long as the client application is using the bean. Once the client shuts down or releases the EJB, the conversational state id lost forever. Stateful session beans are not shared among clients;they are dedicated to the same client for the life of the enterprise bean. A few stateless session beans can serve hundreds and possibly thousands of clients. 24 Message Driven Beans • Message driven beans are integration points for other applications interested in working with EJB applications. • EJB 3.0 is not limited to JMS based message driven beans. Message driven beans can support any messaging system the implements the correct JCA 1.5 contracts. • In many ways the message driven beans are like stateless session beans. But unlike session beans that respond to business method invoked on their component interfaces, a JMS MDB responds to messages delivered through its onMesage() method. Since the messages are asynchronous the client that sends them does not expect a reply. 25 EJB 3.0 is not limited to JMS based message driven beans. Message driven beans can support any messaging system the implements the correct JCA 1.5 contracts. However, support for JMS based message driven beans in EJB 3.0 is mandatory. 25 Resource Management and Primary Services • Instance pooling • The activation mechanism • Java EE connector architecture • Primary services 26 26 Instance pooling • It’s common to pool database connections so that business objects in the system can share database access. • Most EJB containers also apply resource pooling to server side components. This technique is called instance pooling. Instance pooling is possible because clients never access beans directly. Therefore, there’s no fundamental reason to keep a separate copy of each EJB for each client. • Stateless beans exist in one of 3 states: • No state • Pooled state • Ready state 27 The server can keep a much smaller number of enterprise beans around to do the work, reusing each enterprise bean object to service different requests. No state When a bean instance is in this state it has not yet been instantiated. We identify this state to provide a beginning and end for the life cycle of a bean instance. Pooled state When an instance is in this state., it has been instantiated by the container but has not yet been associates eith an EJB request. Ready State When a bean instance id in this state, it has been associated with an EJB request and is ready to respond to business method invocation. 27 The activation mechanism • Unlike other enterprise beans stateful session beans maintain state between method invocations. Hence they cannot participate in instance pooling. • Passivation is the act of disassociating a stateful bean instance from its EJB object and saving its state.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages48 Page
-
File Size-