Proper usage example for $@?
taylor.marks Mar 8, 2016 10:21 PMHere's some Byteman rules that work fine:
RULE trace SLServer initCoreServices at getInstance
CLASS ^com.empolis.ecls.server.system.server.Server
METHOD initCoreServices
AT INVOKE getInstance ALL
IF true
DO traceOpen("ECLSManagedConnectionFactory", "/app/ECLSManagedConnectionFactory.log");
traceln("ECLSManagedConnectionFactory", "Invoking getInstance in initCoreServices on Server or subclass.");
traceClose("ECLSManagedConnectionFactory");
ENDRULE
RULE trace SLServer initCoreServices at getProperty
CLASS ^com.empolis.ecls.server.system.server.Server
METHOD initCoreServices
AT INVOKE getProperty ALL
IF true
DO traceOpen("ECLSManagedConnectionFactory", "/app/ECLSManagedConnectionFactory.log");
traceln("ECLSManagedConnectionFactory", "Invoking getProperty in initCoreServices on Server or subclass.");
traceClose("ECLSManagedConnectionFactory");
ENDRULE
When I run these rules, I get output that looks like this in my log file:
Invoking getInstance in initCoreServices on Server or subclass.
Invoking getInstance in initCoreServices on Server or subclass.
Invoking getInstance in initCoreServices on Server or subclass.
Invoking getInstance in initCoreServices on Server or subclass.
Invoking getProperty in initCoreServices on Server or subclass.
Invoking getProperty in initCoreServices on Server or subclass.
Invoking getInstance in initCoreServices on Server or subclass.
Invoking getInstance in initCoreServices on Server or subclass.
Invoking getProperty in initCoreServices on Server or subclass.
Invoking getProperty in initCoreServices on Server or subclass.
That's useful - I kind of know what is getting run. I'd like more details, though. What arguments are actually getting passed in? The documentation for 3.0.2 (the latest version of the docs I could find - I'm actually using 3.0.3) says that I can use $@ to get at the arguments inside of AT INVOKE. I tried each of the following in seperate tests within a DO body. Each of them resulted in no logs going to my log file at all, which suggests they aren't working for whatever reason.
traceln("ECLSManagedConnectionFactory", $@);
traceln("ECLSManagedConnectionFactory", "Invoking getProperty in initCoreServices on Server or subclass. Arguments: " + $@);
traceln("ECLSManagedConnectionFactory", "Invoking getProperty in initCoreServices on Server or subclass. First argument: " + $@[1]);
I've looked around but couldn't find any examples of using $@. Am I using it properly? How can I find out? I'm firing up Byteman during my Wildfly server start up... is there some way I can get Byteman to log feedback about my rules into a file or something? (It would be quite difficult to run the rules without the Wildfly server... getting the classes to resolve and whatnot would be a major pain.)
Also... how do types within Byteman work? I thought it would be super typesafe/strict like Java is, but this rule works:
RULE trace setECLSPropFile exception
CLASS com.empolis.ecls.server.j2ee.jca.impl.ECLSManagedConnectionFactory
METHOD setECLSPropFile
AT THROW
IF true
DO traceOpen("ECLSManagedConnectionFactory", "/app/ECLSManagedConnectionFactory.log");
traceln("ECLSManagedConnectionFactory", "Throwing from setECLSPropFile");
traceln("ECLSManagedConnectionFactory", "This was thrown: " + $^);
traceClose("ECLSManagedConnectionFactory");
ENDRULE
$^, according to the documentation, is a Throwable. In ordinary Java, attempting to add a Throwable to a string wouldn't work - you need to run the toString method on the Throwable first (I think - I haven't actually done much Java programming in the last 3 years). In Byteman, it seems that running toString is implicit.