Title: 1' JavaJ2EERMI overviewKoteswara Kommineni, Uday Rivella
1Team Presentations Outline
- 1. Java/J2EE/RMI overview-Koteswara Kommineni,
Uday Rivella - 2. EJB Overview
- EJB Concepts -Sarah Lee
- EJB Component Life Cycle, code walkthrough -
Tracey Wilburn - 3. Development Methodology-Manjeera Madduri, Xing
Ruan - 4. CMMI-related Challenges with EJB Component
Development - Kavita Kolli - 5. Summary/Comparison - Shekhar Vemuri
2Topic 2 Enterprise Java Bean Technology Technical
Concepts Sarah B. Lee April 16, 2003
3Java Review
- Java 2 Platform, Enterprise Edition (J2EE)
- component-based, platform independent
architecture - Java Naming Directory Interface (JNDI)
- provides unified interface to directory naming
services - Remote Method Invocation (RMI)
- provides a means of communicating between Java
apps on separate machines
4Enterprise Java Beans Model
- Provides a framework for component based
distributed computing - specifies how distributed components should work
within the Java environment - Makes thin-client, multi-tiered apps easier to
write - separates low-level details from business logic
5What is an Enterprise Java Bean?
- Body of code written to implement modules of
business logic - Standard extension to Java
- available in javax.ejb package
- latest version http//www.javasoft.com/products/e
jb - must be explicitly installed to write code
against EJB interfaces
6EJB Component Model
EJB Server
Client
EJB Container
client request
EJB
The container manages the enterprise beans at
runtime
7EJB Application Server
EJB Server
Client
EJB Container
client request
- Required when using EJB
- Contains EJB containers which
manage EJB objects - Primary goals
- Improve performance
- Simplify development
- Most important feature efficient resource
management
EJB
- iPlanet/Netscape (AOL/Netscape/Sun)
- NetDynamics (Sun)
- Weblogic (BEA)
- WebSphere (IBM)
8EJB Containers
EJB Server
Client
- Set of classes that manage an enterprise beans
- Persistence
- bean state maintained in permanent data
store - Start, enrollment, commitment, and rollback of
transactions - Security
- Insulate the EJBs from direct access from client
applications - whenever a bean is requested, created, or
deleted, the container manages the whole process
EJB Container
client request
Persistence Mgmt Transaction Mgmt Security Mgmt
EJB
Containers live and operate inside EJB Servers
9EJB Interfaces
Each enterprise bean exposes 2 interfaces via the
container to the client
- Home Interface
- Defines the methods that allow clients to create,
find, and remove EJB objects - Creates instances of the remote interface for an
enterprise bean - Remote Interface
- Used by client to invoke operations on the bean
- Describes what the bean does
10Types of EJBs
- Session bean
- a transient object
- lifespan is limited to that of the client
- works with one client
- business logic
- Entity bean
- a persistent object
- lifespan is as long as the database
- multiple clients simultaneously
- represents data in a database
11Session Beans
- Created by client
- exist only for duration of single client/server
session - Performs operations on behalf of client
- ex performing calculations
- Normally not recoverable after system crash
12Session Beans
- Two types
- Stateful
- keeps information across http requests
- Stateless
- information is not kept
13Entity Beans
- Persistent
- state is maintained in permanent data store
- exists as long as the corresponding data exists
in the database - Can be recovered after system crash
- Each bean identified by primary key
- unique identifier that enables client to locate
particular entity bean - ex customer entity bean might be identified by
customer number
14Entity Beans
- Two Types of Persistence
- bean-managed
- container-managed
15Entity Beans Bean-Managed Persistence
- Entity bean code contains the calls that access
the database - Programmer is responsible for coding the insert
statement and any other necessary SQL
16Entity Beans Container-Managed Persistence
- Container automatically generates necessary
database access calls - ex when client creates entity bean, container
generates SQL Insert - Programmer code contains no SQL calls
- Entity bean is independent of any particular
database
17EJB Server
Entity Home
Entity Bean
Database
JNDI
Entity Remote
Container
RMI
Browser
Client App
Session Home
JNDI
Session Bean
RMI
Session Remote
Container
- Client application
- Interacts with EJBs through home and remote
interfaces - EJB Server
- Handles low-level details including database I/O
- Container
- Provides interface between EJB and low-level
platform specific functionality
- Home Interface
- Describes how client creates, finds, removes EJB
from container - Located by client using JNDI
- Remote Interface
- Describes beans methods (what it does)
- Client calls methods defined in remote interface
to invoke business logic - Invoked using RMI
18Typical Enterprise JavaBeans Network Security
Topology
Applets
Web server
EJB Server
Internet
Browsers
Web server
EJB Server
Enterprise information
Applications
DMZ
Firewall 2
Firewall 1
19Benefits of Using EJB
- Productivity
- Industry Support
- Architectural Independence
- Server-Side Write Once, Run Anywhere?
20Topic 2 Enterprise Java Bean Technology Code
Walkthrough Tracey Wilburn April 16, 2003
21Coded Example of EJB Object
- Hello World
- stateless session bean
- EJB Environment
- interaction between code
22Client Code
- Purpose
- Locate an object
- Create a new instance of an object
- Obtain business method operation
23Locate an Object
- JNDI (Java Naming and Directory Interface)
- Four steps to locate an object
- Initialize JNDI properties
- Initialize Naming Context
- Lookup the Object
- Narrow the Object
24Deployment Identifier
- tells the container the name to use for
registering the beans home interface in the JNDI - must be unique
25Client Code
- import javax.rmi.
- import javax.naming.
- import java.util.
- public class HelloWorld
- public static void main( String args)
- try
-
- Properties p new Properties()
-
- //The JNDI properties you set depend
- //on which server you are using.
- //These properties are for the Remote Server.
- p.put("java.naming.factory.initial",
"org.openejb.client.RemoteInitialContextFactory")
- p.put("java.naming.provider.url",
"127.0.0.14201") - p.put("java.naming.security.principal",
"myuser") - p.put("java.naming.security.credentials",
"mypass") -
26Client Code (Cont.)
- //Use the HelloHome to create a HelloObject
- HelloHome ejbObject ejbHome.create()
-
- //The part we've all been waiting for...
- String message ejbObject.sayHello()
- //A drum roll please.
- System.out.println( message )
-
- catch (Exception e)
- e.printStackTrace()
-
-
27Developing an EJB Object
- Home Interface
- Remote Interface
- Enterprise Bean Implementation
28EJB Specifications
- Home Interface
- throws CreateException
- throws RemoteException
- create( )
29Home Interface Code
- import java.rmi.
- import javax.ejb.
- import java.util.
- public interface HelloHome extends EJBHome
- public HelloObject create() throws
RemoteException, CreateException -
30EJB Specification
- Remote Interface
- throws RemoteException
- Methods defined must match methods in EJB class
- Signature of methods must be identical to methods
in EJB class
31Remote Interface Code
- import java.rmi.
- import javax.ejb.
- import java.util.
- public interface HelloObject extends EJBObject
- public String sayHello() throws
RemoteException -
32EJB Specifications
- Enterprise Bean Implementation
- void ejbPassivate()
- void ejbActivate()
- void ejbCreate()
- void ejbRemove()
- void setSessionContext()
33EJB Specification
- Enterprise Bean Implementation
- Implement Business Method
- EJB class must be defined as public
34Enterprise Bean Implementation Code
- import java.rmi.RemoteException
- import javax.ejb.
- public class HelloBean implements SessionBean
- private SessionContext sessionContext
- public void ejbCreate()
-
- public void ejbRemove()
-
- public void ejbActivate()
-
- public void ejbPassivate()
-
- public void setSessionContext(SessionContext
sessionContext) - this.sessionContext sessionContext
-
- public String sayHello() throws
java.rmi.RemoteException - return "Hello World!!!!!"
-
35EJB Example Code
EJB Server
EJB Container
Home Interface
Lookup
Client
Remote Interface
EJB
36EJB Example Code
EJB Server
Reference of Home Interface
EJB Container
Home Interface
Client
Remote Interface
EJB
37EJB Example Code
EJB Server
EJB Container
Home Interface
Client
create( )
ejbCreate()
Remote Interface
EJB
38EJB Example Code
EJB Server
EJB Container
Home Interface
Client
Remote Interface
Reference of Remote Interface
EJB
39EJB Example Code
EJB Server
EJB Container
Home Interface
Client
Locate business method
Remote Interface
EJB
Business method invoked
40EJB Example Code
EJB Server
EJB Container
Home Interface
Client
Remote Interface
EJB
Returns business method