Brad Rippe Fullerton College. What you need to get started? JDK 1.3 standard for compilation J2EE - SDK1.2.1 App Server - An EJB Container/Web Container.

Slides:



Advertisements
Similar presentations
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
Advertisements

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Universität Bonn, Seminar Softwaretechnologie SS 2003, Duc Luu 1 Topics: Java Remote Method Invocation (RMI) Enterprise JavaBeans (EJB) Overview.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
SEI/CBS Initiative Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
CS 483 Enterprise and Web Application Programming
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Fundamentals Celsina Bignoli
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
15 - RMI/EJBCSC4071 Distributed Objects Java Remote Method Invocation Enterprise Java Beans.
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
EJB Enterprise Java Bean.
Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)
Writing Enterprise Applications with J2EE (Second lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Entity Beans BMP Celsina Bignoli
Middleware Technology (J2EE/EJB) Entity Bean. 2 Introduction to Entity Beans Persistence Concepts Entity beans are persistent objects that can be stored.
Lecture 8 Advanced Topics in Enterprise JavaBeans.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
Presented By Pradeep K Sahu. What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Introduction to J2EE Architecture Portions by Kunal Mehta.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Enterprise Java Bean Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
J2EE Structure & Definitions Catie Welsh CSE 432
Session Beans -) stateless -) stateful. Session Beans A session bean represents a single client inside the J2EE server. To access an application that.
A TUTORIAL TO USING EJBs by SHREERAM IYER 09/17/2001.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Enterprise Java Bean Technology Briefing Markus Hebach.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
Enterprise Java Beans Ye Zhou CS6704 Presentation Virginia Tech.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Introduction to J2EE Architecture
Objectives In this lesson, you will learn to:
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Brad Rippe Fullerton College

What you need to get started? JDK 1.3 standard for compilation J2EE - SDK1.2.1 App Server - An EJB Container/Web Container Example uses Jboss 2.4 with Tomcat A good editor

What is a EJB? JavaBean? Java Classes? GUI? Are EJBs part of the J2EE? What is J2EE?

What is a EJB? Enterprise JavaBeans (EJBs) are distributed object that are hosted in Enterprise JavaBean Containers and provide remote services for clients distributed throughout the network. This components encapsulate business logic

Why EJB? (Distributed Computing) Enterprise Applications Development Costs Deployment Costs Maintenance Costs Service More Clients More Bang for the Buck!

J2EE Architecture This is an illustration of the architecture set forth by Sun. See

Containers and Services EJB Containers provide additional services for the (EJBs). Life-Cycle Management, Transaction Management, Security, Persistence, Resource Management.

EJB Container Similar to the Web Container EJBs require a container to function The contain isolates the EJB from direct access from client application. Manages remote access to EJBs. Provided by an Application Server. JBoss, WebLogic, JRun, Borland App Server, etc.

EJB Advantages Productivity Container services are provided automatically. Developer can focus on the business logic without Infrastructure Container management is inherently robust. Supports scalability Portability EJB Spec provides a well-defined contract for EJB Containers

How does the EJB get the services? EJBs can access container services through one of three ways Callback methods The EJBContext interface Java Naming and Directory Interface

CallBack Methods Each EJB is required to implement a subtype of EnterpriseBean interface which defines callback methods. Each callback method provides a way for the container to notify the EJB about an event in the bean’s lifecycle, i.e. removing a bean from memory. The callback methods give the EJB a chance to do some internal housework before or after an event occurs. These are the bean’s event handlers.

EJBContext Every EJB obtains an EJBContext object which is a reference directly to the EJB Container. The EJBContext interface provides methods for interacting with the container so that the EJB can request information about its environment.

Java Naming and Directory Interface (JNDI) JNDI is the standard extension to the Java platform for accessing naming systems like LDAP, NetWare, NDS, file systems. Every EJB automatically has access to a special naming system called the Environmental Naming Context (ENC). The ENC is managed by the container. It allows an EJB to access resources like JDBC connection, other EJBs, and its own properties.

Roles of Application Builders Bean Provider an application developer and, often, a domain expert – builds reusable components without focusing on the framework. Assembler Combines finished EJBs into modules and combines those and other J2EE building blocks into applications, making container neutral- decisions. Deployer Deploys J2EE applications in a specific environment, and make container-specific decisions.

Two Main Types of Beans Session Beans Stateless calculating sales tax, or processing and order Stateful Common Shopping cart component Entity Beans CMP (Container-Managed Persistence) BMP (Bean-Managed Persistence) Message-Driven Beans (Introduced in 2.0) This is a JMS bean. Designed for sending and receiving JMS messages.

Creating EJBs All ejbs implement a subtype of EnterpriseBean. Either SessionBean, EntityBean, or MessageDrivenBean. Each of the subInterfaces declares callback methods for the container. To create an EJB a developer provides: A home interface defines the life-cycle methods of the bean A remote interface defines the business methods of the bean class. A bean class business logic, the meat is here

Conceptual Model Bean Class Home Remote Client Home Remote Application Server EJB Container

Home Interface Extends javax.ejb.EJBHome This interface declares create and find methods. EJB Container implements this interface Clients use JNDI to locate the vendors home class.

Remote Interface Extends javax.ejb.EJBObject Client view and get access to the EJB through the bean’s remote interface. Methods a client can call are declared here. The actually implementation of those business methods is located in the bean class. Gives a client a handle to the EJB

How the do interfaces work? The container creates a class that implements the Home interface and makes it available to JNDI. The container creates a class that implements the Remote interface which acts like a middleman between the bean and the client.

Bean Class Implements javax.ejb.EntityBean if it is an EntityBean Implements javax.ejb.SessionBean if it is an SessionBean This class defines the methods declared in the Home and Remote interfaces. Defines finder, create and business methods of the EJB.

Enity Beans versus Session Beans Entity Beans Persistent Part of permanent storage Should communicate with Session Beans Should not communicate with clients Read and write access to the data store Session Beans Not persistent Does not survive server crash Can access the database for queries Communicates with client via interfaces

Session Bean  Session Beans should be used for short requests that can be satisfied with one method.  Session Beans require low resource costs  Easy for the container to manage  Promotes fast response back to the client  Can be stateful or stateless  Client receive only one stateful bean for service  Clients share stateless beans  Two type of transaction modes  CMT – Container Managed Transaction  BMT – Bean Managed Transaction

Entity Bean Has a direct relation to database row. Database data types are converted into java data types and encapsulated into the Entity Bean. Entity beans must have a defined primary key data type or compound object as its primary key. Require more overhead to maintain state between the database and the EJB object. Entity bean have persistent data. Persistence can be one of two persistence modes: CMP – Container-Managed Persistence BMP – Bean-Managed Persistence

Scenario 1 – Session Bean Example Client Session Bean Data Store Session Bean

Scenario 2 – Entity Bean Example Client Session Bean Data Store Session Bean Entity Bean

Building a Session Bean Example uses one Session Bean, two different clients to access the bean’s business methods Business method – calculateStockPrice( String ticker, int numShares ) Calculates the price of stock for four different companies.

Where to begin? First, download Jboss – or some other app server. App Server must support EJBs. Version integrated with Tomcat is preferred! Second, unzip the archive into the directory where it will be located permanently on your server. I chose a directory like “e:\appServer\” Third, on to the code…

StockBalanceBean Example Requires a home interface Requires a remote interface Requires the bean class Requires the Deployment Descriptor Some packaging? A client or two Deploy

StockBalanceBean Home Interface package edu.fullcoll.exampleEJB; import java.rmi.RemoteException; public interface StockBalanceHome extends EJBHome { StockBalance create() throws CreateException, EJBException, RemoteException; }

StockBalanceHome Home Interface Provides lifecycle methods for creating, destorying and locating EJBs Separate from the remote interface because the home interface is not associated with one instance of an EJB Home interface extend javax.ejb.EJBHome interface

StockBalance Remote Interface package edu.fullcoll.exampleEJB; import java.rmi.RemoteException; public interface StockBalance extends EJBObject { double calculateStockPrice(String ticker, int numShares) throws RemoteException, EJBException; }

StockBalance Remote Interface Declares the business methods available in EJB class. The this is the clients way of communicating with the EJB. The EJB container creates an object that implements this remote interface and returns it to the client. Can be associated with one instance of an EJB.

StockBalanceBean – Bean Class public class StockBalanceBean implements SessionBean { public double calculateStockPrice(String ticker, int numShares){ if( ticker != null) { ticker = ticker.toUpperCase(); if(ticker.equals( "AAPL" )) { return numShares * 20.42; } else if(ticker.equals( "MSFT" )) { return numShares * 64.84; } else if(ticker.equals( "YHOO" )) { return numShares * 16.70; } else if(ticker.equals( "SUNW" )) { return numShares * 13.84; } return 0.0; }

StockBalanceBean Implements SessionBean interface public void ejbActivate() { } public void ejbPassivate() { } public void setSessionContext(SessionContext ctx) {} public void ejbRemove() {} public void ejbCreate() {}

EJBs and RMI The remote and home interfaces are types of Java RMI remote interfaces. This means that the EJB, even though instantiated in the EJB container, can have its methods invoked as a result of a request from an outside application. The RMI stub and skeleton hide the communication specifics from the client.

EJBs and RMI Stub Skeleton EJB Object EJB Object ClientNetwork App Server

Final Steps Home, Remote and Bean class are created. Create a deployment descriptor Package the EJBs Deploy the beans to the App Server

ejb-jar.xml Must be stored in the jar’s META-INF directory. XML document. Describes the EJB setup, transaction mode, JNDI name, security, and persistence. Can be created by hand, not recommended. J2EE deploytool Another GUI tool to generate the xml… Recommended…

ejb-jar.xml Let’s take a look…

Packaging the EJBs Again you can use a tool like Together’s Control Center or the deploytool. Or Create a jar file with your ejb classes in it and the deployment descriptor in the META-INF directory. This file will have a.jar extension. Name the jar an arbitrary name, StockBeanEJBs.jar

Creating a client - local  Let’s take a look…

Creating a client - Remote Let’s take a look…

How does a client lookup a bean? A client needs to know two things: The JNDI name of the Bean The vendor-specific syntax for getting the InitialContext.

Deployment To deploy the bean in jboss, simply copy the EJB jar to the “deploy” directory. 2.4 handles hot deploy, so if you update your EJBs you can copy the new jar into the “deploy” directory and the EJBs will be updated…

Info about client compilation Your client code must be compiled with the following jars. ejb.jar – standard javax.ejb.* jaas.jar – Java security classes jbosssx-client.jar – JBossSX security classes jboss-client.jar – EJB container proxy and stub classes jnp-client.jar – jboss JNDI provider client classes

Entity Beans Provides object representation of data. One entity bean can represent data for multiple clients. Represents a row in the database. Model business objects, nouns, Person, Seat, Room, etc. Container handles persistence, transactions, and access control

Two types of Entity Beans Bean-Managed Persistence (BMP) Develop provides all of the code for managing persistence between the object and the database. The container will notify the bean when its necessary to update or read from the database. Container-Managed Persistence (CMP) The EJB Container handles the relationship between the bean and the database. Bean developer can focus on the data and the business process.

Using Entity Beans CMP Recommended for beginners Handles simple relationships with the database. (one row) BMP Used for more complex relationships. Beans that represent multiple rows or table joins. This code is implemented by the developer

Entity Bean Requirements Home Interface Remote Interface Bean class – implements EntityBean Primary Key – can be a java class or primitive type. Points to a unique record in the database. All Entity beans must have a primary key that is serializable.

Creation The entity bean’s home interface declares a method create(). The bean class must define methods ejbCreate() and ejbPostCreate(). ejbCreate() and ejbPostCreate() must have the same parameters as create() from the home interface. create() Inserts a row into the database. ejbPostCreate()- provides a method for accessing the EJB’s remote method (this).

Callback Methods setEntityContext() unsetEntityContext() ejbLoad() ejbStore() ejbActivate() ejbPassivate() ejbRemove() CMP - the container decides when to call these methods and their implementation. BMP - the container decides when to call these methods and the developer provide the implementation.

Find Methods Find methods in the Home interface are used to query the EJB server for specific entity beans. CMP the find methods are implemented by the container. There isn’t any code in the bean class. Clients can call find methods to obtain a reference to a particular bean’s remote interface. Can return a single reference or an Enumeration or Collection of references. FCStudentBean brad = (FCStudentBean) home.findStudent( );

Entity Beans Example - Home package edu.fullcoll.schedule; import java.rmi.RemoteException; Import javax.ejb.EJBHome; public interface FCStudentHome extends EJBHome { public FCStudentRemote create(int pidm) throws CreateException, RemoteException; public FCStudentRemote findByPrimaryKey(int pk) throws FinderException, RemoteException; }

Entity Beans Example - Remote package edu.fullcoll.schedule; import java.rmi.RemoteException; Import javax.ejb.EJBObject; public interface FCStudentRemote extends EJBObject { public String getName() throws RemoteException; public void setName(String n) throws RemoteException; }

Entity Beans Example – Bean Class public class FCStudent implements EntityBeans { public int pidm; public String name; public int ejbCreate(int pidm) { this.pidm = pidm; return null; } public String getName() { return name; } public void setName(String n) { name = n; } // all callback methods must be defined, but blank for CMP }

J2EE Comprised of many different technologies JSP/Servlets JDBC JNDI JTA JMS, jetc, jetc

Summary Similar to other technologies, EJBs have there place in software development. EJBs are not a solution for all development problems. They are meant for transactional, secure business applications, reservation systems, student registration, online purchasing. They are highly scalable components meant for use in complex, mission-critical applications.

Resources Jboss – Tomcat – J2EE Web Site – J2EE Tutorial – EJB Spec – Lecture available at

Resources J2EE Developer’s Guide – ocs/guides/ejb/html/DevGuideTOC.html ocs/guides/ejb/html/DevGuideTOC.html J2EE Tutorial – fcs/index.html fcs/index.html Server Side Programming –

The End! Thanks for you time!