690 likes | 833 Views
Course #3036 Enterprise Java Beans. Patrick W. McMichael Pillar Technology Group, LLC. Your Expectations. Who are you? Where are you from? What is your role? Why are you here at this tutorial? What business challenges are you hoping J2EE can help with?. My Expectations.
E N D
Course #3036Enterprise Java Beans Patrick W. McMichael Pillar Technology Group, LLC
Your Expectations • Who are you? Where are you from? What is your role? • Why are you here at this tutorial? • What business challenges are you hoping J2EE can help with?
My Expectations • NO head-nodding -- if in doubt, ASK! • DON’T be shy! I’m going to need your help this afternoon! • Think about how the concepts presented might be applied in your domain.
Agenda • The role of the container • Bean Basics • A Closer Look… • Entity Beans • Session Beans • Message Driven Beans • Bean Info You Shouldn’t Leave Home Without • JNDI • JNDI ENC • Transactions • Exceptions • Coming Soon to a Container Near You! (EJB 2.1/3.0)
7 Primary Services (Monson-Haefel) • Concurrent access to system resources • Transaction management • Persistence • Object distribution / Location transparency • Naming / Object binding • Security • Asynchronous messaging
Tell Me About It! How have your apps depended on these services?
Approach #1 -- The MACHO Way “I coded my app…” • with vi • by candlelight • on the last ounce of laptop battery juice • barefoot • using a dial-up connection
How do you configure / manage these services? • Programmatically • Declaratively • UUM Example • intranet deployment • extranet deployment
Questions • What’s the point of using a J2EE container? What does it buy you? • What’s the advantage of declarative configuration of an app’s behavior vs. programmatic configuration?
Bean Basics EXAMPLE: The Rental Manager EJB
Break That Bean Down! • RentalManagerHome • RentalManager • RentalManagerBean • Developer Written Code vs. Generated Code • javac vs. EJB Compiler
WHY All These Classes? • Remember the primary services? • Example: “Going on a Date
EJB Server Client EJB Container Home Stub Remote / Local Home Interface EJB Home Remote / Local Home Interface EJB Object Object Stub Bean Instance Remote / Local Interface Remote / Local Interface Client Calls to Session/Entity Beans
The Special Case of the MDB Hey You!
Remote vs. Local Interfaces • The expense of RMI, Serialization, etc. • Proprietary Optimizations • Planned Localization
Remote vs. Local Interfaces --Session Façade w/ Entity Beans
Questions • Which parts of an EJB does a developer have to create? • What’s the point of the “egg yolk/eyeball” diagram? • What’s unique about MDB’s? • What’s the difference between remote and local interfaces? • When would you use one, the other, or both?
Bean Types Entity Beans
Entity Beans • Encapsulate key NOUN entities in the problem domain • eFlix Entity Bean Candidates • Persistence -- CMP vs. BMP • CMR -- introduced in EJB 2.0 • EJB QL -- also brought in by the 2.0 spec • * (shameless plug for 3138…)
Entity Bean Example • TitleHome -- Local Home Interface • create methods • find methods • remove • Title -- Local “Business” Interface • getters • setters • TitleBean -- Bean Implementation Class • ejbCreate counterparts to Home Interface • lifecycle/callback method implementation • getters/setters and the abstract persistence schema
Entity Bean Example -- EJB QL • EJB 2.0’s EJB QL provides a non-proprietary, declarative way of mapping custom finders (i.e. not by primary key) to their implementation. • findUnitsForTitleByStatus method on TitleUnitHome • SELECT OBJECT(u) FROM TitleUnit AS u WHERE u.title.productNumber = ?1 AND u.status = ?2
Entity Bean Example -- EJB QL • SELECT OBJECT(u) FROM TitleUnit AS u WHERE u.title.productNumber = ?1 AND u.status = ?2 • “TitleUnit” -- Abstract Schema Name • u -- AS clause, object usage, references • u.status -- drill down to field value • u.title.productNumber -- carry across CMR objects
Entity Beans vs. Straight JDBC • Simultaneous access to large volumes of entities -- POOL EXAMPLE -- NEED MORE OR LESS WILLING VOLUNTEERS! • Simultaneous access to same data at the same time by multiple clients (potential blocking issues) • Optimistic Concurrency • DB Schema -- stable or still in flux? • Session Façade Pattern -- clients shouldn’t know or care if entity beans JDBC, JDO, Hibernate, etc. was used.
Bean Types Session Beans
Session Beans • Handle things like... • business logic • workflow • Come in two varieties • Stateless • Stateful
Stateless Session Bean Advantages • NO Activation/Passivation • Instance Swapping between clients • fewer beans can service more clients! • Simple, Efficient Failover in a clustered environment
Session Bean Example • TitleManager Home Interface • create method • TitleManager Business Interface • business methods • TitleManager Bean Class • Session Façade Pattern • locateAvailableUnit method in façade -- more specific to a business service • findUnitsForTitleByStatus method in Entity Bean Home (uses EJB QL) -- more generalized
Bean Types Message Driven Beans
Messaging Basics “First, a little background...”
Session and Entity Beans were NOT designed to handle asynchronous processing of JMS messages. What about synchronous processing? What triggers the processing? A client call? What type of receiving would be done? Endless blocking? Timed blocking? Non-blocking? There simply were NO good options before MDBs! Before MDBs...
Asynchronous -- senders/publishers of messages are decoupled from the processing of the messages. Concurrent -- container-provided, multithreaded, concurrent message consumption Automated -- No client trigger calls are needed because... MDB Message Processing
Client Calls to MDBs The CONTAINER IS the client!
Example 1a -- Publishing to a Topic Renting Out Titles -- RentalManagerBean
Example 1b --An Example Subscriber Renting Out Titles -- CustomerRentalWorkOrderMDB
Example 1c --Run It! onMessage -- CustomerRentalWorkOrderMDB & CustomerRentalNotificationMDB
Implements MessageDrivenBean Implements MessageListener EJB 2.1 allows other options (I.e. JAXM) This is why EJB 2.0 did NOT have MessageDrivenBean extend MessageListener onMessage method (JMS) The bean pool and MDBs ejb-jar.xml ejb-borland.xml jndi-definitions.xml MDB Message Processing
Questions • What are the 3 bean types? • Which was new to EJB 2.0? Why was it added? • What are the two types of session beans? • What are the peformance differences b/t stateful and stateless and why? • What’s an alternative to a Stateful session bean in a web application?
Does your head hurt yet? Bean Info You Shouldn’t Leave Home Without