/Users/lyon/j4p/src/javassist/sample/rmi/ComputationClient.java
|
1 package javassist.sample.rmi;
2
3 import javassist.rmi.ObjectImporter;
4 import javassist.rmi.ObjectNotFoundException;
5 import javassist.web.Viewer;
6
7 public class ComputationClient {
8 private ObjectImporter objectImporter;
9 private RemoteComputation computable;
10
11
12 public ComputationClient() {
13 Viewer viewer = (Viewer) getClass().getClassLoader();
14 objectImporter = new ObjectImporter(
15 viewer.getServer(),
16 viewer.getPort());
17 try {
18 //lookupComputation();
19 lookupJob();
20 } catch (ObjectNotFoundException e) {
21 e.printStackTrace();
22 }
23 }
24
25 private void lookupComputation() throws ObjectNotFoundException {
26 Object obj = objectImporter.lookupObject("computation");
27 Class c = obj.getClass();
28 computable = (RemoteComputation) obj;
29 System.out.println("got computation as:"
30 + c.getName());
31 if (computable instanceof RemoteComputation)
32 System.out.println("this is computable");
33 else
34 System.out.println("this is not computable");
35
36 System.out.println(computable.compute(new Job()));
37 System.out.println("computation computed!");
38 }
39
40 private void lookupJob()
41 throws ObjectNotFoundException {
42 Object obj =
43 objectImporter.lookupObject("job");
44 Class c = obj.getClass();
45 Job j = (Job) obj;
46 System.out.println("got job as:"
47 + c.getName());
48 if (j instanceof Job)
49 System.out.println("this is a Job");
50 else
51 System.out.println("this is not computable");
52
53 System.out.println(j.compute());
54 System.out.println("computation computed!");
55 }
56
57
58 public static void main(String[] args) {
59 new ComputationClient();
60
61
62 }
63 }
64