KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > extension > hotswap > Foo


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the BSD-style license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.extension.hotswap;
9
10 /**
11  * A simple class to test the in process HotSwap
12  *
13  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
14  */

15 public class Foo {
16
17     public void sayHello() {
18         System.out.println("Hello - I am " + this + " class " + this.getClass().hashCode());
19     }
20
21     public static void main(String JavaDoc a[]) throws Throwable JavaDoc {
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 }
Popular Tags