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: import org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper;
10: import org.codehaus.aspectwerkz.exception.WrappedRuntimeException;
11:
12: /**
13: * In process HotSwap - Java level API <p/>When used, the hook* classes (AspectWerkz - core) MUST be
14: * in bootclasspath to ensure correct behavior and lookup of the ClassPreProcessor singleton
15: *
16: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
17: */
18: public class HotSwapClient {
19:
20: static {
21: System.loadLibrary("aspectwerkz");
22: }
23:
24: /**
25: * Native method to calls the JVM C level API
26: *
27: * @param className
28: * @param klazz
29: * @param newBytes
30: * @param newLength
31: * @return
32: */
33: private static native int hotswap(String className, Class klazz,
34: byte[] newBytes, int newLength);
35:
36: /**
37: * In process hotswap
38: *
39: * @param klazz
40: * @param newBytes
41: */
42: public static void hotswap(final Class klazz, final byte[] newBytes) {
43: int code = hotswap(klazz.getName(), klazz, newBytes,
44: newBytes.length);
45: if (code != 0) {
46: throw new RuntimeException("HotSwap failed for "
47: + klazz.getName() + ": " + code);
48: }
49: }
50:
51: }
|