Sesat > Docs + Support > Debugging > Sesat-Interpreter

The Sesat-Interpreter

Basic usage

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:

Bar.java
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.

Console output
..
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.

Console output
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.

Aspectj

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.

https://michaelsembwever.github.io/Sesat/svn/sesat-commons/commons-interpreter-aspectj/trunk/src/main/aspect/no/sesat/interpreter/aspectj/QueryParserInspector.aj

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

Javaagent

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.

 © 2007-2009 Schibsted ASA
Contact us