intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Lập trình mạng nâng cao: EJB: Stateful Session Bean - Nguyễn Xuân Vinh

Chia sẻ: Ngocnga Ngocnga | Ngày: | Loại File: PPT | Số trang:23

48
lượt xem
4
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Learning objectives of this chapter include: 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.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình mạng nâng cao: EJB: Stateful Session Bean - Nguyễn Xuân Vinh

  1. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM GV: NGUYỄN XUÂN VINH MÔN: LẬP TRÌNH MẠNG 2 KHOA CÔNG NGHỆ THÔNG TIN EJB: Stateful Session Bean 15/01/16 Presenter: Nguyễn Xuân Vinh Information Technology Faculty /XX Nong Lam University 1
  2. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Session Objectives GV: NGUYỄN XUÂN VINH  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. MÔN: LẬP TRÌNH MẠNG 2 15/01/16 /XX 2
  3. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Review of Session 3 (1 of 3) GV: NGUYỄN XUÂN VINH  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 MÔN: LẬP TRÌNH MẠNG 2 * 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 15/01/16 /XX 3
  4. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Review of Session 3 (2 of 3) GV: NGUYỄN XUÂN VINH  The deployment descriptor: A file that tells the EJB server about  the classes, the home interface, and the remote interface that  MÔN: LẬP TRÌNH MẠNG 2 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.  Three classes are essential for deployment:    Home Interface  15/01/16  Remote Interface   Bean class /XX 4
  5. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Review of Session 3 (3 of 3) GV: NGUYỄN XUÂN VINH  The ejb­jar.xml file is a compressed file that contains  the declarations of the enterprise bean class, the  MÔN: LẬP TRÌNH MẠNG 2 remote interface and the home interface.  An EJB client can be: * An ordinary JavaBean * Another EJB * A JSP Page * A servlet * An applet 15/01/16 *A stand­alone application /XX 5
  6. Characteristics of Stateful Session         TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN     Beans GV: NGUYỄN XUÂN VINH  Conversional state occurs when a client calls a method on a bean.  Pooling has to be done to conserve resources and enhances scalability.  The container swaps out a bean and saves the conversational state to  the hard disk or other storage devices. This process is called  passivation. MÔN: LẬP TRÌNH MẠNG 2  When the client requests for a method, the passivated conversational  state is returned to the bean. The bean is again ready to meet the  request. This process is called activation.    To passivate a bean a container uses Least Recently Used method.  To activate a bean a container uses Just­in­Time (JIT) method. 15/01/16 /XX 6
  7. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Rules for Conversational State GV: NGUYỄN XUÂN VINH Written to storage Converted to in case of passivation MÔN: LẬP TRÌNH MẠNG 2 Conversational Bit - blob Storage state of a bean Converted into  Read from storage data from bit-blob into memory in case of activation Memory freed 15/01/16 /XX 7
  8. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Passivation of a Stateful Bean GV: NGUYỄN XUÂN VINH Client MÔN: LẬP TRÌNH MẠNG 2 The EJB Container/Server 1. Invoke business methods           2. Take the least recently used bean               3. Call ejbPassivate()  EJB Enterprise Object 4. Serialize the bean state bean 5. Store passivated bean state Other 15/01/16 Enterprise beans Storage /XX 8
  9. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Activation of a Stateful Bean GV: NGUYỄN XUÂN VINH EJB Container/Server Client MÔN: LẬP TRÌNH MẠNG 2 3. Reconstruct bean EJB 4. Call ejbActivate() Enterprise Object 5. Invoke business  Beans 1. Invoke business methods      method 2. Retrieve the passivated state of Other Enterprise bean Beans 15/01/16 Storage /XX 9
  10. Requirements for Stateful session  TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN beans. GV: NGUYỄN XUÂN VINH  Remote Interface  The Bean Class MÔN: LẬP TRÌNH MẠNG 2  The Home Interface  The Client Code  Deployment Descriptor 15/01/16 /XX 10
  11. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The Remote Interface GV: NGUYỄN XUÂN VINH Remote Interface Stateful Session Bean Class MÔN: LẬP TRÌNH MẠNG 2 (Defines business methods of bean) Number extends EJBObject 1. number() Client 1. number() { / Implementation 15/01/16 } /XX 11
  12. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The Bean Class GV: NGUYỄN XUÂN VINH Stateful Session Bean Class public class Numberbean implements SessionBean MÔN: LẬP TRÌNH MẠNG 2 private SessionContext ctx; public int answer;    public int number(){ /* Actual Implementation*/ } public void ejbCreate(int answer) throws CreateException public void ejbRemove() public void ejbActivate() public void ejbPassivate() 15/01/16 public void setSessionContext(SessionContext ctx) /XX 12
  13. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The Home Interface GV: NGUYỄN XUÂN VINH import javax.ejb.*; MÔN: LẬP TRÌNH MẠNG 2 import java.rmi.*; public interface Numberhome extends EJBHome { Number create( int answer ) throws RemoteException, CreateException ; 15/01/16 } /XX 13
  14. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Goals of the Client Code GV: NGUYỄN XUÂN VINH  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  MÔN: LẬP TRÌNH MẠNG 2 from the client code  Deployment descriptors limit the pool size.   Lastly, the EJB objects are removed. 15/01/16 /XX 14
  15. The Deployment Descriptor : TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ejb­jar.xml GV: NGUYỄN XUÂN VINH ejb-jar.xml file contains the declarations of  Enterprise bean  Home interface MÔN: LẬP TRÌNH MẠNG 2  Remote interface  Bean class  Session Type  Transaction type 15/01/16 /XX 15
  16. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN jboss.xml GV: NGUYỄN XUÂN VINH  It contains the declaration of the actual ejb name and the  JNDI name of the Session bean.   Client code maps the actual ejb name from this JNDI name.  MÔN: LẬP TRÌNH MẠNG 2 Number Number 15/01/16 /XX 16
  17. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Creating the jar file GV: NGUYỄN XUÂN VINH  The jar file is created using java appropriate statement  Packages  the  remote  interface,  the  bean  class,  the  MÔN: LẬP TRÌNH MẠNG 2 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  15/01/16 bean.  /XX 17
  18. Advantages  and Disadvantages of  TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Stateless Session bean GV: NGUYỄN XUÂN VINH  Advantages  Pooling  is  simple  in  stateless  session  bean  as  there  is  reuse  of  beans and this reduces overload MÔN: LẬP TRÌNH MẠNG 2  Loss of conversations is comparatively less in a stateless session  bean   Disadvantages  Client­specific  data  needs  to  be  given  for  every  method  invocation  Bandwidth  could be reduced for other processes, as data has to  15/01/16 be passed each time  Input/Output bottlenecks are more in stateless session beans /XX 18
  19. Advantages and Disadvantages of  TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Stateful Session Beans GV: NGUYỄN XUÂN VINH  Advantages  Data is not pushed to the bean for every method invocation MÔN: LẬP TRÌNH MẠNG 2  All resources are stored in a database when the bean is passive  Disadvantages  Conversation  with  the  client  maybe  lost  as    there  is  caching  of  client conversation each time a bean is used.  Bean state has to be activated and passivated in between  method  invocations. Therefore there can be I/O bottlenecks. 15/01/16 /XX 19
  20. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM GV: NGUYỄN XUÂN VINH KHOA CÔNG NGHỆ THÔNG TIN Practices used for writing Stateful Session Beans  Always try to keep the conversations short.  Try to use an EJB product that persists stateful  conversations. MÔN: LẬP TRÌNH MẠNG 2  Always write client code that takes into account  bean failures. 15/01/16 /XX 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD


ERROR:connection to 10.20.1.100:9315 failed (errno=111, msg=Connection refused)
ERROR:connection to 10.20.1.100:9315 failed (errno=111, msg=Connection refused)

 

Đồng bộ tài khoản
2=>2