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