ejb fundamentals q
TRANSCRIPT
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 1/42
EJB Fundamentals
Swapnil Shrivastava
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 2/42
EJB Fundamentals (c)CDAC(Formerly NCST) 2
Contents Introduction
Technology Overview
EJB Architecture
EJB Specification
Sample Application
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 3/42
EJB Fundamentals (c)CDAC(Formerly NCST) 3
Sun’s Definition EJB architecture is a component architecture
for the development and deployment of
component based distributed businessapplications.
Applications written using EJB architectureare scalable, transactional, and multi-user
secure. These applications may be write once, and
then deployed on any server platform thatsupports the EJB specification.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 4/42
EJB Fundamentals (c)CDAC(Formerly NCST) 4
Short Definition EJB is a server-side component
architecture that simplifies the process
of building enterprise-class distributedcomponent applications in Java.
EJB provides standard for component
architecture.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 5/42
EJB Fundamentals (c)CDAC(Formerly NCST) 5
Enterprise Bean Server side software components that
can be deployed in distributed multi tier
environment.
They encapsulate business logic of anapplication.
Consists of one or more java objects.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 6/42
EJB Fundamentals (c)CDAC(Formerly NCST) 6
Types of Beans Session Bean
Entity Bean
Message driven Bean
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 7/42EJB Fundamentals (c)CDAC(Formerly NCST) 7
Session Bean Session beans model business
processes.
They are like ‘verbs’ because they areactions.
E.g. billing engine, catalog engine etc:
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 8/42EJB Fundamentals (c)CDAC(Formerly NCST) 8
Entity Bean Entity Bean Models business data.
They are like ‘nouns’ because they aredata objects
E.g. product, an order, an employeeetc:
Session beans typically calls entitybeans to perform business goals.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 9/42EJB Fundamentals (c)CDAC(Formerly NCST) 9
Message Driven Bean Message driven beans are similar to
session beans.
They are actions.
They are called only when they receivesome message.
E.g. : stock trade message.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 10/42EJB Fundamentals (c)CDAC(Formerly NCST) 10
EJB Architecture
EJB MessageDriven Bean
EJB Session
BeanEJB Entity
Bean
EJB SessionBean
EJB Session
Bean
EJB SessionBean
Servlet JSP
Messaging
Client
C/C++
Client
Java Applet
Java Appl
Business
Partner System
HTML
Client
Messaging CORBA-IIOP RMI-IIOP RMI-IIOP RMI-IIOP
HTTPFirewall SOAP,UDDI
WSDL,ebXML
WebServer
Application Server
PresentationTier
Business
Tier
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 11/42EJB Fundamentals (c)CDAC(Formerly NCST) 11
EJB Foundation: Distributed
Objects
Client
Skeleton
Distributed
Object
Stub
Network
Remote Interface
Remote Interface
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 12/42EJB Fundamentals (c)CDAC(Formerly NCST) 12
What do we need to worryabout now?
We take a monolithic application andbreak it into distributed system with
multiple clients connecting to multipleservers and databases over network.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 13/42
EJB Fundamentals (c)CDAC(Formerly NCST) 13
Services Remote Method
Invocation
Load Balancing Transparent Fail Over
Back end integration.
Clustering
Dynamic Re deployment
Object life cycle
Caching
Security Resource Pooling
SystemManagement
Message OrientedMiddleware
And many more….. Middleware
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 14/42
EJB Fundamentals (c)CDAC(Formerly NCST) 14
Explicit Middleware
Client
Skeleton
Distributed
Object
Stub
Network
Remote Interface
Remote
Interface
Transaction
Services
Security
Services
Database
drivers
Database API
Security API
Transaction API
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 15/42
EJB Fundamentals (c)CDAC(Formerly NCST) 15
Example – Bank account obj Transfer(Acct acc1, Acct acc2,long amt)
//1.Call middleware API to perform security
check. //2.Call middleware API to start a trans
//3.Call middleware API to load rows from db.
//4.perform trans. //5.Call middleware API to store rows in db
//6.Call middleware API to end the trans.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 16/42
EJB Fundamentals (c)CDAC(Formerly NCST) 16
Explicit Middleware Difficult to Write.
Difficult to Maintain.
Difficult to Support.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 17/42
EJB Fundamentals (c)CDAC(Formerly NCST) 17
Implicit MiddlewareClient
Skeleton
RequestInterceptor
Stub
Network
Remote Interface Remote
Interface
Transaction
Services
Security
Services
Database
drivers
Database API
Security API
Transaction API
DistributedObject
Remote
Interface
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 18/42
EJB Fundamentals (c)CDAC(Formerly NCST) 18
Example – Bank account obj Transfer(Acct acc1,Acct acc2,long amt)
//1. Perform trans.(subtract bal from one
account and add to other).
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 19/42
EJB Fundamentals (c)CDAC(Formerly NCST) 19
Implicit Middleware Easy to Write.
Easy to Maintain.
Easy to Support.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 20/42
EJB Fundamentals (c)CDAC(Formerly NCST) 20
EJB Container House enterprise bean and makes them
available to the client to invoke themremotely.
It intercepts the client request and delegatesthem to corresponding bean class.
It automatically performs implicit middleware
that the distributed object needs. EJB object is the physical part of the
container.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 21/42
EJB Fundamentals (c)CDAC(Formerly NCST) 21
EJB Component Ingredients Enterprise Bean Class
Interfaces Remote and Home interface for remote
access.
Local and Local Home interface for localaccess.
Deployment Descriptor.
Vendor Specific files.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 22/42
EJB Fundamentals (c)CDAC(Formerly NCST) 22
Enterprise Bean Class It conforms to a well defined interface.
It contains business implementation
details of our component. Each bean type has more specific
interface that extends
javax.ejb.EnterpriseBean interface. Bean class implements the interface
corresponding to the bean type.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 23/42
EJB Fundamentals (c)CDAC(Formerly NCST) 23
EJB Object Client request interceptor.
It duplicates all the business logic
methods that the corresponding beanclass exposes.
Proprietary and specific to each EJB
container.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 24/42
EJB Fundamentals (c)CDAC(Formerly NCST) 24
Remote Interface Interface to request interceptor.
Informs EJB Object auto generator
which methods to clone.
All remote interfaces must derive from javax.ejb.EJBObject.
EJB remote interfaces must confirm toRMI rules.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 25/42
EJB Fundamentals (c)CDAC(Formerly NCST) 25
Home Object EJB object factory.
Creates,finds and destroys EJB objects.
Proprietary and specific to each EJBcontainer.
Home objects implements HomeInterface.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 26/42
EJB Fundamentals (c)CDAC(Formerly NCST) 26
Home Interface EJB Object factory interface.
They define methods for
creating,destroying and finding EJBObjects.
All home interfaces must extend
javax.ejb.EJBHome. EJB remote interfaces must confirm to
RMI rules.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 27/42
EJB Fundamentals (c)CDAC(Formerly NCST) 27
Local Access Local objects make enterprise bean calls
fast and efficient.
Local objects implements Local Interface.
Local home objects creates beans fast.
Local home object implemnts Local Homeinterface.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 28/42
EJB Fundamentals (c)CDAC(Formerly NCST) 28
Deployment Descriptor Declare how the container should
perform middleware services for the
EJB component. In EJB 2.0 deployment descriptor is a
XML file.
Key to implicit middleware.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 29/42
EJB Fundamentals (c)CDAC(Formerly NCST) 29
Vendor Specific Files All vendors have proprietary value
added features.
Include files specific to that vendor.
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 30/42
EJB Fundamentals (c)CDAC(Formerly NCST) 30
Package
Remote
Interface
Local
Interface
Enterprise
Bean
Home
Interface
Deployment
Descriptor
Vendor
Specific
Jar file creator EJB jar file
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 31/42
EJB Fundamentals (c)CDAC(Formerly NCST) 31
Sample ApplicationMy First Bean!
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 32/42
EJB Fundamentals (c)CDAC(Formerly NCST) 32
Session Bean : FirstBean package example; public class FirstBean implements javax.ejb.SessionBean
{
private SessionContext ctx;
public void ejbCreate()
{
System.out.println(“ejbCreate()”);
}
public void ejbRemove()
{
System.out.println(“ejbRemove()”); }
public void ejbActivate()
{
System.out.println(“ejbActivate()”);
}
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 33/42
EJB Fundamentals (c)CDAC(Formerly NCST) 33
public void ejbPassivate()
{
System.out.println(“ejbPassivate()”);
} public void setSessionContext(javax.ejb.SessionContext ctx)
{
this.ctx=ctx;
}
public String first(){
System.out.println(“first()”);
return “My First Bean”;
}
}
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 34/42
EJB Fundamentals (c)CDAC(Formerly NCST) 34
Remote Interface : First.java package example;
public interface First extends javax.ejb.EJBObject
{
public String first() throws java.rmi.RemoteException;
}
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 35/42
EJB Fundamentals (c)CDAC(Formerly NCST) 35
Home Interface : FirstHome package example;
public interface FirstHome extends javax.ejb.EJBHome
{First create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 36/42
EJB Fundamentals (c)CDAC(Formerly NCST) 36
Deployment Descriptor<ejb-jar>
<enterprise-bean>
<session>
<ejb-name>First</ejb-name><home>example.FirstHome</home>
<remote>example.First</remote>
<ejb-class>example.FirstBean<ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-bean>
</ejb-jar>
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 37/42
EJB Fundamentals (c)CDAC(Formerly NCST) 37
Client Application package example;
import javax.naming.*;
Import java.util.*;
public class FirstClient
{
public static void main(String[] arg) throws Exception
{
Properties props=System.getProperties();Context ctx=new InitialContext(props);
Object obj=ctx.llokup(“FirstHome”);
FisrtHome home=(FirstHome)
javax.rmi.RemotePortableObject.narrow
(obj,FirstHome.class);
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 38/42
EJB Fundamentals (c)CDAC(Formerly NCST) 38
First first=home.create();
System.out.println(first.first());
first.remove();
}}
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 39/42
EJB Fundamentals (c)CDAC(Formerly NCST) 39
EJB Object Model<<interface>>
java.rmi.Remote
<<interface>>
java.io.Serializable
<<interface>>
javax.ejb.EnterpriseBean
<<interface>>
javax.ejb.SessionBean
Bean Implement
Class
<<interface>>
javax.ejb.EJBObject
<<interface>>
Javax.ejb.EJBHome
<<interface>>Remote Interface
<<interface>>Home Interface
EJB Object Home Object
Comes with Java2 platform
Comes with EJB Distribution
Written by developer
Generated by Componet Vendor Tool
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 40/42
EJB Fundamentals (c)CDAC(Formerly NCST) 40
Home
Object
EJB
Object
Enterprise
Bean
Client
Naming
Service
1 : Retrieve
Home object
Reference
2 : Return
Home object
Reference
JNDI
3: Create a new
EJB Object
4: Create a new
EJB Object
5: Return EJBObject Reference
6: Invoke Business
Method
7: Delegate Request to Bean
Remote
Interface
Home
Interface
EJB Container
7/30/2019 EJB Fundamentals q
http://slidepdf.com/reader/full/ejb-fundamentals-q 41/42
EJB Fundamentals (c)CDAC(Formerly NCST) 41
Advantages of EJB Helps to write scalable,reliable and secure
applications.
Provides distributed component framework and hence supports rapid applicationdevelopment.
Supports application portablility and
reusability across any vendor’s enterprisemiddleware services.
It is agreed upon by industry.