aboutsummaryrefslogtreecommitdiffstats
path: root/sample/hotswap
diff options
context:
space:
mode:
Diffstat (limited to 'sample/hotswap')
-rw-r--r--sample/hotswap/HelloWorld.java5
-rw-r--r--sample/hotswap/Test.java25
-rw-r--r--sample/hotswap/logging/HelloWorld.java6
3 files changed, 36 insertions, 0 deletions
diff --git a/sample/hotswap/HelloWorld.java b/sample/hotswap/HelloWorld.java
new file mode 100644
index 00000000..51d8fcd9
--- /dev/null
+++ b/sample/hotswap/HelloWorld.java
@@ -0,0 +1,5 @@
+public class HelloWorld {
+ public void print() {
+ System.out.println("hello world");
+ }
+}
diff --git a/sample/hotswap/Test.java b/sample/hotswap/Test.java
new file mode 100644
index 00000000..c0ae1771
--- /dev/null
+++ b/sample/hotswap/Test.java
@@ -0,0 +1,25 @@
+import java.io.*;
+import javassist.tool.HotSwapper;
+
+public class Test {
+ public static void main(String[] args) throws Exception {
+ HotSwapper hs = new HotSwapper(8000);
+ new HelloWorld().print();
+
+ File newfile = new File("logging/HelloWorld.class");
+ byte[] bytes = new byte[(int)newfile.length()];
+ new FileInputStream(newfile).read(bytes);
+ System.out.println("** reload a logging version");
+
+ hs.reload("HelloWorld", bytes);
+ new HelloWorld().print();
+
+ newfile = new File("HelloWorld.class");
+ bytes = new byte[(int)newfile.length()];
+ new FileInputStream(newfile).read(bytes);
+ System.out.println("** reload the original version");
+
+ hs.reload("HelloWorld", bytes);
+ new HelloWorld().print();
+ }
+}
diff --git a/sample/hotswap/logging/HelloWorld.java b/sample/hotswap/logging/HelloWorld.java
new file mode 100644
index 00000000..88f08664
--- /dev/null
+++ b/sample/hotswap/logging/HelloWorld.java
@@ -0,0 +1,6 @@
+public class HelloWorld {
+ public void print() {
+ System.out.println("** HelloWorld.print()");
+ System.out.println("hello world");
+ }
+}