/Users/lyon/j4p/src/net/rmi/rmiimage/Client.java

1    package net.rmi.rmiimage; 
2     
3    import java.rmi.Naming; 
4     
5    class StartBenchmark extends Thread { 
6      int servernumber; 
7     
8      static BenchMark BM[] = new BenchMark[26]; 
9      CpuPanel cpu[] = new CpuPanel[26]; 
10    
11     public static boolean checkServers(int i, String servername) { 
12       try { 
13         System.out.println("Looking up servers..."); 
14         System.out.println("Checking server " + servername); 
15         BM[i] = (BenchMark) Naming.lookup(servername); 
16         System.out.println("Server checked!"); 
17         return true; 
18       } catch (Exception e) { 
19         System.out.println("The exception in checking server: " + e); 
20       } 
21       return false; 
22     } 
23    
24     public StartBenchmark(int i, CpuPanel Cpu) { 
25       servernumber = i; 
26       cpu[i] = Cpu; 
27     } 
28    
29     public void run() { 
30       long starttime, endtime; 
31       try { 
32         starttime = System.currentTimeMillis(); 
33         BM[servernumber].multiplyBench(999999); 
34         endtime = System.currentTimeMillis(); 
35         System.out.println("The time taken is: " + 
36                            (endtime - starttime)); 
37         cpu[servernumber].setSpeed((endtime - starttime)); 
38       } catch (Exception e) { 
39         System.out.println(e); 
40       } 
41     } 
42   } 
43    
44   public class Client { 
45     static String serverNames[] = { 
46       "rmi://" + "192.107.38.221" + ":1099/HelloServer", 
47       "rmi://" + "192.107.38.222" + ":1099/Helloserver", 
48       "rmi://" + "192.107.38.223" + ":1099/HelloServer", 
49       "rmi://" + "192.107.38.224" + ":1099/HelloServer", 
50       "rmi://" + "192.107.38.225" + ":1099/HelloServer", 
51       "rmi://" + "192.107.38.226" + ":1099/HelloServer", 
52       "rmi://" + "192.107.38.227" + ":1099/HelloServer", 
53       "rmi://" + "192.107.38.228" + ":1099/HelloServer", 
54       "rmi://" + "192.107.38.229" + ":1099/HelloServer", 
55       "rmi://" + "192.107.38.230" + ":1099/HelloServer", 
56       "rmi://" + "192.107.38.231" + ":1099/HelloServer", 
57       "rmi://" + "192.107.38.80" + ":1099/HelloServer", 
58       "rmi://" + "192.107.38.81" + ":1099/HelloServer", 
59       "rmi://" + "192.107.38.82" + ":1099/HelloServer", 
60       "rmi://" + "192.107.38.83" + ":1099/HelloServer", 
61       "rmi://" + "192.107.38.84" + ":1099/HelloServer", 
62       "rmi://" + "192.107.38.85" + ":1099/HelloServer", 
63       "rmi://" + "192.107.38.86" + ":1099/HelloServer", 
64       "rmi://" + "192.107.38.87" + ":1099/HelloServer", 
65       "rmi://" + "192.107.38.88" + ":1099/HelloServer", 
66       "rmi://" + "192.107.38.89" + ":1099/HelloServer", 
67       "rmi://" + "192.107.38.92" + ":1099/HelloServer", 
68       "rmi://" + "192.107.38.93" + ":1099/HelloServer", 
69       "rmi://" + "192.107.38.94" + ":1099/HelloServer", 
70       "rmi://" + "192.107.38.95" + ":1099/HelloServer", 
71       "rmi://" + "192.107.38.96" + ":1099/HelloServer", 
72       "rmi://" + "192.107.38.97" + ":1099/HelloServer", 
73       "rmi://" + "192.107.38.98" + ":1099/HelloServer" 
74     }; 
75    
76     StartBenchmark sb[] = new StartBenchmark[serverNames.length]; 
77     boolean b[] = new boolean[serverNames.length]; 
78    
79     public Client(int statearr[]) { 
80       for (int i = 0; i < serverNames.length; i++) { 
81         if (statearr[i] == 1) 
82           b[i] = StartBenchmark.checkServers(i, 
83                                              serverNames[i]); 
84       } 
85     } 
86    
87     public void Start(int i, CpuPanel Cpu) { 
88       if (b[i]) //&& !(sb[i].isAlive())) 
89       { 
90         sb[i] = new StartBenchmark(i, Cpu); 
91         sb[i].start(); 
92       } else 
93         System.out.println("Server " + serverNames[i] + " not found"); 
94     } 
95   } 
96