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