Additional top-level class in compilation unit: Trigger.
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.
HotSwapAgent
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private VirtualMachine | |
| private Map | |
| private MethodEntryRequest | |
| private Trigger | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private Connector | |
| pack-priv void | |
| private static MethodEntryRequest | |
| public void | |
| public void | |
| private void | |
| private void | |
| private ReferenceType | |
| pack-priv EventSet |
| HOST_NAME | back to summary |
|---|---|
| private static final String HOST_NAME | |
| jvm | back to summary |
|---|---|
| private VirtualMachine jvm | |
| newClassFiles | back to summary |
|---|---|
| private Map<ReferenceType, byte[]> newClassFiles | |
| request | back to summary |
|---|---|
| private MethodEntryRequest request | |
| trigger | back to summary |
|---|---|
| private Trigger trigger | |
| TRIGGER_NAME | back to summary |
|---|---|
| private static final String TRIGGER_NAME | |
| HotSwapper | back to summary |
|---|---|
| public HotSwapper(int port) throws IOException, IllegalConnectorArgumentsException Connects to the JVM.
| |
| HotSwapper | back to summary |
|---|---|
| public HotSwapper(String port) throws IOException, IllegalConnectorArgumentsException Connects to the JVM.
| |
| deleteEventRequest | back to summary |
|---|---|
private void deleteEventRequest(EventRequestManager manager, MethodEntryRequest request)
| |
| findConnector | back to summary |
|---|---|
| private Connector findConnector(String connector) throws IOException | |
| hotswap | back to summary |
|---|---|
| pack-priv void hotswap() | |
| methodEntryRequests | back to summary |
|---|---|
| private static MethodEntryRequest methodEntryRequests(EventRequestManager manager, String classpattern) | |
| reload | back to summary |
|---|---|
| public void reload(String className, byte[] classFile) Reloads a class.
| |
| reload | back to summary |
|---|---|
| public void reload(Map<String, byte[]> classFiles) Reloads a class. | |
| reload2 | back to summary |
|---|---|
| private void reload2(Map<ReferenceType, byte[]> map, String msg) | |
| startDaemon | back to summary |
|---|---|
| private void startDaemon() | |
| toRefType | back to summary |
|---|---|
| private ReferenceType toRefType(String className) | |
| waitEvent | back to summary |
|---|---|
| pack-priv EventSet waitEvent() throws InterruptedException | |