Bài giảng lập trình mạng stateless session bean GV nguyễn xuân vinh

30 319 0
Bài giảng lập trình mạng  stateless session bean   GV  nguyễn xuân vinh

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

01/06/151 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN EJB: Stateless Session Bean Presenter: Nguyễn Xuân Vinh Information Technology Faculty Nong Lam University 01/06/152 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/2 of 31 Session Objectives  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 01/06/153 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/3 of 31 Review 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:  The Client  The EJB Server  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 01/06/154 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/4 of 31 Review of Session 2-(2 of 2)  The server and the container provide following services to the developer * Transaction support * Security support * Persistence support * Support for management of multiple instances .  An Enterprise Java Bean can be classified into: * Session Beans * Entity Beans * Message-Driven Beans 01/06/155 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/5 of 31 Components of an Enterprise Bean Components of an enterprise bean The bean class The EJB object The Remote interface Deployment Descriptors The Home Interface The EJB-jar file The Home object The Local Interface The LocalHome Interface 01/06/156 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/6 of 31 The Bean class Well-defined interface The Bean Bound Communicates to the client through the interface Container Works 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 confirmed 01/06/157 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/7 of 31 The 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 01/06/158 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/8 of 31 The Remote Interface Remote Interfaces derived from javax.ejb.EJBObject Business Methods Define Perform Functionality of the bean javax.ejb.EJBObject public interface java.rmi.RemoteInterface extends javax.ejb.EJBObject { public abstract javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException; } 01/06/159 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/9 of 31 Relationship between Java RMI and EJB Objects Bean Java Virtual Machine Bean Java Virtual Machine Location Transparency Remote Method Invocation Portability of Client Code EJB Object java.rmi.Remote Remote Object JVM JVM 01/06/1510 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0/Session 3/10 of 31 The Home Interface Home Interface Find EJB Objects Create EJB Objects Destroy EJB Objects EJB specifies certain methods that the home interface has to support. These methods are defined in the javax.ejb.EJBHome public interface javax.ejb.EJBHome extends java.rmi.Remote { public abstract EJBMetaData getEJBMetaData() throws java.rmi.RemoteException; } [...]... 2.0 /Session 3/15 of 31 KHOA CÔNG NGHỆ THÔNG TIN Writing a Session Bean The six methods to be followed while writing a session bean MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM setSessionContext(SessionContext ctx) ejbRemove() 16 /XX 01/06/15 ejbCreate() Business methods ejbPassivate() ejbActivate() ACCP2005/EJB 2.0 /Session 3/16 of 31 17 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: ... NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The setSessionContext (SessionContext ctx) setSessionContext() Container Session Context (Gateway) public class theBean implements SessionBean { private SessionContext ctx; public void setSessionContext(SessionContext ctx) { this.ctx=ctx; } ACCP2005/EJB 2.0 /Session 3/17 of 31 } Bean Associates 18 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG... jar file 25 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM ACCP2005/EJB 2.0 /Session 3/25 of 31 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Accessing from Client side Possible Clients Ordinary JavaBean Enterprise JavaBean Home Object JNDI lookup create() EJB Object Enterprise JavaBean Applet 26 01/06/15 Business... of Stateless Session Bean EJB Server/Container Client Invokes Bean Bean EJB Object Bean Invokes 21 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM ACCP2005/EJB 2.0 /Session 3/21 of 31 Bean KHOA CÔNG NGHỆ THÔNG TIN Deployment Descriptors  specifies how the container is supposed to create and manage the enterprise bean object  defines the name of the enterprise bean. ..  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 22 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM ACCP2005/EJB 2.0 /Session 3/22 of 31 23 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN... EJB Home are getEJBMetaData(): It is this method that gets information about the beans that are being worked on remove(): This method destroys an EJB object 11 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM ACCP2005/EJB 2.0 /Session 3/11 of 31 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN The Home Object Client... 2.0 /Session 3/14 of 31 KHOA CÔNG NGHỆ THÔNG TIN Conversational and Non Conversational Beans Client Conversation Bean  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 15 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH. .. 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 28 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM ACCP2005/EJB 2.0 /Session 3/28 of 31 KHOA... ACCP2005/EJB 2.0 /Session 3/13 of 31 EJB Server KHOA CÔNG NGHỆ THÔNG TIN Life Cycle of a Session Bean  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 14 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG... the META-INF file Welcome Welcome < /session> ACCP2005/EJB 2.0 /Session 3/23 of 31 24 /XX 01/06/15 MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN Creating the jar file Welcome.class Welcomehome.class Welcomebean.class Deployment Descriptors Welcome.jar . 01/06/151 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN EJB: Stateless Session Bean Presenter: Nguyễn Xuân Vinh Information Technology. instances .  An Enterprise Java Bean can be classified into: * Session Beans * Entity Beans * Message-Driven Beans 01/06/155 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM. deploy stateless session beans 01/06/153 /XX MÔN: LẬP TRÌNH MẠNG 2 GV: NGUYỄN XUÂN VINH TRƯỜNG ĐẠI HỌC NÔNG LÂM TP.HCM KHOA CÔNG NGHỆ THÔNG TIN ACCP2005/EJB 2.0 /Session 3/3 of 31 Review of Session

Ngày đăng: 01/06/2015, 15:17

Từ khóa liên quan

Mục lục

  • EJB: Stateless Session Bean

  • Session Objectives

  • Review of Session 2-(1of 2)

  • Review of Session 2-(2 of 2)

  • Components of an Enterprise Bean

  • The Bean class

  • The EJB Object

  • The Remote Interface

  • Relationship between Java RMI and EJB Objects

  • The Home Interface

  • The Methods in EJB Home

  • The Home Object

  • Deployment Descriptors

  • Life Cycle of a Session Bean

  • Conversational and Non Conversational Beans

  • Writing a Session Bean

  • The setSessionContext (SessionContext ctx)

  • Business Methods

  • Using JNDI to lookup Home Objects

  • Steps in accessing Home Objects

Tài liệu cùng người dùng

Tài liệu liên quan