Java Reference
In-Depth Information
10. private int pollingInterval = DEFAULT_POLLING_INTERVAL;
11.
12. public ClientPullRequester(PullClient newParent, ClientPullServer newUpdateServer,
13. String newTaskID){
14. parent = newParent;
15. taskID = newTaskID;
16. updateServer = newUpdateServer;
17. processingThread = new Thread(this);
18. processingThread.start();
19. }
20.
21. public void run(){
22. while (!isShutdown()){
23. try{
24. currentTask = updateServer.getTask(taskID, currentTask.getLastEditDate());
25. parent.setUpdatedTask(currentTask);
26. }
27. catch (RemoteException exc){ }
28. catch (UpdateException exc){
29. System.out.println(" " + parent + ": " + exc.getMessage());
30. }
31. try{
32. Thread.sleep(pollingInterval);
33. }
34. catch (InterruptedException exc){ }
35. }
36. }
37.
38. public void updateTask(Task changedTask){
39. try{
40. updateServer.updateTask(taskID, changedTask);
41. }
42. catch (RemoteException exc){ }
43. catch (UpdateException exc){
44. System.out.println(" " + parent + ": " + exc.getMessage());
45. }
46. }
47.
48. public int getPollingInterval(){ return pollingInterval; }
49. public boolean isShutdown(){ return shutdown; }
50.
51. public void setPollingInterval(int newPollingInterval){ pollingInterval =
newPollingInterval; }
52. public void setShutdown(boolean isShutdown){ shutdown = isShutdown; }
53. }
The RMI server's behavior is defined by the ClientPullServer interface and managed by the
ClientPullServerImpl class. Two methods allow clients to interact with a server, getTask and updateTask .
Example A.238 ClientPullServer.java
1. import java.rmi.Remote;
2. import java.rmi.RemoteException;
3. import java.util.Date;
4. public interface ClientPullServer extends Remote{
5. public Task getTask(String taskID, Date lastUpdate) throws RemoteException,
UpdateException;
6. public void updateTask(String taskID, Task updatedTask) throws RemoteException,
UpdateException;
7. }
Example A.239 ClientPullServerImpl.java
1. import java.util.Date;
2. import java.rmi.Naming;
3. import java.rmi.server.UnicastRemoteObject;
4. public class ClientPullServerImpl implements ClientPullServer{
5. private static final String UPDATE_SERVER_SERVICE_NAME = "updateServer";
6. public ClientPullServerImpl(){
7. try {
8. UnicastRemoteObject.exportObject(this);
9. Naming.rebind(UPDATE_SERVER_SERVICE_NAME, this);
10. }
11. catch (Exception exc){
12. System.err.println("Error using RMI to register the ClientPullServerImpl " + exc);
13. }
14. }
15.
Search WWH ::




Custom Search