/Users/lyon/j4p/src/net/compute/ComputeClient.java
|
1 package net.compute;
2
3
4 import java.io.ObjectInputStream;
5 import java.io.ObjectOutputStream;
6 import java.io.Serializable;
7 import java.net.Socket;
8 /**
9 * 1. Use the ComputeClient to create a Reloader
10 * that gives you bytes codes.
11 * 2. Get the RemoteClassLoader and send it to the
12 * compute server.
13 * 3. The compute server define and computes the class using
14 * the remote class loader.
15 * 4. It then returns the answer to the compute client.
16 */
17
18 public class ComputeClient implements Runnable {
19 private ComputableObject computeIt = new BigComputation();
20 private String lookupServer = "172.16.11.107";
21 private int lookupServerPort = 8088;
22
23 public void setComputableObject(ComputableObject co) {
24 computeIt = co;
25 }
26
27 public static void main(String args[]) {
28 ComputeClient cc = new ComputeClient();
29 //cc.setComputableObject( new ANewComputableObject());
30 cc.run();
31 }
32
33 public void run() {
34 try {
35 Socket s
36 = new Socket(lookupServer, lookupServerPort);
37 ObjectInputStream
38 ois =
39 new ObjectInputStream(
40 s.getInputStream());
41 ObjectOutputStream
42 oos =
43 new ObjectOutputStream(
44 s.getOutputStream());
45 oos.writeObject(computeIt);
46 // block the thread of execution
47 // until the computation is finished by
48 // the compute server. E.g.
49 // a = f(b);
50 Object o = ois.readObject();
51 System.out.println(o);
52 ois.close();
53 oos.close();
54 } catch (Exception e) {
55 e.printStackTrace();
56 }
57 }
58
59 private static class ANewComputableObject
60 implements ComputableObject {
61 public Serializable compute() {
62 return "this is really different";
63 }
64 }
65 }