Documente Academic
Documente Profesional
Documente Cultură
By
Janaranjani K
Outline
Introduction of EJBs.
EJB as a Business Tier Component.
EJB fundamentals.
Enterprise Beans.
Foundation of EJB.
Session beans.
Components of a Session beans.
loaded
Security
Networking
Persistant Management
Concurrency
Location transparency
Load Balancing etc.
EJB as a Business Tier
Component
Enterprise beans are intended for server side component
development not for client side (which lies in presentation tier
and components like thick clients, web service clients etc are
used for its development). So it lies in Business Tier.
Types of Beans:
Session beans.
Stateful session beans.
Entity beans.
Accessing database
own copy)
Destroy/re-instantiate on the fly
table
Persistence code can be written manually (bean-managed
persistence, BMP) or automatically (container-managed
persistence, CMP)
A single bean instance (on the server) can be accessed by
multiple clients
Unlike stateful session beans.
Message Driven Beans
New in EJB 2.0 standard
Built on top of JMS to send messages to clients, which in
turn would be received by MDB.
It is invoked by the container upon arrival of message at
the destination that is serviced by the message-driven
bean.
Have no client visibility,
Foundation of EJB
Distributed Architecture
EJB components are based on Distributed Objects
A distributed object is an object that is callable from a remote
system.
The client can be in-process, out-of-process or a client located
elsewhere on the network.
It does the invocation with the help of the followings:
Stubs (client side proxy object):
Component Interface:
Remote Interface:
Used when you are calling the bean that presents in the
same process.
Unlike remote interface, it will not undergo stubs, skeleton,
marshaling/demarshaling of parameters.
EJB object:
It is container generated implementations of the remote
interface.
All client invoications go through this.It delegates the call to
Home object:
Container generated implementation of home interface.
EJB-jar file:
A complete zip of the above said files.
Application server unpacks the jar file and loads the bean into the
container.
Session Beans
Components of a Session
Beans
To define session bean X, you must create three classes:
The remote (local) component interface, called X (or XLocal)
home interface
In the home interface, the ‘ejb’ prefix is not used
...
Activation and Passivation
During the bean’s lifecycle, the container may decide to
passivate it
Normally done to free up memory and other resources
Bean is notified immediately before passivation by lifecycle
method ejbPassivate()
In this method, the bean should:
Release any resources it might be holding
Sockets, Open files, database connections, etc.
Nullify fields that should not be serialized (cache, etc.)
If the bean is referenced by client while passivated, the container
activates it.
Bean is notified by ejbActivate() immediately after de-
serialization
Its chance to restore all field values, resources, etc.
The Lifecycle of Stateless
Session
EJBs
Session EJBs have no state, so activation and passivation are
meaningless
The container simply destroys instances when low on memory,
import javax.ejb.SessionBean;
import javax.ejb.CreateException;
import javax.ejb.SessionContext;
return returnValue;
}
}
Home Interface
package examples.webservices.basic.localHome_Object;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
}
Local Home Interface
package examples.webservices.basic.localHome_Object;
import javax.ejb.EJBLocalHome;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalObject;