javassist.util
Class HotSwapper

java.lang.Object
  extended by javassist.util.HotSwapper

public class HotSwapper
extends java.lang.Object

A utility class for dynamically reloading a class by the Java Platform Debugger Architecture (JPDA), or HotSwap. It works only with JDK 1.4 and later.

Note: The new definition of the reloaded class must declare the same set of methods and fields as the original definition. The schema change between the original and new definitions is not allowed by the JPDA.

To use this class, the JVM must be launched with the following command line options:

Note that 8000 is the port number used by HotSwapper. Any port number can be specified. Since HotSwapper does not launch another JVM for running a target application, this port number is used only for inter-thread communication.

Furthermore, JAVA_HOME/lib/tools.jar must be included in the class path.

Using HotSwapper is easy. See the following example:

reload() first unload the Test class and load a new version of the Test class. classFile is a byte array containing the new contents of the class file for the Test class. The developers can repatedly call reload() on the same HotSwapper object so that they can reload a number of classes.

Since:
3.1

Constructor Summary
HotSwapper(int port)
          Connects to the JVM.
HotSwapper(java.lang.String port)
          Connects to the JVM.
 
Method Summary
 void reload(java.util.Map classFiles)
          Reloads a class.
 void reload(java.lang.String className, byte[] classFile)
          Reloads a class.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HotSwapper

public HotSwapper(int port)
           throws java.io.IOException,
                  com.sun.jdi.connect.IllegalConnectorArgumentsException
Connects to the JVM.

Parameters:
port - the port number used for the connection to the JVM.
Throws:
java.io.IOException
com.sun.jdi.connect.IllegalConnectorArgumentsException

HotSwapper

public HotSwapper(java.lang.String port)
           throws java.io.IOException,
                  com.sun.jdi.connect.IllegalConnectorArgumentsException
Connects to the JVM.

Parameters:
port - the port number used for the connection to the JVM.
Throws:
java.io.IOException
com.sun.jdi.connect.IllegalConnectorArgumentsException
Method Detail

reload

public void reload(java.lang.String className,
                   byte[] classFile)
Reloads a class.

Parameters:
className - the fully-qualified class name.
classFile - the contents of the class file.

reload

public void reload(java.util.Map classFiles)
Reloads a class.

Parameters:
classFiles - a map between fully-qualified class names and class files. The type of the class names is String and the type of the class files is byte[].


Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2008 Shigeru Chiba. All Rights Reserved.