Enterprise JavaBeans. Session EJBs

Similar documents
Enterprise JavaBeans. Layer:03. Session

<<Interface>> EntityBean (from ejb) EJBHome. <<Interface>> CountHome. (from entity) create() findbyprimarykey() <<Interface>> EJBObject.

UNIT-III EJB APPLICATIONS

The Details of Writing Enterprise Java Beans

Stateless Session Bean

Q: I just remembered that I read somewhere that enterprise beans don t support inheritance! What s that about?

Oracle8i. Enterprise JavaBeans Developer s Guide and Reference. Release 3 (8.1.7) July 2000 Part No. A

Entity Beans 02/24/2004

Session Bean. Disclaimer & Acknowledgments. Revision History. Sang Shin Jeff Cutler

Enterprise Java Beans

Conception of Information Systems Lecture 8: J2EE and EJBs

Lab1: Stateless Session Bean for Registration Fee Calculation

jar command Java Archive inherits from tar : Tape Archive commands: jar cvf filename jar tvf filename jar xvf filename java jar filename.

Enterprise JavaBeans (I) K.P. Chow University of Hong Kong

Oracle9iAS Containers for J2EE

Enterprise JavaBeans. Layer:07. Entity

Lab2: CMP Entity Bean working with Session Bean

Oracle Developer Day Agenda

The Developer s Guide to Understanding Enterprise JavaBeans. Nova Laboratories

Sharpen your pencil. Container services. EJB Object. the bean

Describing the functionality of EJB using the behavior protocols

Distributed Applications (RMI/JDBC) Copyright UTS Faculty of Information Technology 2002 EJB EJB-3

Objectives. Software Development using MacroMedia s JRun. What are EJBs? Topics for Discussion. Examples of Session beans calling entity beans

Copyright UTS Faculty of Information Technology 2002 EJB2 EJB-3. Use Design Patterns 1 to re-use well known programming techniques.

This chapter describes: AssetBean AssetMgr AssetMgrEJB AssetMgrHome AssetTagAssociationBean AssetTypeBean AssociationBean AssociationMgr

Introduction to Session beans EJB 3.0

BEA WebLogic Server. Enterprise JavaBeans

Lab3: A J2EE Application with Stateful Session Bean and CMP Entity Beans

Enterprise JavaBeans: BMP and CMP Entity Beans

SCBCD EXAM STUDY KIT. Paul Sanghera CX JAVA BUSINESS COMPONENT DEVELOPER CERTIFICATION FOR EJB MANNING. Covers all you need to pass

Chapter 6 Enterprise Java Beans

Create Modules for the J2EE Adapter Engine

8. Component Software

Enterprise JavaBeans (EJB) security

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

Virus Scan with SAP Process Integration Using Custom EJB Adapter Module

Developing Portable Applications for the Java 2 Platform, Enterprise Edition (J2EE )

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER

133 July 23, :01 pm

Container Managed Persistent in EJB 2.0

J2EE Packaging and Deployment

ITdumpsFree. Get free valid exam dumps and pass your exam test with confidence

JBuilder. Getting Started Guide part II. Preface. Creating your Second Enterprise JavaBean. Container Managed Persistent Bean.

Enterprise JavaBeans. Layer:08. Persistence

Using JNDI from J2EE components

@jbossdeveloper. explained

Enterprise JavaBeans TM

Exam Questions 1Z0-895

SUN Sun Cert Bus Component Developer Java EE Platform 5, Upgrade. Download Full Version :

Life Cycle of an Entity Bean

Artix Artix for J2EE (JAX-WS)

Enterprise JavaBeans

Enterprise JavaBeans 2.1

1Z Oracle. Java Enterprise Edition 5 Business Component Developer Certified Professional Upgrade

Topexam. 一番権威的な IT 認定試験ウェブサイト 最も新たな国際 IT 認定試験問題集

Business-Driven Software Engineering (6.Vorlesung) Bean Interaction, Configuration, Transactions, Security Thomas Gschwind <thg at zurich.ibm.

NetBeans IDE Field Guide

Enterprise JavaBeans. Layer 05: Deployment

Code generation with XDoclet. It s so beautifully arranged on the plate you know someone s fingers have been all over it.

J2EE Application Server. EJB Overview. Java versus.net for the Enterprise. Component-Based Software Engineering. ECE493-Topic 5 Winter 2007

Teamcenter Global Services Customization Guide. Publication Number PLM00091 J

The 1st Java professional open source Convention Israel 2006

8. Component Software

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture

Understanding and Designing with EJB

JAVA RMI. Remote Method Invocation

Oracle EXAM - 1Z Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam. Buy Full Product.

An EJB Bean as a Client to Another Bean

Deccansoft Software Services. J2EE Syllabus

Topics. Advanced Java Programming. Transaction Definition. Background. Transaction basics. Transaction properties

Enterprise Java Beans for the Oracle Internet Platform

Borland Application Server Certification. Study Guide. Version 1.0 Copyright 2001 Borland Software Corporation. All Rights Reserved.

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

JBuilder EJB. Development Using JBuilder 4 and Inprise Application Server 4.1. Audience. A Step-by-step Tutorial.

ITcertKing. The latest IT certification exam materials. IT Certification Guaranteed, The Easy Way!

Overview p. 1 Server-side Component Architectures p. 3 The Need for a Server-Side Component Architecture p. 4 Server-Side Component Architecture

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

Advanced Java Programming

IBM. Application Development with IBM Rational Application Developer for Web Sphere

SDN Community Contribution

JSpring and J2EE. Gie Indesteege Instructor & Consultant

Practice Test. Oracle 1z Java Enterprise Edition 5 Business Component Developer Certified Professional Upgrade Exam. Version: 14.

TIBCO BusinessWorks EJB Plug-in User s Guide. Software Release 5.3 February 2008

JAVA. Aspects (AOP) AspectJ

IBD Intergiciels et Bases de Données

5. Enterprise JavaBeans 5.4 Session Beans. Session beans

On Performance of Enterprise JavaBeans

J2EE. Enterprise Architecture Styles: Two-Tier Architectures:

The Evolution to Components. Components and the J2EE Platform. What is a Component? Properties of a Server-side Component

Using Message Driven Beans.

Component-Based Platform for a Virtual University Information System

Grid Computing. Java Remote Method Invocation (RMI) RMI Application. Grid Computing Fall 2006 Paul A. Farrell 9/5/2006

SAP NetWeaver Process Integration 7.1 Developing User Enhancement Modules in the Adapter Engine

presentation DAD Distributed Applications Development Cristian Toma

1 interface TemperatureSensor extends java.rmi.remote 2 { 3 public double gettemperature() throws java.rmi.remoteexception; 4 public void

Introduction. Enterprise Java Instructor: Please introduce yourself Name Experience in Java Enterprise Edition Goals you hope to achieve

Applying Aspect Orientation to J2EE Business Tier Patterns

Plan. Department of Informatics. Advanced Software Engineering Prof. J. Pasquier-Rocha Cours de Master en Informatique - SH 2003/04

J2EE Web Development 13/1/ Application Servers. Application Servers. Agenda. In the beginning, there was darkness and cold.

Module 8 The Java Persistence API

Transcription:

Enterprise JavaBeans Dan Harkey Client/Server Computing Program Director San Jose State University dharkey@email.sjsu.edu www.corbajava.engr.sjsu.edu Session EJBs Implement business logic that runs on an EJB server Are not shared between clients--logical extension of a single client Do not maintain persistent state Two types Stateless--no client specific state is maintained between client method calls Stateful--can maintain conversational state Copyright 2001-2002, Dan Harkey. All rights reserved. Page 1-2

Session EJB Component Contract Serializable (from io) EJBContext EnterpriseBean SessionBean ejbactivate() ejbpassivate() ejbremove() setsessioncontext() YourSessionBean SessionSynchronization afterbegin() aftercompletion() beforecompletion() Optional getcallerprincipal() : Principal getejbhome() : EJBHome getrollbackonly() : boolean getusertransaction() : UserTransaction iscallerinrole(arg0 : String) : boolean setrollbackonly() : void SessionContext getejbobject() ejbcreate() businessmethod() Session EJB Client/Server Contract Remote (from rmi) EJBMetaData EJBObject getejbhome() gethandle() getprimarykey() isidentical() remove() YourRemoteInterface businessmethod() EJBHome getejbmetadata() gethomehandle() remove() YourHomeInterface create() getejbhome() gethomeinterfaceclass() getprimarykeyclass() getremoteinterfaceclass() issession() Handle getejbobject() Serializable (from io) HomeHandle getejbhome() Copyright 2001-2002, Dan Harkey. All rights reserved. Page 3-4

EJB Development Process The Count Stateless EJB Copyright 2001-2002, Dan Harkey. All rights reserved. Page 5-6

Count Stateless Session EJB EJBHome SessionBean CountClient (from statelesssession) sum main() CountHome (from statelesssession) create() EJBObject Count (from statelesssession) CountEJB (from statelesssession) CountEJB() ejbcreate() ejbactivate() ejbpassivate() ejbremove() setsessioncontext() increment() increment() Stateless Session EJB State Diagram Copyright 2001-2002, Dan Harkey. All rights reserved. Page 7-8

Count Stateless Session Interaction Diagram : CountClient JNDI : InitialContext EJB Home : CountHome EJB Object : Count EJB : CountEJB 1: new() 2: lookup(jndihomename) 3: new() 4: create() 5: new() 6: new() 7: setsessioncontext(sessioncontext) 8: ejbcreate( ) 9: increment(sum) 10: increment(sum) Home Interface for Stateless Session EJBs Extends the EJBHome interface. It can also extend other interfaces but must follow the RMI-over-IIOP rules for interface definition Declares one method named create which has no parameters. The create method returns a reference to a remote interface for the bean and throws CreateException and RemoteException Copyright 2001-2002, Dan Harkey. All rights reserved. Page 9-10

Rules for Writing RMI-IIOP Interfaces The interface must extend, either directly or indirectly, the interface java.rmi.remote. This happens automatically for enterprise beans as the EnterpriseBean interface extends java.rmi.remote Each method declaration must satisfy the requirements of a remote method declaration. These requirements are: A remote object declared as a parameter or return value must be declared as a remote interface, not the implementation class of that interface Rules for Writing RMI-IIOP Interfaces (continued) Each method must throw RemoteException Method parameters or return types must be a Java object that is serializable. This includes Java primitive types, remote Java objects, and non-remote Java objects that implement the java.io.serializable interface. A remote interface may also extend another non-remote interfaces, as long as all of the methods (if any) of the interface being extended satisfies the requirements of a remote method declaration. Copyright 2001-2002, Dan Harkey. All rights reserved. Page 11-12

Count Stateless Session EJB: Home Interface // CountHome.java package count.statelesssession; import javax.ejb.ejbhome; import java.rmi.remoteexception; import javax.ejb.createexception; public interface CountHome extends EJBHome { public Count create() throws RemoteException, CreateException; } Remote Interface for Stateless Session EJBs Extends the EJBObject interface. It can also extend other interfaces but again, it must follow the RMI-over-IIOP rules for interface definition. Declares the business methods the enterprise bean will support. These methods must have valid RMI-over-IIOP return types and arguments and must declare RemoteException in addition to any other exceptions thrown by the matching method in the bean class. Copyright 2001-2002, Dan Harkey. All rights reserved. Page 13-14

Count Stateless Session EJB: Remote Interface // Count.java package count.statelesssession; import javax.ejb.ejbobject; import java.rmi.remoteexception; public interface Count extends EJBObject { public int increment(int sum) throws RemoteException; } Class for Stateless Session EJBs May extend other classes or interfaces but bean class or one of it s parent classes must implement the SessionBean interface. The class must be public and must not be abstract or final. It must provide a default, no-argument constructor and it must not have a finalize method. Copyright 2001-2002, Dan Harkey. All rights reserved. Page 15-16

Class for Stateless Session EJBs (continued) The bean class or one of it s parent classes must implement the ejbcreate method (note that ejbcreate returns a void) and any business methods declared in the remote interface. The bean class can implement helper and private methods that are not exposed to clients of the enterprise bean. Count Stateless Session EJB Class // CountBean.java package count.statelesssession; import javax.ejb.*; import java.rmi.remoteexception; public class CountEJB implements SessionBean { // no arg contructor public CountEJB() {} } public void ejbcreate() {} public void ejbactivate() {} public void ejbpassivate() {} public void ejbremove() {} public void setsessioncontext(sessioncontext ctx ) {} public int increment(int sum) { return ++sum; } Copyright 2001-2002, Dan Harkey. All rights reserved. Page 17-18

Count Stateless Session EJB: EJB Deployment Descriptor <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'> <ejb-jar> <description>no description</description> <display-name>ejb1</display-name> <enterprise-beans> <session> <description>no description</description> <display-name>countstateless</display-name> <ejb-name>countstateless</ejb-name> <home>count.statelesssession.counthome</home> <remote>count.statelesssession.count</remote> <ejb-class>count.statelesssession.countejb</ejb-class> <session-type>stateless</session-type> <transaction-type>bean</transaction-type> </session> </enterprise-beans> </ejb-jar> Count Stateless Session EJB: Application Deployment Descriptor <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com/j2ee/dtds/application_1_2.dtd'> <application> <display-name>countstateless</display-name> <description>application description</description> <module> <ejb>ejb-jar27688.jar</ejb> </module> </application> Copyright 2001-2002, Dan Harkey. All rights reserved. Page 19-20

Count Stateless Session EJB: J2EE RI Specific Deployment Descriptor <?xml version="1.0" encoding="utf-8"?> <j2ee-ri-specific-information> <server-name></server-name> <rolemapping /> <enterprise-beans> <ejb> <ejb-name>countstateless</ejb-name> <jndi-name>statelesssessioncounthome</jndi-name> </ejb> </enterprise-beans> </j2ee-ri-specific-information> Steps Peformed by an EJB Client Look up the enterprise bean s home using JNDI Create an instance of the bean Call business methods on the bean Remove the bean when it is no longer needed Copyright 2001-2002, Dan Harkey. All rights reserved. Page 21-22

Steps Performed to Look Up an EJB's Home Interface Using JNDI Creating an instance of the JNDI InitialContext object Call the lookup method of the InitialContext object to find the bean s home. A string name is passed to the lookup method to identify the bean s home The object that is discovered using the lookup method is cast to the correct type using the narrow method of the PortableRemote object Classes used by a JNDI Client Context (from naming) InitialContext (from naming) InitialContext() addtoenvironment() bind() close() composename() createsubcontext() destroysubcontext() getenvironment() getnameinnamespace() getnameparser() list() listbindings() lookup() lookuplink() rebind() removefromenvironment() rename() unbind() Copyright 2001-2002, Dan Harkey. All rights reserved. Page 23-24

Count Stateless Session EJB: Client (1 of 3) // CountClient.java package count.statelesssession; import count.statelesssession.count; // Count EJB Remote import count.statelesssession.counthome; // Count EJB Home import java.rmi.*; import java.util.*; import java.io.*; import javax.rmi.*; import javax.naming.*; import javax.ejb.*; public class CountClient { public static void main ( String args[] ) { int sum; // current sum CountHome counthome; Count Stateless Session EJB: Client (2 of 3) try { // Get the initial JNDI context System.out.println("Getting initial context"); InitialContext context = new InitialContext(); // Find the home interface and narrow to CountHome Object object = context.lookup("statelesssessioncounthome"); counthome = (CountHome)PortableRemoteObject.narrow(object, CountHome.class); // Create EJB System.out.println("Creating EJB"); Count count = counthome.create(); // Set sum to initial value of 0 System.out.println("Setting sum to 0"); sum = 0; Copyright 2001-2002, Dan Harkey. All rights reserved. Page 25-26

Count Stateless Session EJB: Client (3 of 3) // Calculate Start time long starttime = System.currentTimeMillis(); // Increment 1000 times System.out.println("Incrementing"); for (int i = 0 ; i < 1000 ; i++ ) { sum = count.increment(sum); } // Calculate stop time; print out statistics long stoptime = System.currentTimeMillis(); System.out.println("Avg Ping = " + ((stoptime - starttime)/1000f) + " msecs"); System.out.println("Sum = " + sum); } catch(exception e) { System.err.println("Exception"); System.err.println(e); } } Copyright 2001-2002, Dan Harkey. All rights reserved. Page 27-28