Search code examples
drools

How to get the current session name in Drools Rule RHS


I have tried searching through the various levels of indirection of both 'drools' and 'kcontext', but seem to keep running into a wall. Is there a way I can get access to the current session name in a RHS of a rule?

Thanks.


Solution

  • The "session name" is used as a handle for retrieving the session model from the container. It isn't a property of KieSession.

    It's easy to use a global containing the session name:

    String sessionName = ...;
    KieSession kSession = kContainer.newKieSession( sessionName );
    kSession.setGlobal( "sessionName", sessionName );
    

    DRL

    global String sessionName;
    

    This might be improved by adding the creation date/time or anything else that identifies session instances (as opposed to session model).