| Sesat > Docs + Support > Debugging > Sesat-Interpreter |
The Sesat-Interpreter is a simple interpreter that let's you add commands with some arbitrary code assosiated with it.
To enable the Sesat-Interpreter set/export SESAT_INTERPRETER=true
an example of how to add a command:
import no.sesat.Interpreter; static { Interpreter.addFunction("gc", new Function() { public String execute(final Context ctx) { System.gc(); return "GC requested"; } public String describe() { return "Request a gc run."; } }); }
When you start catelina from the commandline, and the interpreter has been enabled by setting the SESAT_INTERPRETER enironment variable to true, then you will see the functions as they are added.
.. Added function: test-arguments Added function: help Added function: gc Added function: all-stacktraces Added function: loggers Added function: properties Added function: save Added function: read Added function: macro Added function: quit Added function: sites .. ..
Now you can invoke a method by typing in it's name.
help
Functions available:
all-stacktraces
Look at all stacktraces.
echo
Echo arguments.
gc
Request a gc run.
help
Print this help message
loggers
Print active loggers, and set level if specified. 'loggers [regexp] [level]'
macro
Make a macro
properties
List System.getProperties()
..
..
test-arguments 1 2 query='en fisk'
Raw argument string:
1 2 query='en fisk'
Argument array: 2
1
2
Keywords:
QUERY --> en fisk
Most of the functions added, like the one in Bar.java at the top, are in static blocks. This means that the function will be added when the class is loaded. So all functions might not be available at once.
Some times you do not want to introduce code permanently, then you might want to use AspectJ to instrument the classes. Have a look at this aspectj class.
If you want your aspect code to be active you need to include the interpreter-aspectj profile when building.
I use this:
-P include-fast,development,interpreter-aspectj
Enable this by setting JAVA_OPTS=-javaagent:/home/haavard/.m2/repository/sesat/commons-interpreter/2.0/commons-interpreter-2.0.jar
where home/haavard.... should be changed to wherever you have it.