01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the BSD-style license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.extension.hotswap;
08:
09: /**
10: * A simple class to test the in process HotSwap
11: *
12: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
13: */
14: public class Foo {
15:
16: public void sayHello() {
17: System.out.println("Hello - I am " + this + " class "
18: + this .getClass().hashCode());
19: }
20:
21: public static void main(String a[]) throws Throwable {
22: // System.out.println("start");
23: // HotSwapClient client = new HotSwapClient();
24: // System.out.println("created hotswap client");
25: // Foo aFoo = new Foo();
26: // aFoo.sayHello();
27: // ClassPool cp = ClassPool.getDefault();
28: // CtClass newFoo = cp.get("org.codehaus.aspectwerkz.extension.hotswap.Foo");
29: // CtMethod m = newFoo.getDeclaredMethod("sayHello");
30: // m.insertBefore("{System.out.println(\"\thotswapped talks:\");}");
31: // byte[] newFooB = cp.write("org.codehaus.aspectwerkz.extension.hotswap.Foo");
32: // HotSwapClient.hotswap(Foo.class, newFooB);
33: //
34: // // same instance is hotswapped
35: // aFoo.sayHello();
36: //
37: // // other instance is hotswapped
38: // Foo bFoo = new Foo();
39: // bFoo.sayHello();
40: // ClassPool cp2 = new ClassPool(null);
41: // cp2.appendClassPath(new LoaderClassPath(Foo.class.getClassLoader()));
42: // try {
43: // // swap java.lang.ClassLoader with itself
44: // cp2.writeFile("java.lang.ClassLoader", "_dump");
45: // //byte[] bytecode =
46: // ClassLoaderPatcher.getPatchedClassLoader("org.codehaus.aspectwerkz.hook.impl.ClassLoaderPreProcessorImpl");
47: // HotSwapClient.hotswap(ClassLoader.class, cp2.get("java.lang.ClassLoader").toBytecode());
48: // } catch (Throwable e) {
49: // e.printStackTrace();
50: // }
51: //
52: // // swap java.lang.String with itself
53: // cp2.writeFile("java.lang.String", "_dump");
54: // //byte[] bytecode =
55: // ClassLoaderPatcher.getPatchedClassLoader("org.codehaus.aspectwerkz.hook.impl.ClassLoaderPreProcessorImpl");
56: // HotSwapClient.hotswap(String.class, cp2.get("java.lang.String").toBytecode());
57: }
58: }
|