[rules-users] Drools Flow Persistence throws stack overflow error

PremKumar s premkumar.sivanandan at gmail.com
Fri Oct 9 00:36:50 EDT 2009


Kris,

    I am new to drools flow am not aware of other better ways to pass
ProcessInstance to drools rule (DRL)  When conditions.  Based on few
examples in the forum and sample testing code with out inserting
processInstance to working memory rule constraints not able get to process
instance in drools rule drl file.

     If would be great if could  suggest better approach to pass the process
instance to drools rule (DRL) conditions. I with try that out and update
you.

Thanks
Prem

On Fri, Oct 9, 2009 at 7:12 AM, Kris Verlaenen <
kris.verlaenen at cs.kuleuven.be> wrote:

> You can register a custom strategy like this:
>
> Environment env = KnowledgeBaseFactory.newEnvironment();
> env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
> env.set(EnvironmentName.TRANSACTION_MANAGER,
> TransactionManagerServices.getTransactionManager());
> ObjectMarshallingStrategy[] objectMarshalingStrategies = new
> ObjectMarshallingStrategy[] {
>  new ProcessInstanceMarshallingStrategy(env)
> };
> env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,
> objectMarshalingStrategies);
> StatefulKnowledgeSession ksession =
> JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
>
> ... and then define the strategy as ...
>
> private static class ProcessInstanceMarshallingStrategy implements
> ObjectMarshallingStrategy {
>  private Environment environment;
>  public ProcessInstanceMarshallingStrategy(Environment environment) {
>    this.environment = environment;
>  }
>  public boolean accept(Object o) {
>    return o instanceof ProcessInstance;
>  }
>  public Object read(ObjectInputStream ois) throws IOException,
> ClassNotFoundException {
>    long id = ois.readLong();
>    return ((ProcessRuntime)
> environment.get("ksession")).getProcessInstance(id);
>  }
>  public void write(ObjectOutputStream oos, Object o) throws IOException {
>    oos.writeLong(((ProcessInstance) o).getId());
>  }
> }
>
> Note that this strategy only works for active process instances (so you
> need to make sure they are removed from the working memory before ending
> the process instance, for example by using an on-entry/exit action.  I
> think we will probably build in this strategy by default in the future.
>
> Could you clarify why you need the processInstance in the working
> memory?  As there might be an easier alternative?
>
> Kris
>
>
> Quoting PremKumar s <premkumar.sivanandan at gmail.com>:
>
> > Thanks Kris for your input. It would be great if you could share us
> > on
> > sample code snippet how to acheive this ObjectMarshallingStrategy
> > for
> > ProcessInstances .
> >
> > Also confirm us by using this approach the process is avialable for
> > drools
> > rule constraints to take decisions.
> >
> > Thanks
> > Prem
> >
> > On Thu, Oct 8, 2009 at 4:07 PM, Kris Verlaenen <
> > kris.verlaenen at cs.kuleuven.be> wrote:
> >
> > > This is indeed a special case.  Process instances are already
> > stored as
> > > part of the session runtime state, so no need to store them again
> > as
> > > part of the working memory.  You need to register a custom
> > > ObjectMarshallingStrategy for ProcessInstances in the working
> > memory
> > > that simply retrieves them from the session state.
> > >
> > > Kris
> > >
> > > Quoting PremKumar s <premkumar.sivanandan at gmail.com>:
> > >
> > > > Hi,
> > > >
> > > >
> > > >
> > > >       I am evaluating the drools expert with drool flow using
> > > > TimeManagement
> > > > System. I am inserting the process instance into working memory
> > of
> > > > drools
> > > > [session.insert(workflowProcessInstance)]  So that the rules can
> > use
> > > > the
> > > > process instance as part of Rule constraints to enable the rules
> > to
> > > > make
> > > > more sophisticated decisions based on the state of the current
> > > > process
> > > > instance.
> > > >
> > > >
> > > >
> > > > Rule snippet
> > > >
> > > >
> > > >
> > > > rule "Submit Time"  ruleflow-group "Submit Time"
> > > >        dialect "java"
> > > >        when
> > > >
> > > >                processInstance:WorkflowProcessInstance()
> > > >
> > > >                tkRequest:TKRequest ()
> > > >                tkRequestDAO:TKRequestDAO()
> > > >        then
> > > >
> > > >                     // check the current processInstance state
> > as
> > > > Active
> > > > then do that
> > > >
> > > >                        //Do custom operation, status change,
> > > > persistence
> > > > update
> > > >
> > > >        end
> > > >
> > > >
> > > >
> > > >        The approach is works fine with using
> > > > KnowledgeBuilder.newStatefulKnowledgeSession() that is no
> > > > persistence.  But
> > > > once i have enabled the Persistence using
> > > > JPAKnowledgeService.newStatefulKnowledgeSession(know, null,
> > > > getEnvironment())  it throws stack over flow error due the
> > > > workflowProcessInstance is not serialized while trying to persist
> > the
> > > > newly
> > > > added workflowProcessInstance  to working memory.
> > > >
> > > >
> > > >
> > > >            Once i have commented the
> > > > session.insert(workflowProcessInstance)
> > > > the stack overflow error is gone but none of my rules are not
> > > > executed.
> > > >
> > > >
> > > >
> > > > Can some one provide guidance on how to pass this
> > > > workflowProcessInstance to
> > > > rule constriant with persistence JPAKnowledgeSession enabled.
> > > >
> > > >
> > > >
> > > > Thanks
> > > >
> > > > Prem
> > > >
> > >
> > >
> > >
> > >
> > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
> > >
> >
>
>
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091009/bb0db4ba/attachment.html 


More information about the rules-users mailing list