Components of an Enterprise BeanComponents of an enterprise bean The bean class The EJB object The Remote interface Deployment Descriptors The Home The EJB-jar file The Home object The
Trang 1EJB: Stateless Session Bean
Presenter: Nguyễn Xuân Vinh Information Technology Faculty
Trang 2home object and deployment descriptors.
Trang 3Review of Session 2-(1of 2)
In session 2 we discussed
Four stages are followed while developing business solutions
Six parties are involved while deploying Enterprise JavaBeans
Logical three-tier architecture of EJB:
Trang 4* Support for management of multiple instances
An Enterprise Java Bean can be classified into:
* Session Beans
* Entity Beans
* Message-Driven Beans
Trang 5Components of an Enterprise Bean
Components of an enterprise bean
The bean class
The EJB object
The Remote interface
Deployment Descriptors
The Home
The EJB-jar file
The Home object
The Local Interface The LocalHome
Interface
Trang 6Works in any container with the help of these interfaces
public interface javax ejb EnterpriseBean extends
java.io.Serializable {
}
Once the above interface is implemented, the bean class is
Trang 7The EJB Object
Client Code
EJB Container/Server
1 Calls a method
4.Returns method
to client Home
Object
EJB Object
3 Returns the Method
Enterprise Bean
Instance
2 Delegates
method
to bean
The container is the middleman between the
client and the bean It manifests itself as a
single network-aware object
This network-aware object is called the
EJB Object
Trang 8Business Methods
Define
Perform
Functionality of the bean
Trang 9Location Transparency Remote Method Invocation
Portability of Client Code
EJB Object java.rmi.Remote Remote
Object
JVM JVM
Trang 10Find EJB
Objects
Destroy EJB Objects
EJB specifies certain
methods that the home
interface has to support
These methods are defined
Trang 11The Methods in EJB Home
getEJBMetaData(): It is this method
that gets information about the
beans that are being worked on
remove(): This method destroys an
EJB object
The methods that fall under the EJB Home are
Trang 12EJB Object
Enterprise Beans
EJB Container/Server
1 Requests new EJB Object
3 Returns the objects
2 Creates new object
Trang 13Life cycle requirements
and Bean management
Trang 14 A session bean may last as long as the client session
Will not survive if the application server changes or crashes
They are objects which are present in-memory which die along with the surrounding environment and are not persisted in a database.
Trang 15Conversational and Non Conversational Beans
A conversation stretches across a business process with respect to the client.
A stateless session bean conducts a conversation that spreads over a single method call.
Stateful session beans can retain their conversational state.
Trang 16The six methods to be followed while writing a session bean
Trang 17The setSessionContext (SessionContext ctx)
Session Context (Gateway)
Associates
Trang 18public class sess implements Sessionbean{
public int multiply(int a, int b){
return (a*b);
} ejbPassivate()
ejbCreate()
ejbActivate()
ejbRemove()
Business methods are written to solve business logic problems
Business methods are contained in the remote interface of
the bean for the client to access them
Trang 19Using JNDI to lookup Home Objects
Home Object
Enterprise beans
EJB Object
3 Creates an EJB Object
5 Return Object reference
6 Invokes business methods
EJB Container/Server
4 Create EJB Object
2 Returns reference
to the home object
7 Delegates request to bean
Trang 20The steps followed by the client code
to get a reference
The setting up of the Environment
Destroying the EJB Object Calling a Method
Creating an Object Retrieving the home objects
The Initial Context
Trang 21Pooling of Stateless Session Bean
Client
EJB Object
Invokes
EJB Server/Container
Bean
BeanBean
Bean
Invokes
Trang 22 ejb-jar file provides naming information about enterprise bean,
remote interface and home interface
ejb.jar has to be present in the directory called META-INF
Trang 23 This file also has to be put into the META-INF file
Trang 24A jar file is created to package the three java files, namely the
bean class, the home interface and the remote interface The XML files Namely ejb-jar.xml and jboss.xml are also present in the
Trang 25Deploying the bean
the newly created jar file has to be copied into
the deploy directory on the server
Trang 26Home Object
EJB Object
JNDI lookup
create()
Business Methods
Trang 27 The bean class, the EJB object, the remote interface, the home interface, the home
object, the deployment descriptors, and the jar files constitute the enterprise bean
The bean class contains the implementation of the business logic methods
The EJB container performs certain important management functions when it intercepts client requests These management functions are:
* Transaction logic
* Security logic
* Bean instance logic
The Remote interface duplicates the methods exposed by the bean class
Trang 28 Responsibilities of the EJB home object:
* Creating EJB objects
* Searching for existing EJB Objects
* Removing EJB Objects
The deployment descriptor: A file that tells the EJB server about the classes, the home interface, and the remote interface that form the bean
The lifetime of a session bean may last till such time as that of a client session It could
be as long as a window is open or as long as an application is open Session beans do
not, therefore, survive application server crashes or machine crashes.
Trang 29 The ejb-jar.xml file is a compressed file that contains the declarations of the
enterprise bean class, the remote interface and the home interface.
It is important to have a client because EJB will not function without the client This client can be: