ejb basics
Post on 29-May-2018
261 Views
Preview:
TRANSCRIPT
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 1/42
EJB Fundamentals
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 2/42
Contents Introduction
Technology Overview EJB Architecture
EJB Specification
Sample Application
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 3/42
Suns Definition EJB architecture is a component architecture
f or 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 platf orm that supports the EJB specification.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 4/42
Short Definition EJB is a server-side component
architecture that simplifies the processof building enterprise-class distributedcomponent applications in Java.
EJB provides standard f or component
architecture.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 5/42
Enterprise Bean Server side software components that
can be deployed in distributed multi tierenvironment.
They encapsulate business logic of anapplication.
Consists of one or more java objects.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 6/42
Types of Beans Session Bean
Entit y Bean Message driven Bean
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 7/42
Session Bean Session beans model business
processes.
They are like verbs because they areactions.
E.g. billing engine, catalog engine etc:
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 8/42
Entit y Bean Entit y Bean Models business data.
They are like nouns because they aredata objects
E.g. product, an order, an employeeetc:
Session beans t ypically calls entit y beans t o perf orm business goals.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 9/42
Message Driven Bean Message driven beans are similar t o
session beans.
They are actions.
They are called only when they receivesome message.
E.g. : st ock trade message.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 10/42
EJB Architecture
EJB MessageDriven Bean
EJB Session
BeanEJB Entity
Bean
EJB SessionBean
EJB Session
Bean
EJB SessionBean
Servlet JSPMessaging
Client
C/C++
Client
Java Applet
Java Appl
BusinessPartner System
HTMLClient
Messaging CORBA-IIOP RMI-IIOP RMI-IIOP RMI-IIOP
HTTPFirewall SOAP,UDDI
WSDL,ebXML
WebServer
Application Server
Presentation
Tier
Business
Tier
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 11/42
EJB Foundation: Distributed
Objects
Client
Skeleton
Distributed
Object
Stub
Network
Remote Interface
Remote Interface
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 12/42
What do we need t o worry about now?
We take a monolithic application andbreak it int o distributed system withmultiple clients connecting t o multipleservers and databases over network.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 13/42
Services Remote Method
Invocation
Load Balancing Transparent Fail Over
Back end integration.
Clustering
Dynamic Re deployment
Object life cycle
Caching
Securit y Resource Pooling
SystemManagement
Message OrientedMiddleware
And many more..Middleware
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 14/42
Explicit Middleware
Client
Skeleton
Distributed
Object
Stub
Network
Remote Interface
Remote
Interface
Transaction
Services
SecurityServices
Database
drivers
Database API
Security API
Transaction API
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 15/42
Example Bank account obj Transfer(Acct acc1, Acct acc2,long amt)
//1.Call middleware API t o perf orm securit y
check.
//2.Call middleware API t o start a trans
//3.Call middleware API t o load rows from db.
//4.perf orm trans. //5.Call middleware API t o st ore rows in db
//6.Call middleware API t o end the trans.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 16/42
Explicit Middleware Difficult t o Write.
Difficult t o Maintain. Difficult t o Support.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 17/42
Implicit MiddlewareClient
Skeleton
Request
Interceptor
Stub
Network
Remote Interface Remote
Interface
Transaction
Services
Security
Services
Database
drivers
Database API
Security API
Transaction API
Distributed
ObjectRemote
Interface
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 18/42
Example Bank account obj Transfer(Acct acc1,Acct acc2,long amt)
//1. Perf orm trans.(subtract bal from oneaccount and add t o other).
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 19/42
Implicit Middleware Easy t o Write.
Easy t o Maintain. Easy t o Support.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 20/42
EJB Container House enterprise bean and makes them
available t o the client t o invoke them
remotely. It intercepts the client request and delegates
them t o corresponding bean class.
It aut omatically perf orms implicit middleware
that the distributed object needs. EJB object is the physical part of the
container.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 21/42
EJB Component Ingredients Enterprise Bean Class
Interfaces Remote and Home interface f or remote
access.
Local and Local Home interface f or localaccess.
Deployment Descript or.
Vendor Specific files.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 22/42
Enterprise Bean Class It conf orms t o a well defined interface.
It contains business implementationdetails of our component.
Each bean t ype has more specificinterface that extends
javax.ejb.EnterpriseBean interface. Bean class implements the interface
corresponding t o the bean t ype.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 23/42
EJB Object Client request intercept or.
It duplicates all the business logicmethods that the corresponding beanclass exposes.
Proprietary and specific t o each EJB
container.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 24/42
Remote Interface Interface t o request intercept or.
Inf orms EJB Object aut
o generat
or
which methods t o clone.
All remote interfaces must derive from javax.ejb.EJBObject.
EJB remote interfaces must confirm t o RMI rules.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 25/42
Home Object EJB object fact ory.
Creates,finds and destroys EJB objects.
Proprietary and specific t o each EJBcontainer.
Home objects implements HomeInterface.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 26/42
Home Interface EJB Object fact ory interface.
They define methods f orcreating,destroying and finding EJBObjects.
All home interfaces must extend
javax.ejb.EJBHome.
EJB remote interfaces must confirm t o RMI rules.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 27/42
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.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 28/42
Deployment Descript or Declare how the container should
perf orm middleware services f or the
EJB component.
In EJB 2.0 deployment descript or is aXML file.
Key t o implicit middleware.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 29/42
Vendor Specific Files All vendors have proprietary value
added features.
Include files specific t o that vendor.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 30/42
Package
Remote
Interface
Local
Interface
Enterprise
Bean
Home
Interface
Deployment
Descriptor
Vendor
Specific
Jar file creator EJB jar file
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 31/42
Sample ApplicationMy First Bean!
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 32/42
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()´);
}
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 33/42
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´;
}
}
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 34/42
Remote Interface : First.java package example;
public interface First extends javax.ejb.EJBObject{
public String first() throws java.rmi.RemoteException;
}
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 35/42
Home Interface : FirstHome package example;
public interface FirstHome extends javax.ejb.EJBHome
{First create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 36/42
Deployment Descript or<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>
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 37/42
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);
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 38/42
First first=home.create();
System.out.println(first.first());
first.remove();
}
}
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 39/42
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
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 40/42
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 EJB
Object Reference
6: Invoke Business
Method
7: Delegate Request to Bean
Remote
Interface
Home
Interface
EJB Container
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 41/42
Advantages of EJB Helps t o write scalable,reliable and secure
applications.
Provides distributed component frameworkand hence supports rapid applicationdevelopment.
Supports application portablilit y and
reusabilit y across any vendors enterprisemiddleware services.
It is agreed upon by industry.
8/9/2019 EJB Basics
http://slidepdf.com/reader/full/ejb-basics 42/42
References Mastering Enterprise Java Beans
J2EE 1.4 Tut orials
Professional Java Server Programming,J2EE Edition
top related