In the first tutorial we have shown some basic rule examples. We have however not still shown how to load/unload dynamically new rules. This tutorial shows how to manage Byteman rules.
Byteman does not require to be configured statically, you can as well inject rules and start the agent dynamically on a running server.
Starting the Byteman agent (bminstall script)
If you have not added any JVM startup option, the first thing you need to do is starting the agent and connecting it to the running JVM. Pickup the PID of your JBoss AS (or any other JVM process) with any tool like JConsole:
Now navigate to the BYTEMAN_HOME and move to the “bin” folder
C:\byteman\bin>bminstall 11776
Loading new Rules at runtime (bmsubmit -l rule)
Once that the Agent is running, you can start loading rules to the JVM. In order to load/unload rules you can use the bmsubmit shell script. Here’s how to load a rule named example.btm
C:\byteman\bin>bmsubmit.bat -l C:\jboss-as-7.1.1.Final\bin\example.btm
Unloading Rules at runtime (bmsubmit -u rule)
Rules can be as well unloaded using the bmsubmit -u shell command as in this example:
C:\byteman\bin>bmsubmit.bat -u C:\jboss-as-7.1.1.Final\bin\example.btm
uninstall RULE trace Servlet
By providing no arguments to the bmsubmit -u shell you will unload all rules
Listing Rules (bmsubmit -l)
The bmsubmit -l shell command provides a list of all rules which are loaded
C:\byteman\bin>bmsubmit.bat -l
# File example.btm line 2
RULE trace Servlet
CLASS com.sample.ByteServlet
METHOD doGet
AT ENTRY
BIND request = $request;
IF true
DO traceln ("Query String " + request.getQueryString())
ENDRULE