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: Stateless Session Bean - Nguyễn Xuân Vinh

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

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

This chapter identify the constituents of an Enterprise JavaBean; define a bean class, EJB object, home interface, home object and deployment descriptors; define a stateless session bean; write programs related to stateless session beans; compile and deploy stateless session beans.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình mạng nâng cao: EJB: Stateless 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: Stateless 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  Identify the constituents of an Enterprise  JavaBean. MÔN: LẬP TRÌNH MẠNG 2  Define a bean class, EJB object, home interface,  home object and deployment descriptors.  Define a stateless session bean  Write programs related to stateless session beans  Compile and deploy stateless session beans 15/01/16 /XX ACCP2005/EJB 2.0/Session 3/2 of 31 2
  3. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Review of Session 2-(1of 2) GV: NGUYỄN XUÂN VINH 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:   The Client  The EJB Server MÔN: LẬP TRÌNH MẠNG 2  The Database  The EJB Container resides inside the EJB server. The container acts as a buffer  between the bean and the outside world.  The responsibility of the EJB Server and Container 15/01/16 /XX ACCP2005/EJB 2.0/Session 3/3 of 31 3
  4. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Review of Session 2-(2 of 2) GV: NGUYỄN XUÂN VINH  The server and the container provide following services to the  developer         * Transaction support              *  Security support                             * Persistence support    MÔN: LẬP TRÌNH MẠNG 2        * Support for management of multiple instances .  An Enterprise Java Bean can be classified into:      * Session Beans         * Entity Beans         * Message­Driven Beans 15/01/16 /XX ACCP2005/EJB 2.0/Session 3/4 of 31 4
  5. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Components of an Enterprise Bean GV: NGUYỄN XUÂN VINH Components of an  enterprise bean   MÔN: LẬP TRÌNH MẠNG 2 The LocalHome  Interface The Local Interface The bean class The EJB­jar file The EJB object Deployment Descriptors 15/01/16 The Remote  The Home object interface /XX The Home  ACCP2005/EJB 2.0/Session 3/5 of 31 5 Interface
  6. 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  Communicates to the   client through the   interface The Bean Bound Well­defined interface MÔN: LẬP TRÌNH MẠNG 2 Works in any  container with the  help of these interfaces Container public interface javax. ejb. EnterpriseBean extends       java.io.Serializable { } 15/01/16 Once the above interface is  implemented, the bean class is  confirmed  /XX ACCP2005/EJB 2.0/Session 3/6 of 31 6
  7. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The EJB Object GV: NGUYỄN XUÂN VINH EJB Container/Server MÔN: LẬP TRÌNH MẠNG 2                                                                  Client                                              4.Returns method    Home  Code    to client Object                          EJB  3. Returns the Method 1 .Calls a method Object Enterprise               2. Delegates   The container is the middleman between the     Bean                                                                                 method  client and the bean. It manifests itself  as a single        Instance                  to bean 15/01/16 network­aware object.  This network­aware object is called the EJB  /XX Object ACCP2005/EJB 2.0/Session 3/7 of 31 7
  8. 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 javax.ejb.EJBObject Business  MÔN: LẬP TRÌNH MẠNG 2 Define Remote Interfaces  Methods derived from javax.ejb.EJBObject  Perform public interface java.rmi.RemoteInterface extends javax.ejb.EJBObject {  Functionality of  15/01/16 public abstract javax.ejb.EJBHome getEJBHome() throws the bean java.rmi.RemoteException; /XX } ACCP2005/EJB 2.0/Session 3/8 of 31 8
  9. Relationship between Java RMI TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN and EJB Objects GV: NGUYỄN XUÂN VINH Remote Method Invocation JVM Java Virtual Machine Java Virtual Machine MÔN: LẬP TRÌNH MẠNG 2 EJB Object java.rmi.Remote Remote  Object Bean Bean JVM 15/01/16 Location Transparency /XX Portability of Client Code ACCP2005/EJB 2.0/Session 3/9 of 31 9
  10. 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 Home EJB  specifies  certain   Interface   methods  that  the  home  MÔN: LẬP TRÌNH MẠNG 2 interface  has  to  support.  Destroy EJB These methods are defined  Find EJB  Objects in the javax.ejb.EJBHome Objects Create EJB  Objects public interface javax.ejb.EJBHome extends  java.rmi.Remote  { 15/01/16   public abstract EJBMetaData  getEJBMetaData() throws java.rmi.RemoteException; } /XX ACCP2005/EJB 2.0/Session 3/10 of 31 10
  11. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The Methods in EJB Home GV: NGUYỄN XUÂN VINH The methods that fall under the  MÔN: LẬP TRÌNH MẠNG 2 EJB Home are getEJBMetaData():  It is this method remove(): This method destroys an  15/01/16  that gets information about the  EJB object beans that are being worked on /XX ACCP2005/EJB 2.0/Session 3/11 of 31 11
  12. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The Home Object GV: NGUYỄN XUÂN VINH Client  3. Returns the objects MÔN: LẬP TRÌNH MẠNG 2 Code EJB Container/Server 1. Requests new EJB  Object Home  Object    Enterprise  2. Creates new object Beans 15/01/16 EJB  Object /XX ACCP2005/EJB 2.0/Session 3/12 of 31 12
  13. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Deployment Descriptors GV: NGUYỄN XUÂN VINH Classes that form the bean MÔN: LẬP TRÌNH MẠNG 2 Deployment  Home Interface EJB Server Descriptors Life cycle requirements  Remote Interface and Bean management Persistence Requirements Transaction Requirements  Security Management 15/01/16 /XX ACCP2005/EJB 2.0/Session 3/13 of 31 13
  14. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Life Cycle of a Session Bean GV: NGUYỄN XUÂN VINH  A session bean may last as long as the client session.   Will not survive if the application server changes or crashes.  MÔN: LẬP TRÌNH MẠNG 2  They are objects which are present in­memory which die along  with  the  surrounding  environment  and  are  not  persisted  in  a  database. 15/01/16 /XX ACCP2005/EJB 2.0/Session 3/14 of 31 14
  15. Conversational and Non Conversational 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 Conversation Bean MÔN: LẬP TRÌNH MẠNG 2 Client  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. 15/01/16  Stateful  session  beans  can  retain  their  conversational  state. /XX ACCP2005/EJB 2.0/Session 3/15 of 31 15
  16. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Writing a Session Bean GV: NGUYỄN XUÂN VINH The six methods to be followed while  writing a session bean  MÔN: LẬP TRÌNH MẠNG 2 setSessionContext(SessionContext ctx) Business methods ejbCreate() ejbRemove() 15/01/16 ejbPassivate() ejbActivate() /XX ACCP2005/EJB 2.0/Session 3/16 of 31 16
  17. The setSessionContext (SessionContext TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ctx) GV: NGUYỄN XUÂN VINH setSessionContext() Bean Container Associates MÔN: LẬP TRÌNH MẠNG 2 Session Context (Gateway) public class theBean implements SessionBean { private SessionContext ctx; public void setSessionContext(SessionContext ctx) 15/01/16 { this.ctx=ctx; } /XX . . . . . . .  ACCP2005/EJB 2.0/Session 3/17 of 31 17 }
  18. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Business Methods GV: NGUYỄN XUÂN VINH  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. MÔN: LẬP TRÌNH MẠNG 2 import javax.ejb.*; public class sess implements Sessionbean{ public int multiply(int a, int b){ return (a*b);  }      ejbPassivate()          ejbCreate() 15/01/16          ejbActivate()          ejbRemove()  . . . . . . .  /XX    } ACCP2005/EJB 2.0/Session 3/18 of 31 18
  19. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Using JNDI to lookup Home Objects GV: NGUYỄN XUÂN VINH EJB Container/Server 3. Creates an EJB Object Client Home  MÔN: LẬP TRÌNH MẠNG 2 Object 5. Return Object reference 1. Retrieve  4. Create  EJB Object    Home     Object 6. Invokes business methods EJB      Enterprise  JNDI Object beans 7. Delegates request to bean 2. Returns reference      to the home object 15/01/16 Naming /XX  Service ACCP2005/EJB 2.0/Session 3/19 of 31 19
  20. TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Steps in accessing Home Objects GV: NGUYỄN XUÂN VINH The steps followed by the client code  to get a reference MÔN: LẬP TRÌNH MẠNG 2 The setting up of the Environment The Initial Context Retrieving the home objects Creating an Object 15/01/16 Calling a Method Destroying the EJB Object /XX ACCP2005/EJB 2.0/Session 3/20 of 31 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

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