
Bài giảng Lập trình mạng nâng cao: EJB: Stateless Session Bean - Nguyễn Xuân Vinh
lượt xem 5
download

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.
Bình luận(0) Đăng nhập để gửi bình luận!
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
- 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
- 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
- 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 threetier 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
- 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 * MessageDriven Beans 15/01/16 /XX ACCP2005/EJB 2.0/Session 3/4 of 31 4
- 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 EJBjar 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
- 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 Welldefined 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
- 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 networkaware object. This networkaware object is called the EJB /XX Object ACCP2005/EJB 2.0/Session 3/7 of 31 7
- 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
- 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
- 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
- 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
- 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
- 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
- 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 inmemory 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
- 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
- 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
- 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 }
- 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
- 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
- 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

CÓ THỂ BẠN MUỐN DOWNLOAD
-
Bài giảng Lập trình mạng nâng cao ICMP protocol - Nguyễn Vũ
29 p |
163 |
26
-
Bài giảng Lập trình C nâng cao: Chương 5 - Trần Minh Thái
22 p |
148 |
18
-
Bài giảng Lập trình mạng nâng cao: Giới thiệu - Nguyễn Xuân Vinh
8 p |
131 |
16
-
Bài giảng Lập trình C nâng cao: Chương 1 - Trần Minh Thái
25 p |
124 |
15
-
Bài giảng Lập trình mạng nâng cao - Chương 3: IP Multicasting
21 p |
98 |
11
-
Bài giảng Lập trình mạng nâng cao - Nguyễn Vũ
18 p |
106 |
10
-
Bài giảng Lập trình mạng nâng cao - Xử lý sự kiện (Event)
47 p |
123 |
10
-
Bài giảng Lập trình mạng: Chương 3 - ThS. Trần Bá Nhiệm
96 p |
101 |
9
-
Bài giảng Lập trình mạng: Bài 4 - Bùi Trọng Tùng
20 p |
79 |
7
-
Bài giảng Lập trình mạng nâng cao: J2EE architecture - Nguyễn Xuân Vinh
90 p |
64 |
5
-
Bài giảng Lập trình nâng cao - Chương 3: Mảng
48 p |
74 |
5
-
Bài giảng Lập trình nâng cao: Danh sách liên kết - Trần Quốc Long
66 p |
63 |
5
-
Bài giảng Lập trình web nâng cao: Chương 3 - Trường ĐH Văn Hiến
26 p |
32 |
5
-
Bài giảng Lập trình nâng cao: Bài 4+5+6 - Trương Xuân Nam
25 p |
36 |
4
-
Bài giảng Lập trình mạng nâng cao: Java Remote Method Invocation - Nguyễn Xuân Vinh
26 p |
67 |
4
-
Bài giảng Lập trình nâng cao: Bài 1 - Trương Xuân Nam
18 p |
31 |
3
-
Bài giảng Lập trình mạng Java: Chương 0 - ThS. Nguyễn Minh Thành
8 p |
75 |
3
-
Bài giảng Lập trình nâng cao (Advanced Programming) - Chương 5. Kiểu mảng và xâu ký tự
16 p |
6 |
2


Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn
