Java Reference
In-Depth Information
2. public class RunPattern{
3. public static void main(String [] arguments){
4. System.out.println("Example for the SuccessiveUpdate pattern");
5. System.out.println("This code provides a basic demonstration");
6. System.out.println(" of how the client pull form of this pattern");
7. System.out.println(" could be applied.");
8. System.out.println("In this case, a change made by a client to a");
9. System.out.println(" central Task object is subsequently retrieved");
10. System.out.println(" and displayed by another client.");
11.
12. System.out.println("Running the RMI compiler (rmic)");
13. System.out.println();
14. try{
15. Process p1 = Runtime.getRuntime().exec("rmic ClientPullServerImpl");
16. p1.waitFor();
17. }
18. catch (IOException exc){
19. System.err.println("Unable to run rmic utility. Exiting application.");
20. System.exit(1);
21. }
22. catch (InterruptedException exc){
23. System.err.println("Threading problems encountered while using the rmic utility.");
24. }
25.
26. System.out.println("Starting the rmiregistry");
27. System.out.println();
28. Process rmiProcess = null;
29. try{
30. rmiProcess = Runtime.getRuntime().exec("rmiregistry");
31. Thread.sleep(15000);
32. }
33. catch (IOException exc){
34. System.err.println("Unable to start the rmiregistry. Exiting application.");
35. System.exit(1);
36. }
37. catch (InterruptedException exc){
38. System.err.println("Threading problems encountered when starting the rmiregistry.");
39. }
40.
41. System.out.println("Creating the ClientPullServer and two PullClient objects");
42. ClientPullServer server = new ClientPullServerImpl();
43. PullClient clientOne = new PullClient("Thing I");
44. PullClient clientTwo = new PullClient("Thing II");
45. clientOne.requestTask("First work step");
46. clientTwo.requestTask("First work step");
47.
48. try{
49. Thread.sleep(10000);
50. }
51. catch (InterruptedException exc){ }
52.
53. Task task = clientOne.getUpdatedTask();
54. task.setTaskDetails("Trial for task update");
55. clientOne.updateTask(task);
56.
57. Task newTask = clientTwo.getUpdatedTask();
58. newTask.setTaskDetails("New details string");
59. clientTwo.updateTask(newTask);
60.
61.
62. }
63. }
 
Search WWH ::




Custom Search