[rules-users] KnowledgeAgent and Pipeline

David Zeigler dzeigler at gmail.com
Tue May 12 18:31:21 EDT 2009


Hi Mark,
Thanks for the quick reply.

Now I'm getting a NullPointerException when I insert the message into
the pipeline using 5.0.1.SNAPSHOT from today:
java.lang.NullPointerException
	at org.drools.runtime.pipeline.impl.StatelessKnowledgeSessionPipelineImpl.insert(StatelessKnowledgeSessionPipelineImpl.java:24)

It looks like StatelessKnowledgeSession's ruleBase is null when
created by the KnowledgeAgent, which poses a problem since
StatelessKnowledgeSessionPipelineImpl invokes getRootClassLoader() on
the session's ruleBase.

Here's what I'm doing:
StatelessKnowledgeSession ksession = kagent.newStatelessKnowledgeSession();
Pipeline pipeline =
PipelineFactory.newStatelessKnowledgeSessionPipeline(ksession);
pipeline.setReceiver(messageTransformer);
pipeline.insert(message);  // NPE here

Thanks,
David

2009/5/12 Mark Proctor <mproctor at codehaus.org>:
> David Zeigler wrote:
>
> Hi,
> I've set up the KnowledgeAgent to automatically reload the rules
> resources if they change.  If I use this with a Pipeline, it seems
> that its StatelessKnowledgeSession is not reloaded automatically.  The
> only way I've been able to get the Pipeline to reflect the rules
> change is to do the following prior to each pipeline.insert():
>
> StatelessKnowledgeSession ksession =
> kagent.getKnowledgeBase().newStatelessKnowledgeSession();
> Pipeline pipeline =
> PipelineFactory.newStatelessKnowledgeSessionPipeline(ksession);
> pipeline.setReceiver( messageTransformer );
>
> Reloading the pipeline for each request adds a lot of overhead (halves
> my transactions per second).  Is there a way to automatically reload
> the Pipeline's session when its needed instead of recreating the
> Pipeline prior to each insert?  I see there is a
> ResourceChangeListener interface that I could probably use to
> accomplish this, but I figured I'd ask in case there is a better way
> to handle this case with pipelines.  What's the best approach?
>
>
> Try trunk, it has a fix for this. Where if you get the
> StatelessKnowledgeSession directly from the knowledgeagent every execute
> will check for a new KnowledgeBase.
> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/
>
> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/javadocs/stable/drools-api/org/drools/agent/KnowledgeAgent.html
> KnowledgeAgent.newStatelessKnowledgeSession(KnowledgeSessionConfiguration conf)
>  StatelessKnowledgeSession created from here will always have the execute()
> method called against the latest built KnowledgeBase.
>
> So now you can just use that returned session with the pipeline and it
> should always be using the latest rules.
>
> Mark
>
> I'm using 5.0.0.CR1.
>
> Thanks!
> David
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>




More information about the rules-users mailing list