Ruleflow not working with stateless session in drools-server 5.5.0.Final

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Ruleflow not working with stateless session in drools-server 5.5.0.Final

tslonaker
I am running drools-server 5.5.0.Final and I am having a problem with stateless sessions and ruleflows.  Only the first step in the ruleflow executes.  

There is a catch to my problem though.  I have drools-server hosted in JBoss 7.1.  If I restart the service by disabling and then enabling via the admin console then the ruleflow works correctly (all nodes hit) one time.  So, it always works just after the service starts.  Each time after the first rule execution it stops at the first ruleflow node.

I am sending commands to the service in JSON format through the REST interface.  If I send the same commands in the same order through Java / eclipse then the ruleflow works correctly every time.  

My problem sounds very similar to the problem described in the thread below:
http://drools.46999.n3.nabble.com/RuleFlow-only-calling-first-RuleFlowGroup-when-called-through-drools-server-td2514244.html

It looks like this problem was addressed in version 5.3.0 (https://issues.jboss.org/browse/JBRULES-2718).  
Reply | Threaded
Open this post in threaded view
|

Re: Ruleflow not working with stateless session in drools-server 5.5.0.Final

tslonaker
This post was updated on .
I have come up with steps to recreate the problem I am having with the ruleflow stopping on the first step when using a stateless session.  Hopefully it is simply something that I don’t have configured correctly.  Any help would be appreciated.  

Here is a zip file containing my source files for the rules, ruleflow, and the complied package file.  SimpleRuleflowTest.zip

My ruleflow looks like this:

START --> Step1 --> Step2 --> Step3 --> END

Below is what the Model and the Rules look like for my test.  I created the rules using Guvnor’s guided rule editor.  The text below is from the view source code window in Guvnor:
   
package SimpleRuleflowTest

declare Input
    Name: String
end

declare Output
    Name: String
end

declare InternalData
    StepNumber: Integer
end

rule "Step_1"
    ruleflow-group "Step1"
    dialect "mvel"
    when
        Input( )
    then
        InternalData fact0 = new InternalData();
        fact0.setStepNumber( 1 );
        insert( fact0 );
end

rule "Step_2"
    ruleflow-group "Step2"
    dialect "mvel"
    when
        InternalData( StepNumber == 1 )
    then
        InternalData fact0 = new InternalData();
        fact0.setStepNumber( 2 );
        insert( fact0 );
end

rule "Step_3"
    ruleflow-group "Step3"
    dialect "mvel"
    when
        InternalData( StepNumber == 2 )
    then
        Output fact0 = new Output();
        fact0.setName( "Finished with Step 3" );
        insert( fact0 );
end



I am using cURL to send the commands to the drools server.  Below the cURL command line I am using to test:

curl  -v -H "Content-Type: text/plain" --data "{\"batch-execution\":{\"lookup\":\"ksession1\",\"commands\":[{\"insert\":{\"object\":{\"SimpleRuleflowTest.Input\":{\"Name\":\"Test\"}}}},{\"start-process\":{\"process-id\":\"TestRuleflow\"}},{\"fire-all-rules\":{\"out-identifier\":\"firedActivations\"}},{\"get-objects\":{\"out-identifier\":\"objects\"}}]}}" http://localhost:8080/drools-server/kservice/rest/execute


Below is the JSON returned after the first execution just after the drools server is started.  Notice that 3 rules are executed and an Output object is created and returned:

{
    "execution-results": {
        "results": {
            "result": [{
                "identifier": "firedActivations",
                "value": {
                    "int": 3
               }
            },
            {
                "identifier": "objects",
                "value": {
                    "list": {
                        "SimpleRuleflowTest.InternalData": [{
                            "StepNumber": 1
                        },
                        {
                            "StepNumber": 2
                        }],
                        "SimpleRuleflowTest.Input": {
                            "Name": "Test"
                        },
                        "SimpleRuleflowTest.Output": {
                            "Name": "Finished with Step 3"
                        }
                    }
                }
            }]
        }
    }
}


Below is the JSON returned for every other call to the drools server after the first time.  Notice that only one rule is executed and no Output object is created:

{
    "execution-results": {
        "results": {
            "result": [{
                "identifier": "firedActivations",
                "value": {
                    "int": 1
                }
            },
            {
                "identifier": "objects",
                "value": {
                    "list": {
                        "SimpleRuleflowTest.Input": {
                            "Name": "Test"
                        },
                        "SimpleRuleflowTest.InternalData": {
                            "StepNumber": 1
                        }
                    }
                }
            }]
        }
    }
}


Here are the details of my setup:
- Drools server 5.5.0 Final
- Drools Guvnor 5.5.0 Final to create the rules
- Drools server and guvnor are hosted in JBoss 7.1
- The OS is Windows 7

Knowledge-services.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:drools="http://drools.org/schema/drools-spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring-1.3.0.xsd">
  <drools:grid-node id="node1"/>
  <drools:kbase id="kbase1" node="node1">
    <drools:resources>
      <drools:resource type="PKG" source="file:C:/DroolsRulePackages/SimpleRuleflowTest_1.pkg"/>
    </drools:resources>
  </drools:kbase>
  <drools:ksession id="ksession1" type="stateless" kbase="kbase1" node="node1"/>
</beans>



Camel-server.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    ">
   
  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  <cxf:rsServer id="rsServer"  
                address="/rest"
                serviceClass="org.drools.jax.rs.CommandExecutorImpl">
       <cxf:providers>
           <bean class="org.drools.jax.rs.CommandMessageBodyReader"/>
       </cxf:providers>
  </cxf:rsServer> 
 
  <cxf:cxfEndpoint id="soapServer"
            address="/soap"
             serviceName="ns:CommandExecutor"
             endpointName="ns:CommandExecutorPort"
          wsdlURL="soap.wsdl"
          xmlns:ns="http://soap.jax.drools.org/" >
    <cxf:properties>
      <entry key="dataFormat" value="MESSAGE"/>
      <entry key="defaultOperationName" value="execute"/>
    </cxf:properties>
  </cxf:cxfEndpoint>

  <bean id="droolsPolicy" class="org.drools.camel.component.DroolsPolicy" /> 
   
  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">   
    <route>
       <from uri="cxfrs://bean://rsServer"/>
       <policy ref="droolsPolicy">
               <unmarshal ref="json" />       
               <to uri="drools:node1/ksession1" />
               <marshal ref="json" />
       </policy>
    </route>       

    <route>
      <from uri="cxf://bean://soapServer"/>
      <policy ref="droolsPolicy">
        <unmarshal ref="xstream" />       
        <to uri="drools:node1/ksession1" />
        <marshal ref="xstream" />
      </policy>
    </route>
  </camelContext>
</beans>
Reply | Threaded
Open this post in threaded view
|

Re: Ruleflow not working with stateless session in drools-server 5.5.0.Final

tslonaker
I found a much easier way to recreate the problem described in my previous post.  I believe I have also found the root cause of the problem.  Below are the steps to recreate the issue:

- Create a simple ruleflow and rules and compile them into a rule package.
- In code create a stateless session
- In a loop
    o Create a fact
    o Create a new execution batch with the following commands
        - Insert the fact from above
        - Start Process
        - Fire All Rules
        - Get Objects
    o Execute the batch
    o Check the results (number of rules that ran)

I posted before that the problem didn’t happen while executing locally (not in drools server).  I didn’t realize this before, but adding a loop that executes the rules multiple times with the same session recreates the problem.  

Below is code that will recreate the issue.  Notice that the code below creates one instance of ksession and reuses it in the loop.  

        //Setup
        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        //The package includes the ruleflow
        kbuilder.add( ResourceFactory.newFileResource( ("YourRulePackage_WithRuleflow.pkg") ), ResourceType.PKG );
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

        //Create the stateless knowledge session outside the for loop
        StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();


        //Loop through executing the rules with the same data 3 times
        for (int x = 0; x < 3; x++)
        {
                //Create a new instance of the input fact
                FactType inputDataType = kbase.getFactType("SimpleRuleflowTest",  "Input");
                Object inputData = inputDataType.newInstance();
                inputDataType.set(inputData, "Name", "Test data");

                //Create a new instance of the command list
                List cmds = new ArrayList();        
                cmds.add( CommandFactory.newInsert( inputData ));
                cmds.add( CommandFactory.newStartProcess( "TestRuleflow"));
                cmds.add( CommandFactory.newFireAllRules("rules"));
                cmds.add( CommandFactory.newGetObjects("output"));                                

                //Execute the rules
                ExecutionResults results = ksession.execute( CommandFactory.newBatchExecution( cmds ) );

                //Get the number of rules that ran
                Object rules = results.getValue("rules");
                System.out.println("Rules that ran:  " + rules.toString());
        }



Each iteration through the loop should fire 3 rules.  Running the code above you should get the following output:

       Rules that ran:  3
       Rules that ran:  1
       Rules that ran:  1
                     

I spent several hours researching the drools source code and I believe I have found the problem.  What I have found is related to Issue 2718.  
Check out the change made for this issue:  2718 fix.  

Below is a snippet from the code that was modified for issue 2718.  The “if (!initialized)” block was added.  The code loops through event listeners on the wm object and adds them to the stateless session’s listeners.  This works fine for the first rule execution.  But the next rule execution creates a new instance for wm.  Therefore it also creates new instances of listeners for wm.  So we have a new instance of wm and the stateless session is pointing to the old listeners from the first instance of wm.  I believe that is why it only runs correctly one time. It seems that that the “if (!initialized)” block of code needs to execute every time newWorkingMemory() is called.  

        public StatefulKnowledgeSession newWorkingMemory() {
                :
                :
                ReteooWorkingMemory wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
                                                                                                                  this.ruleBase,
                                                                                                                  (SessionConfiguration) this.conf,
                                                                                                                  this.environment );
                :
                :
                if (!initialized) {
                        // copy over the default generated listeners that are used for internal stuff once
                        for (org.drools.event.AgendaEventListener listener: wm.getAgendaEventSupport().getEventListeners()) {
                                this.agendaEventSupport.addEventListener(listener);
                        }
                        for (org.drools.event.WorkingMemoryEventListener listener: wm.getWorkingMemoryEventSupport().getEventListeners()) {
                                this.workingMemoryEventSupport.addEventListener(listener);
                        }
                        InternalProcessRuntime processRuntime = wm.getProcessRuntime();
                        if (processRuntime != null) {
                                for (ProcessEventListener listener: processRuntime.getProcessEventListeners()) {
                                        this.processEventSupport.addEventListener(listener);
                                }
                        }
                        initialized = true;
                }
                :
                :
        }
                     

So, I tested this theory in my test function.  I used reflection to flip the “initialized” flag at the bottom of my loop.  I did this to force the listeners of the stateless session to be refreshed for every execute call.  It worked!  The other nodes in the ruleflow now get executed after the first rule execution.  Below is a snippet of my modified test code:
             

       //Same As Above
       :
       :
       //Create the stateless knowledge session outside the for loop
       StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();

       //Loop through executing the rules with the same data 3 times
       for (int x = 0; x < 3; x++)
       {
              :
              :
              //Flip the initialized flag to false through reflection
              Field field = StatelessKnowledgeSessionImpl.class.getDeclaredField("initialized");
              field.setAccessible(true);
              field.setBoolean(ksession, false);

       }
                     

Running the code above you should get the following output:

       Rules that ran:  3
       Rules that ran:  3
       Rules that ran:  3

My original problem deals with drools-server.  It isn’t possible for me to flip the initialized flag to false in that scenario.  So, is there any sort of workaround that would get me past this issue when using drools-server?
Reply | Threaded
Open this post in threaded view
|

Re: Ruleflow not working with stateless session in drools-server 5.5.0.Final

tslonaker
I am new to Drools and I am struggling with this ruleflow issue.  Please let me know if I have been posting this info to the wrong message board.  

My situation is that I am working on converting our application from using an expensive commercial rule engine to Drools.  Our rule engine implementation uses a stateless server and it heavily depends on ruleflows.  We could develop the rules using salience but that isn't ideal.

It seems to me that there is still a bug in drools-server when using ruleflows in a stateless session.  It seems that the fix for issue 2718 partially fixed the problem.  There is an easy workaround if you are coding your solution in Java.  You just create a new instance of the Stateless session every time.  But in drools-server I don’t have any control over that.

tslonaker wrote
I found a much easier way to recreate the problem described in my previous post.  I believe I have also found the root cause of the problem.  Below are the steps to recreate the issue:

- Create a simple ruleflow and rules and compile them into a rule package.
- In code create a stateless session
- In a loop
    o Create a fact
    o Create a new execution batch with the following commands
        - Insert the fact from above
        - Start Process
        - Fire All Rules
        - Get Objects
    o Execute the batch
    o Check the results (number of rules that ran)

I posted before that the problem didn’t happen while executing locally (not in drools server).  I didn’t realize this before, but adding a loop that executes the rules multiple times with the same session recreates the problem.  

Below is code that will recreate the issue.  Notice that the code below creates one instance of ksession and reuses it in the loop.  

        //Setup
        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        //The package includes the ruleflow
        kbuilder.add( ResourceFactory.newFileResource( ("YourRulePackage_WithRuleflow.pkg") ), ResourceType.PKG );
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

        //Create the stateless knowledge session outside the for loop
        StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();


        //Loop through executing the rules with the same data 3 times
        for (int x = 0; x < 3; x++)
        {
                //Create a new instance of the input fact
                FactType inputDataType = kbase.getFactType("SimpleRuleflowTest",  "Input");
                Object inputData = inputDataType.newInstance();
                inputDataType.set(inputData, "Name", "Test data");

                //Create a new instance of the command list
                List cmds = new ArrayList();        
                cmds.add( CommandFactory.newInsert( inputData ));
                cmds.add( CommandFactory.newStartProcess( "TestRuleflow"));
                cmds.add( CommandFactory.newFireAllRules("rules"));
                cmds.add( CommandFactory.newGetObjects("output"));                                

                //Execute the rules
                ExecutionResults results = ksession.execute( CommandFactory.newBatchExecution( cmds ) );

                //Get the number of rules that ran
                Object rules = results.getValue("rules");
                System.out.println("Rules that ran:  " + rules.toString());
        }



Each iteration through the loop should fire 3 rules.  Running the code above you should get the following output:

       Rules that ran:  3
       Rules that ran:  1
       Rules that ran:  1
                     

I spent several hours researching the drools source code and I believe I have found the problem.  What I have found is related to Issue 2718.  
Check out the change made for this issue:  2718 fix.  

Below is a snippet from the code that was modified for issue 2718.  The “if (!initialized)” block was added.  The code loops through event listeners on the wm object and adds them to the stateless session’s listeners.  This works fine for the first rule execution.  But the next rule execution creates a new instance for wm.  Therefore it also creates new instances of listeners for wm.  So we have a new instance of wm and the stateless session is pointing to the old listeners from the first instance of wm.  I believe that is why it only runs correctly one time. It seems that that the “if (!initialized)” block of code needs to execute every time newWorkingMemory() is called.  

        public StatefulKnowledgeSession newWorkingMemory() {
                :
                :
                ReteooWorkingMemory wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
                                                                                                                  this.ruleBase,
                                                                                                                  (SessionConfiguration) this.conf,
                                                                                                                  this.environment );
                :
                :
                if (!initialized) {
                        // copy over the default generated listeners that are used for internal stuff once
                        for (org.drools.event.AgendaEventListener listener: wm.getAgendaEventSupport().getEventListeners()) {
                                this.agendaEventSupport.addEventListener(listener);
                        }
                        for (org.drools.event.WorkingMemoryEventListener listener: wm.getWorkingMemoryEventSupport().getEventListeners()) {
                                this.workingMemoryEventSupport.addEventListener(listener);
                        }
                        InternalProcessRuntime processRuntime = wm.getProcessRuntime();
                        if (processRuntime != null) {
                                for (ProcessEventListener listener: processRuntime.getProcessEventListeners()) {
                                        this.processEventSupport.addEventListener(listener);
                                }
                        }
                        initialized = true;
                }
                :
                :
        }
                     

So, I tested this theory in my test function.  I used reflection to flip the “initialized” flag at the bottom of my loop.  I did this to force the listeners of the stateless session to be refreshed for every execute call.  It worked!  The other nodes in the ruleflow now get executed after the first rule execution.  Below is a snippet of my modified test code:
             

       //Same As Above
       :
       :
       //Create the stateless knowledge session outside the for loop
       StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();

       //Loop through executing the rules with the same data 3 times
       for (int x = 0; x < 3; x++)
       {
              :
              :
              //Flip the initialized flag to false through reflection
              Field field = StatelessKnowledgeSessionImpl.class.getDeclaredField("initialized");
              field.setAccessible(true);
              field.setBoolean(ksession, false);

       }
                     

Running the code above you should get the following output:

       Rules that ran:  3
       Rules that ran:  3
       Rules that ran:  3

My original problem deals with drools-server.  It isn’t possible for me to flip the initialized flag to false in that scenario.  So, is there any sort of workaround that would get me past this issue when using drools-server?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Ruleflow not working with stateless session in drools-server 5.5.0.Final

nashyura
Hi Tim,
I know that you posted these through nabble, and it's not necessarily propagating your message to the community.  I have gotten a good response by registering for the mailing list and sending messages directly to Rules Users List <[hidden email]>.  
I am replying to your message through the rules-users mailing list - this way everyone on the list will definitely see your post.


On Fri, Feb 8, 2013 at 9:08 AM, tslonaker <[hidden email]> wrote:
I am new to Drools and I am struggling with this ruleflow issue.  Please let
me know if I have been posting this info to the wrong message board.

My situation is that I am working on converting our application from using
an expensive commercial rule engine to Drools.  Our rule engine
implementation uses a stateless server and it heavily depends on ruleflows.
We could develop the rules using salience but that isn't ideal.

It seems to me that there is still a bug in drools-server when using
ruleflows in a stateless session.  It seems that the fix for  issue 2718
<https://issues.jboss.org/browse/JBRULES-2718>   partially fixed the
problem.  There is an easy workaround if you are coding your solution in
Java.  You just create a new instance of the Stateless session every time.
But in drools-server I don’t have any control over that.


tslonaker wrote
> I found a much easier way to recreate the problem described in my previous
> post.  I believe I have also found the root cause of the problem.  Below
> are the steps to recreate the issue:
>
> - Create a simple ruleflow and rules and compile them into a rule package.
> - In code create a stateless session
> - In a loop
>     o Create a fact
>     o Create a new execution batch with the following commands
>         - Insert the fact from above
>         - Start Process
>         - Fire All Rules
>         - Get Objects
>     o Execute the batch
>     o Check the results (number of rules that ran)
>
> I posted before that the problem didn’t happen while executing locally
> (not in drools server).  I didn’t realize this before, but adding a loop
> that executes the rules multiple times with the same session recreates the
> problem.
>
> Below is code that will recreate the issue.  Notice that the code below
> creates one instance of ksession and reuses it in the loop.
>
>       //Setup
>       KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>
>       //The package includes the ruleflow
>       kbuilder.add( ResourceFactory.newFileResource(
> ("YourRulePackage_WithRuleflow.pkg") ), ResourceType.PKG );
>       KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
>       kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
*
>       //Create the stateless knowledge session outside the for loop
>       StatelessKnowledgeSession ksession =
> kbase.newStatelessKnowledgeSession();
*
>
>       //Loop through executing the rules with the same data 3 times
>       for (int x = 0; x < 3; x++)
>       {
>               //Create a new instance of the input fact
>               FactType inputDataType = kbase.getFactType("SimpleRuleflowTest",
> "Input");
>               Object inputData = inputDataType.newInstance();
>               inputDataType.set(inputData, "Name", "Test data");
>
>               //Create a new instance of the command list
>               List cmds = new ArrayList();
>               cmds.add( CommandFactory.newInsert( inputData ));
>               cmds.add( CommandFactory.newStartProcess( "TestRuleflow"));
>               cmds.add( CommandFactory.newFireAllRules("rules"));
>               cmds.add( CommandFactory.newGetObjects("output"));
>
>               //Execute the rules
>               ExecutionResults results = ksession.execute(
> CommandFactory.newBatchExecution( cmds ) );
>
>               //Get the number of rules that ran
>               Object rules = results.getValue("rules");
>               System.out.println("Rules that ran:  " + rules.toString());
>       }
>
>
>
> Each iteration through the loop should fire 3 rules.  Running the code
> above you should get the following output:
>
>        Rules that ran:  3
>        Rules that ran:  1
>        Rules that ran:  1
>
>
> I spent several hours researching the drools source code and I believe I
> have found the problem.  What I have found is related to
> Issue 2718 <https://issues.jboss.org/browse/JBRULES-2718>
> .
> Check out the change made for this issue:
> 2718 fix
> <https://source.jboss.org/viewrep/Drools/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java?r1=63021da325036ec6fbdf4019e8c8293db21555ec&r2=fad9b951f44ac813e5faf50f097335c2a97007ae>
> .
>
> Below is a snippet from the code that was modified for issue 2718.  The
> “if (!initialized)” block was added.  The code loops through event
> listeners on the wm object and adds them to the stateless session’s
> listeners.  This works fine for the first rule execution.  But the next
> rule execution creates a new instance for wm.  Therefore it also creates
> new instances of listeners for wm.  So we have a new instance of wm and
> the stateless session is pointing to the old listeners from the first
> instance of wm.  I believe that is why it only runs correctly one time. It
> seems that that the “if (!initialized)” block of code needs to execute
> every time newWorkingMemory() is called.
>
>       public StatefulKnowledgeSession newWorkingMemory() {
>               :
>               :
>               ReteooWorkingMemory wm = new ReteooWorkingMemory(
> this.ruleBase.nextWorkingMemoryCounter(),
>                                                                                                                 this.ruleBase,
>                                                                                                                 (SessionConfiguration) this.conf,
>                                                                                                                 this.environment );
>               :
>               :
>
*
> if (!initialized) {
*
>                       // copy over the default generated listeners that are used for internal
> stuff once
>                       for (org.drools.event.AgendaEventListener listener:
> wm.getAgendaEventSupport().getEventListeners()) {
>                               this.agendaEventSupport.addEventListener(listener);
>                       }
>                       for (org.drools.event.WorkingMemoryEventListener listener:
> wm.getWorkingMemoryEventSupport().getEventListeners()) {
>                               this.workingMemoryEventSupport.addEventListener(listener);
>                       }
>                       InternalProcessRuntime processRuntime = wm.getProcessRuntime();
>                       if (processRuntime != null) {
>                               for (ProcessEventListener listener:
> processRuntime.getProcessEventListeners()) {
>                                       this.processEventSupport.addEventListener(listener);
>                               }
>                       }
>                       initialized = true;
>               }
>               :
>               :
>       }
>
>
> So, I tested this theory in my test function.  I used reflection to flip
> the “initialized” flag at the bottom of my loop.  I did this to force the
> listeners of the stateless session to be refreshed for every execute call.
> It worked!  The other nodes in the ruleflow now get executed after the
> first rule execution.  Below is a snippet of my modified test code:
>
>
>        //Same As Above
>        :
>        :
>        //Create the stateless knowledge session outside the for loop
>        StatelessKnowledgeSession ksession =
> kbase.newStatelessKnowledgeSession();
>
>        //Loop through executing the rules with the same data 3 times
>        for (int x = 0; x < 3; x++)
>        {
>               :
>               :
>               //Flip the initialized flag to false through reflection
*
>               Field field =
> StatelessKnowledgeSessionImpl.class.getDeclaredField("initialized");
>               field.setAccessible(true);
>               field.setBoolean(ksession, false);
*
>        }
>
>
> Running the code above you should get the following output:
>
>        Rules that ran:  3
>        Rules that ran:  3
>        Rules that ran:  3
>
> My original problem deals with drools-server.  It isn’t possible for me to
> flip the initialized flag to false in that scenario.  So, is there any
> sort of workaround that would get me past this issue when using
> drools-server?





--
View this message in context: http://drools.46999.n3.nabble.com/Ruleflow-not-working-with-stateless-session-in-drools-server-5-5-0-Final-tp4021624p4022161.html
Sent from the Drools: User forum mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Ruleflow not working with stateless session in drools-server 5.5.0.Final

srikanthmalli
I am having the same issue with rule flow, how did you solve the issue?

Thanks,
Sri