/Users/lyon/j4p/src/javassist/sample/rmi/ComputationServer.java

1    package javassist.sample.rmi; 
2     
3    import javassist.CannotCompileException; 
4    import javassist.NotFoundException; 
5    import javassist.rmi.AppletServer; 
6     
7    import java.io.IOException; 
8     
9    public class ComputationServer { 
10       AppletServer as = null; 
11    
12       // the following code cannot work on a running AppletServer. 
13       // how do we exportObjects on a live running AppletServer? 
14       public void exportObject(String name, Object obj) { 
15    
16           try { 
17               as.end(); 
18               initServer(); 
19               as.exportObject(name, obj); 
20               as.run(); 
21           } catch (IOException e) { 
22               e.printStackTrace(); 
23           } catch (NotFoundException e) { 
24               e.printStackTrace(); 
25           } catch (CannotCompileException e) { 
26               e.printStackTrace(); 
27           } 
28    
29       } 
30    
31    
32       private void initServer() throws IOException, NotFoundException, CannotCompileException { 
33           as = new AppletServer(5500); 
34       } 
35    
36       public ComputationServer() { 
37           try { 
38               initServer(); 
39               // you can export a new job with the same 
40               // name. The most recent export will be used. 
41    
42    
43               as.exportObject("job", new Job.IntJob()); 
44               as.run(); 
45           } catch (IOException e) { 
46               e.printStackTrace(); 
47           } catch (NotFoundException e) { 
48               e.printStackTrace(); 
49           } catch (CannotCompileException e) { 
50               e.printStackTrace(); 
51           } 
52       } 
53    
54    
55       public static void main(String[] args) { 
56           ComputationServer cs 
57                   = new ComputationServer(); 
58           cs.exportObject("job",new Job()); 
59       } 
60   } 
61