/Users/lyon/j4p/src/net/rmi/rmiSynth/HostManagerGui.java

1    package net.rmi.rmiSynth; 
2     
3    // rmi.rmiSynth.HostManager 
4     
5    import gui.browser.HtmlSynthesizer; 
6    import gui.html.Browser; 
7     
8    import java.rmi.RemoteException; 
9     
10   /** 
11    * The <code>HostManager</code> is invoked 
12    * remotely by unicast remote protocol. New 
13    * workers that enter into the grid must know the 
14    * IP addBk.address of the HostManager We need to 
15    * provide a leasing mechanism that expires a 
16    * host. First start the host manager. Then start 
17    * the computation servers. Finally start the 
18    * compute client 
19    */ 
20    
21   public class HostManagerGui { 
22    
23       HostManagerInterface hmi; 
24    
25       HostManagerGui() { 
26           hmi = HostManager.getProxy(); 
27    
28       } 
29    
30       private void exit() { 
31           System.exit(0); 
32       } 
33    
34    
35       public void printHosts() { 
36           print(getHosts()); 
37       } 
38    
39       public void printHtml() { 
40           print(getHtml()); 
41       } 
42    
43       public String getHtml() { 
44           Host h[] = getHosts(); 
45           HtmlSynthesizer hs = new HtmlSynthesizer(); 
46           int xMax = h.length; 
47           int yMax = 2; 
48           String hostSheet [][] = new String[xMax][yMax]; 
49           for (int x = 0; x < xMax; x++) { 
50               hostSheet[x][0] = 
51               hs.getCheckbox(h[x].getIP(), true) 
52               + "benchMark:" 
53               + 
54               h[x].getBenchMark(); 
55               hostSheet[x][1] = h[x].toString(); 
56           } 
57           String titles[][] = { 
58               {"on/off:BenchMark Run time", 
59                "Host Name/IP Address"} 
60           }; 
61    
62           return hs.getHtml( 
63                   hs.getHead( 
64                           hs.getTitle( 
65                                   "CentiJ Web Interface")) + 
66                   hs.getBody(hs.getHomePage(1) + 
67                              "CentiJ Web Interface" + 
68                              hs.getTable( 
69                                      hs.getForm( 
70                                              "processHostRequest", 
71                                              "get", 
72                                              hs.getP( 
73                                                      hs.getSheet( 
74                                                              titles) 
75                                                      + 
76                                                      hs.getSheet( 
77                                                              hostSheet)))) 
78                              + 
79                              hs.getP( 
80                                      hs.getSubmit()))); 
81       } 
82    
83       public void testHtmlDisplay() { 
84           Browser b = new Browser(); 
85           new HtmlSynthesizer(); 
86           b.setString(getHtml()); 
87       } 
88    
89       public static void print(Object o[]) { 
90           for (int i = 0; i < o.length; i++) { 
91               print(o[i]); 
92           } 
93       } 
94    
95       public Host[] getHosts() { 
96           try { 
97               System.out.println("Getting Hosts:"); 
98               Host h[] = hmi.getHosts(); 
99               print("there are:" + h.length + 
100                    " hosts"); 
101              return h; 
102          } catch (RemoteException e) { 
103              String s = "ERROR:HostManagerGUI, can't get hosts!"; 
104              print(s); 
105              exit(); 
106              return null; 
107          } 
108      } 
109   
110      public static void print(Object o) { 
111          System.out.println(o); 
112      } 
113   
114      public static void main(String args[]) { 
115          HostManagerGui hmg = new HostManagerGui(); 
116          hmg.printHosts(); 
117          hmg.printHtml(); 
118          hmg.testHtmlDisplay(); 
119      } 
120   
121   
122  } 
123