aboutsummaryrefslogtreecommitdiffstats
path: root/sample/evolve/DemoLoader.java
blob: 7c770bd51986d7e6837d60aba88c48c97aaee357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package sample.evolve;

import javassist.*;

/**
 * DemoLoader is a class loader for running a program including
 * an updatable class.  This simple loader allows only a single
 * class to be updatable.  (Extending it for supporting multiple
 * updatable classes is easy.)
 *
 * To run, type as follows:
 *
 * % java sample.evolve.DemoLoader <port number>
 *
 * Then DemoLoader launches sample.evolve.DemoServer with <port number>.
 * It also translates sample.evolve.WebPage, which sample.evolve.DemoServer
 * uses, so that it is an updable class.
 *
 * Note: JDK 1.2 or later only.
 */
public class DemoLoader {
    private static final int initialVersion = 0;
    private String updatableClassName = null;
    private CtClass updatableClass = null;

    /* Creates a <code>DemoLoader</code> for making class WebPage
     * updatable.  Then it runs main() in sample.evolve.DemoServer.
     */
    public static void main(String[] args) throws Throwable {
        Evolution translator = new Evolution();
        ClassPool cp = ClassPool.getDefault();
        Loader cl = new Loader();
        cl.addTranslator(cp, translator);

        translator.makeUpdatable("sample.evolve.WebPage");
        cl.run("sample.evolve.DemoServer", args);
    }
}