Java Reference
In-Depth Information
9. private static final String DEFAULT_HOST = "localhost";
10. private Calendar calendar;
11. private String host;
12.
13. public CalendarHOPP(){
14. this(DEFAULT_HOST);
15. }
16. public CalendarHOPP(String host){
17. try {
18. this.host = host;
19. String url = PROTOCOL + host + REMOTE_SERVICE;
20. calendar = (Calendar)Naming.lookup(url);
21. Naming.rebind(HOPP_SERVICE, this);
22. }
23. catch (Exception exc){
24. System.err.println("Error using RMI to look up the CalendarImpl or register the
CalendarHOPP " + exc);
25. }
26. }
27.
28. public String getHost(){ return host; }
29. public ArrayList getAppointments(Date date) throws RemoteException{ return
calendar.getAppointments(date); }
30.
31. public void addAppointment(Appointment appointment, Date date) throws RemoteException
{ calendar.addAppointment(appointment, date); }
32. }
The CalendarHOPP provides a key benefit over a conventional RMI client - it can locally run what would
normally be remote methods. This can provide a substantial benefit in terms of communication overhead. The
HOPP implements the same remote interface, but it will not export itself. It keeps a reference to the stub and
forwards all the method calls to the stub that it does not (or cannot) handle. Now it can implement the methods
that it wants to execute locally—in this example, the getHost method. The HOPP can be registered with the
rmiregistry like a normal stub, but it now has the ability to execute methods locally.
 
Search WWH ::




Custom Search