Class HotSwapper
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:
For Java 1.4,
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
For Java 5,
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
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:
CtClass clazz = ... byte[] classFile = clazz.toBytecode(); HotSwapper hs = new HostSwapper(8000); // 8000 is a port number. hs.reload("Test", classFile);
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.
HotSwap
depends on the debug agent to perform hot-swapping
but it is reported that the debug agent is buggy under massively multithreaded
environments. If you encounter a problem, try HotSwapAgent
.
- Since:
- 3.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private VirtualMachine
private Map
<ReferenceType, byte[]> private MethodEntryRequest
private Trigger
private static final String
-
Constructor Summary
ConstructorsConstructorDescriptionHotSwapper
(int port) Connects to the JVM.HotSwapper
(String port) Connects to the JVM. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
deleteEventRequest
(EventRequestManager manager, MethodEntryRequest request) private Connector
findConnector
(String connector) (package private) void
hotswap()
private static MethodEntryRequest
methodEntryRequests
(EventRequestManager manager, String classpattern) void
Reloads a class.void
Reloads a class.private void
reload2
(Map<ReferenceType, byte[]> map, String msg) private void
private ReferenceType
(package private) EventSet
-
Field Details
-
jvm
-
request
-
newClassFiles
-
trigger
-
HOST_NAME
- See Also:
-
TRIGGER_NAME
-
-
Constructor Details
-
HotSwapper
Connects to the JVM.- Parameters:
port
- the port number used for the connection to the JVM.- Throws:
IOException
IllegalConnectorArgumentsException
-
HotSwapper
Connects to the JVM.- Parameters:
port
- the port number used for the connection to the JVM.- Throws:
IOException
IllegalConnectorArgumentsException
-
-
Method Details
-
findConnector
- Throws:
IOException
-
methodEntryRequests
private static MethodEntryRequest methodEntryRequests(EventRequestManager manager, String classpattern) -
deleteEventRequest
-
reload
Reloads a class.- Parameters:
className
- the fully-qualified class name.classFile
- the contents of the class file.
-
reload
Reloads a class.- Parameters:
classFiles
- a map between fully-qualified class names and class files. The type of the class names isString
and the type of the class files isbyte[]
.
-
toRefType
-
reload2
-
startDaemon
private void startDaemon() -
waitEvent
- Throws:
InterruptedException
-
hotswap
void hotswap()
-