글쓴이 :이원영 1998년 11월 06일 14:58:36
In Reply to: [질문] RMI의 exportRemoteObject posted by 강신동 on 1998년 11월 05일 11:59:14:
UnicastRemoteObject.exportObject(Remote)
Method는 Remote Interface를 Implements한 객체을
UnicastRemoteObject로 만들어 주는 기능을 합니다.
RMI Server Implementation를 할 때
public class HelloImpl extends UnicastRemoteObject implements Hello
{
..
}
하잖아요, 즉 HelloImpl은 UnicastRemoteObject를 상속받아사용하는데,
Applet이나 Frame등과 같은 object를 RMI Remote Object로
사용할 수 있도록 만들어 줄 때 위의 method를 사용합니다.
예)
[Node.java]
import java.rmi.*;
public interface Node extends java.rmi.Remote {
void client_method( String message ) throws java.rmi.RemoteException;
}
[NodeApplet.java]
....
public class NodeApplet extends Applet implements Node
{
....
public void init(){
....
UnicastRemoteObject.exportObject(this);
...
NodeServer server = (NodeServer)Naming.lookup(..);
server.registry(this); <=== 즉 Node Interface를 구현한Applet Reference를 인자로 넘김
..
}
public void client_method(String message) throws RemoteException{
.....
}
}
그러면 NodeServer는 그 Reference를 이용해
node1.client_method("hey...");라고 필요할 때 마다 Applet의
method를 부를 수 있게 되죠.
====================================
그러나, 그러나.. But,
이것은 netscape에서는 아직 안됩니다.
DNS에 등록되어 있지 않은 머신에서는 RMI가
Registry에 등록할 때 머신 명으로 등록하게 되고
IP Address로 하지 않잖습니까?
RMI Server 측 같은 경우는
InetAddress address = InetAddress.getLocalHost();
String thisHost = address.getHostAddress();
Properties currentProperties = System.getProperties();
currentProperties.put("java.rmi.server.hostname", thisHost);
System.setProperties(currentProperties);
와 같은 방식으로 Registry에 등록할 때 IP Address를
사용하라고 명시적으로 설정할 수 있지만
불행하게도(아시다시피) System.setProperties()는
Applet의 Security에 걸립니다. Applet이 웹브라우져의
JVM이 properties를 변경할 수 없다는 거죠..
결국, HotJava나, Appletviewer에서만 가능합니다.