• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package sample.evolve;
2 
3 import javassist.*;
4 
5 /**
6  * DemoLoader is a class loader for running a program including
7  * an updatable class.  This simple loader allows only a single
8  * class to be updatable.  (Extending it for supporting multiple
9  * updatable classes is easy.)
10  *
11  * To run, type as follows:
12  *
13  * % java sample.evolve.DemoLoader <port number>
14  *
15  * Then DemoLoader launches sample.evolve.DemoServer with <port number>.
16  * It also translates sample.evolve.WebPage, which sample.evolve.DemoServer
17  * uses, so that it is an updable class.
18  *
19  * Note: JDK 1.2 or later only.
20  */
21 public class DemoLoader {
22     private static final int initialVersion = 0;
23     private String updatableClassName = null;
24     private CtClass updatableClass = null;
25 
26     /* Creates a <code>DemoLoader</code> for making class WebPage
27      * updatable.  Then it runs main() in sample.evolve.DemoServer.
28      */
main(String[] args)29     public static void main(String[] args) throws Throwable {
30         Evolution translator = new Evolution();
31         ClassPool cp = ClassPool.getDefault();
32         Loader cl = new Loader();
33         cl.addTranslator(cp, translator);
34 
35         translator.makeUpdatable("sample.evolve.WebPage");
36         cl.run("sample.evolve.DemoServer", args);
37     }
38 }
39