tailieunhanh - VẤN ĐỀ THAM TRỊ VÀ THAM BIẾN TRONG KỸ THUẬT LẬP TRÌNH PHÂN TÁN ĐỐI

Kế thừa từ lớp Remote: đối tượng được tham khảo theo tham biến (GET OBJECT BY REFERENCE) Ví dụ: RemoteClass: (interface & implement): đối tượng được gọi từ xa import .*; public interface MyRemoteClass extends Remote{ public int getMyAttribute() throws RemoteException; public void setMyAttribute(int value) throws RemoteException; } | VẤN ĐỀ THAM TRỊ VÀ THAM BIẾNTRONG KỸ THUẬT LẬP TRÌNH PHÂN TÁN ĐỐI TƯỢNG Kế thừa từ lớp Remote đối tượng được tham khảo theo tham biến GET OBJECT BY REFERENCE Ví dụ RemoteClass interface implement đối tượng được gọi từ xa import . public interface MyRemoteClass extends Remote public int getMyAttributeO throws RemoteException public void setMyAttribute int value throws RemoteException __ import . public class MyRemoteClassImpl implements MyRemoteClass private int myAttribute 0 public int getMyAttribute throws RemoteException return myAttribute public void setMyAttribute int value throws RemoteException myAttribute value ServerClass đăng ký đối tượng RemoteClass import . import . public class MyRemoteClassServer public static void main String args try MyRemoteClassImpl c new MyRemoteClassImplO Exporting MyRemoteClass. c rmi localhost MyRemoteClass c Register MyRemoteClass while true Value of c catch Exception e e Clientclass sử dụng đối tượng RemoteClass import . public class MyRemoteClassClient public static void main String args try DEMO GET OBJECT BY REFERENCE MyRemoteClass c MyRemoteClass rmi localhost MyRemoteClass 12 Value of c MyRemoteClass c1 MyRemoteClass rmi localhost MyRemoteClass Value of c1 .