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.. EJB contain
Trang 1EJB: Stateful Session Bean
Presenter: Nguyễn Xuân VinhInformation Technology Faculty
Trang 2 Define a Stateful Session Bean
List the characteristics of a Stateful Session Bean
Write Stateful session bean programs
Differentiate between Stateless and Stateful Session beans
Trang 3 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.
Bean class contains the implementation of the business logic methods
EJB container performs important management functions when it intercepts
client requests such as:
* Transaction logic
* Security logic
* Bean instance logic
The Remote interface duplicates the methods exposed by the bean class
Responsibilities of the EJB home object:
* Creating EJB objects
* Searching for existing EJB Objects
* Removing EJB Objects
Trang 4the 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.
Home Interface
Remote Interface
Bean class
Trang 5 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
An EJB client can be:
Trang 6the hard disk or other storage devices This process is called
passivation.
state is returned to the bean The bean is again ready to meet the
request This process is called activation
Trang 7data from bit-blob
Trang 8TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN
Passivation of a Stateful Bean
Client
EJB Object Enterprise
bean
Other Enterprise beans
Storage
1 Invoke business methods
5 Store passivated bean state
The EJB Container/Server
2 Take the least recently used bean
3 Call ejbPassivate()
4 Serialize the bean state
Trang 9EJB Object
Other Enterprise Beans
1 Invoke business methods
2 Retrieve the passivated state of bean
Trang 10 The Bean Class
The Home Interface
The Client Code
Deployment Descriptor
Trang 111 number(){
/ Implementation}
Remote Interface (Defines business methods of bean)
1 number()
Number extends EJBObject
Client
Trang 12TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN
The Bean Class
Stateful Session Bean Class
public class Numberbean implements SessionBean
private SessionContext ctx;
public int answer;
public void ejbCreate(int answer) throws CreateException public void ejbRemove()
public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext ctx)
Trang 14TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN
Goals of the Client Code
It acquires a JNDI initial context and the naming context
Home object is located using JNDI
Client calls methods on the bean using the Home Object
Conversations are created using home interface and used
from the client code
Deployment descriptors limit the pool size
Lastly, the EJB objects are removed
Trang 17 The jar file is created using java appropriate statement
Packages the remote interface, the bean class, the home interface and the XML files
The jar file is copied into the deploy directory on the server and then deployed
The creation and copying of the file in the deploy directory of the server marks the completion of the bean
Trang 18TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCMAdvantages and Disadvantages KHOA CÔNG NGHỆ THÔNG TIN
of Stateless Session bean
Bandwidth could be reduced for other processes, as data has to
be passed each time
Input/Output bottlenecks are more in stateless session beans
Trang 19 Data is not pushed to the bean for every method invocation
All resources are stored in a database when the bean is passive
Trang 20TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN
Practices used for writing Stateful Session Beans
conversations.
bean failures.
Trang 21database or file is known as passivation.
with all its resources is known as activation.
ago is called the Least Recently Used method.
serialization.
is going to passivate the bean
conversational state is read back into the memory The container then re-constructs the memory-state using object serialization.
Trang 22 A jar file is created in order to package the three files,
namely, the remote interface, the bean class, and the home interface
To deploy the bean, the newly created jar file has to be
copied into the deploy directory on the server
If the business process requires multiple invocations, a
stateful session bean has to be used However, if the
business process is only for a single method call, the
stateless session bean will suffice