Documente Academic
Documente Profesional
Documente Cultură
Swapnil Shrivastava
Contents
EJB Fundamentals
(c)CDAC(Formerly NCST)
Suns Definition
EJB architecture is a component architecture for the development and deployment of component based distributed business applications. Applications written using EJB architecture are scalable, transactional, and multi-user secure. These applications may be write once, and then deployed on any server platform that supports the EJB specification.
EJB Fundamentals (c)CDAC(Formerly NCST) 3
Short Definition
EJB is a server-side component architecture that simplifies the process of building enterprise-class distributed component applications in Java. EJB provides standard for component architecture.
EJB Fundamentals
(c)CDAC(Formerly NCST)
Enterprise Bean
Server side software components that can be deployed in distributed multi tier environment. They encapsulate business logic of an application. Consists of one or more java objects.
EJB Fundamentals
(c)CDAC(Formerly NCST)
Types of Beans
EJB Fundamentals
(c)CDAC(Formerly NCST)
Session Bean
Session beans model business processes. They are like verbs because they are actions. E.g. billing engine, catalog engine etc:
EJB Fundamentals
(c)CDAC(Formerly NCST)
Entity Bean
Entity Bean Models business data. They are like nouns because they are data objects E.g. product, an order, an employee etc: Session beans typically calls entity beans to perform business goals.
(c)CDAC(Formerly NCST) 8
EJB Fundamentals
Message driven beans are similar to session beans. They are actions. They are called only when they receive some message. E.g. : stock trade message.
EJB Fundamentals
(c)CDAC(Formerly NCST)
EJB Architecture
Presentation Tier
Messaging Client
Messaging
HTML Client
Firewall
HTTP
C/C++ Client
CORBA-IIOP
Servlet
JSP
Web Server
Business Tier
10
Distributed Object
Remote Interface
Skeleton
We take a monolithic application and break it into distributed system with multiple clients connecting to multiple servers and databases over network.
Services
Remote Method Invocation Load Balancing Transparent Fail Over Back end integration. Clustering Dynamic Re deployment
Middleware
EJB Fundamentals
Object life cycle Caching Security Resource Pooling System Management Message Oriented Middleware And many more..
13
(c)CDAC(Formerly NCST)
Explicit Middleware
Transaction API Transaction
Services
Client
Remote Interface
Distributed Object
Remote Interface
Security API
Security Services
Database API
Database drivers
Stub Network
EJB Fundamentals
Skeleton
(c)CDAC(Formerly NCST)
14
Explicit Middleware
EJB Fundamentals
(c)CDAC(Formerly NCST)
16
Client
Services
Security API
Request Interceptor
Remote Interface Remote Interface
Security Services
Database API
Stub
Network
EJB Fundamentals
Skeleton
Database drivers
(c)CDAC(Formerly NCST)
17
EJB Fundamentals
(c)CDAC(Formerly NCST)
18
Implicit Middleware
EJB Fundamentals
(c)CDAC(Formerly NCST)
19
EJB Container
House enterprise bean and makes them available to the client to invoke them remotely. It intercepts the client request and delegates them to corresponding bean class. It automatically performs implicit middleware that the distributed object needs. EJB object is the physical part of the container.
(c)CDAC(Formerly NCST) 20
EJB Fundamentals
Remote and Home interface for remote access. Local and Local Home interface for local access.
EJB Fundamentals
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.
(c)CDAC(Formerly NCST) 22
EJB Fundamentals
EJB Object
Client request interceptor. It duplicates all the business logic methods that the corresponding bean class exposes. Proprietary and specific to each EJB container.
EJB Fundamentals
(c)CDAC(Formerly NCST)
23
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 to RMI rules.
(c)CDAC(Formerly NCST) 24
EJB Fundamentals
Home Object
EJB object factory. Creates,finds and destroys EJB objects. Proprietary and specific to each EJB container. Home objects implements Home Interface.
EJB Fundamentals
(c)CDAC(Formerly NCST)
25
Home Interface
EJB Object factory interface. They define methods for creating,destroying and finding EJB Objects. All home interfaces must extend javax.ejb.EJBHome. EJB remote interfaces must confirm to RMI rules.
EJB Fundamentals (c)CDAC(Formerly NCST) 26
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 Home interface.
EJB Fundamentals
(c)CDAC(Formerly NCST)
27
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.
EJB Fundamentals
(c)CDAC(Formerly NCST)
28
All vendors have proprietary value added features. Include files specific to that vendor.
EJB Fundamentals
(c)CDAC(Formerly NCST)
29
Package
Remote Interface Local Interface
(c)CDAC(Formerly NCST)
30
EJB Fundamentals
(c)CDAC(Formerly NCST)
31
EJB Fundamentals
32
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; }
}
EJB Fundamentals (c)CDAC(Formerly NCST) 33
EJB Fundamentals
(c)CDAC(Formerly NCST)
34
EJB Fundamentals
(c)CDAC(Formerly NCST)
35
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>
EJB Fundamentals (c)CDAC(Formerly NCST) 36
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);
EJB Fundamentals (c)CDAC(Formerly NCST)
37
EJB Fundamentals
(c)CDAC(Formerly NCST)
38
<<interface>> javax.ejb.SessionBean
Written by developer
EJB Object EJB Fundamentals Home Object (c)CDAC(Formerly NCST) Generated by Componet Vendor Tool 39
EJB Container
3: Create a new Home EJB Object Interface
Client
Home Object
4: Create a new EJB Object
EJB Object
Enterprise Bean
Advantages of EJB
Helps to write scalable,reliable and secure applications. Provides distributed component framework and hence supports rapid application development. Supports application portablility and reusability across any vendors enterprise middleware services. It is agreed upon by industry.
(c)CDAC(Formerly NCST) 41
EJB Fundamentals
References
Mastering Enterprise Java Beans J2EE 1.4 Tutorials Professional Java Server Programming, J2EE Edition
EJB Fundamentals
(c)CDAC(Formerly NCST)
42