You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ode.apache.org by Ju...@empolis.com on 2009/04/14 15:14:50 UTC

Concurrent execution of extension activities (RE: Problem with flow and extension activities)

Hi Tammo,

> -----Original Message-----
> From: Tammo van Lessen [mailto:tvanlessen@gmail.com]
> Sent: Thursday, April 02, 2009 4:17 PM
> Subject: Re: AW: Problem with flow and extension activities
>
> That's true. If you need a concurrent execution of extension activities
> you'd need to implement the abstract class for async extensions, fork
> your own thread and call the ExtensionContext.complete method once your
> processing has finished. In this case the run method can finish before
> the processing is done and the navigation continues.

I tried this with ODE 2.0 beta2 and put the complete code of my extension activity 
execution in a Runnable to be executed in an own thread, but it doesn't work yet.
The code is basically like this:

class MyExtensionActivity extends AbstractAsyncExtensionOperation {

  static java.util.concurrent.Executor executor = Executors.newCachedThreadPool();

  void run(...) {
    executor.execute(new Runnable() {
      public void run() {
	  // extension activity code: 
        // read variables from ext context
        // do something
	  // write variables to ext context
	  // complete ext context
      }
    }
  }
}

For in-memory=true there is an exception when I try to complete the ExtensionContext:

java.lang.NullPointerException
	at org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
	at org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
	at $Proxy42.completed(Unknown Source)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.complete(ExtensionContextImpl.java:147)

So the actual execution of the extension code has worked in this case.

For in-memory=false I get an exception when trying to read a variable in my separate thread:
 
java.lang.NullPointerException
	at org.apache.ode.dao.jpa.ProcessInstanceDAOImpl.getScope(ProcessInstanceDAOImpl.java:231)
	at org.apache.ode.bpel.engine.BpelRuntimeContextImpl.fetchVariableData(BpelRuntimeContextImpl.java:354)
	at org.apache.ode.bpel.rtrep.v2.RuntimeInstanceImpl.fetchVariableData(RuntimeInstanceImpl.java:155)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:90)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:108)

which means that the DAO impl cannot find it's associated JPA entity manager anymore. 
So it seems I cannot access the variables in the extension context in this case. 

And then there's another exception on completeWithFault() that looks similar to the above:

Exception in thread "pool-2-thread-3" java.lang.NullPointerException
	at org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
	at org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
	at $Proxy40.completed(Unknown Source)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.completeWithFault(ExtensionContextImpl.java:162)

It doesn't matter if my extension activities are actually called from within a <flow> or not. 
It also didn't change anything to let my extension implementation extend AbstractAsyncExtensionOperation 
instead of just implementing ExtensionOperation (I also did not find anything in the ODE code, where they 
are treated differently). Or have there been changes since 2.0-beta2 that make this work? 

Or is there just something I am missing or that I have misunderstood? (-; 

Thanks for your patience, 
Juergen.


Re: Concurrent execution of extension activities

Posted by Matthieu Riou <ma...@gmail.com>.
On Mon, Apr 27, 2009 at 12:51 PM, Tammo van Lessen <tv...@gmail.com>wrote:

> Matthieu Riou wrote:
> > You can't start a thread that will do something at the Jacob level. When
> you
> > think of it, the main purpose of Jacob is to avoid multi-threading by
> using
> > a cooperative and lightweight threading model. The way you do parrallel
> > stuff in Jacob is by injecting more threads.
> >
> > So I guess the question becomes: what do you need a thread for in your
> > extension?
>
> For non-blocking extension activities. AFAIK a new thread is the only
> way to run the extension code independently from the jacob loop.
> Long-running code in JacobRunnable.run() would block the whole
> navigation. Instead, this code can run in a different thread and mark
> the activity completed once its finished. That's at least what I had in
> mind. So I guess we'd need to find a way to synchronize both threads?
>
> Would there be a more elegant way to generically allow for custom
> long-running code?
>

I think so yes. We should probably have a specific channel for extension
activities that extension runnables could listen to (accepting any
Serialzable for example). Then external code could fire the channel when the
async processing is done. It'd look very much like what we're doing for all
BPEL activities right now and would probably be easier than greenspuning
Java multi-threading in Jacob.

Makes sense?

Cheers,
Matthieu


>
> Cheers,
>   Tammo
>
> --
> Tammo van Lessen - http://www.taval.de
>

Re: Concurrent execution of extension activities

Posted by Tammo van Lessen <tv...@gmail.com>.
Matthieu Riou wrote:
> You can't start a thread that will do something at the Jacob level. When you
> think of it, the main purpose of Jacob is to avoid multi-threading by using
> a cooperative and lightweight threading model. The way you do parrallel
> stuff in Jacob is by injecting more threads.
> 
> So I guess the question becomes: what do you need a thread for in your
> extension?

For non-blocking extension activities. AFAIK a new thread is the only
way to run the extension code independently from the jacob loop.
Long-running code in JacobRunnable.run() would block the whole
navigation. Instead, this code can run in a different thread and mark
the activity completed once its finished. That's at least what I had in
mind. So I guess we'd need to find a way to synchronize both threads?

Would there be a more elegant way to generically allow for custom
long-running code?

Cheers,
  Tammo

-- 
Tammo van Lessen - http://www.taval.de

Re: Concurrent execution of extension activities

Posted by Matthieu Riou <ma...@gmail.com>.
On Mon, Apr 27, 2009 at 7:03 AM, <Ju...@empolis.com> wrote:

> Hi,
>
> I posted message below some time ago, but there was no response (or did I
> miss it?
> I didn't find anything in the archives, either).
>
> Any idea about it? Tammo?
>
> Thanks in advance for any hint you can give me.
>
> Regards,
> Juergen.
>
>
> -----Original Message-----
> From: Juergen.Schumacher@empolis.com [mailto:
> Juergen.Schumacher@empolis.com]
> Sent: Tuesday, April 14, 2009 3:15 PM
> To: dev@ode.apache.org
> Subject: Concurrent execution of extension activities (RE: Problem with
> flow and extension activities)
>
> Hi Tammo,
>
> > -----Original Message-----
> > From: Tammo van Lessen [mailto:tvanlessen@gmail.com]
> > Sent: Thursday, April 02, 2009 4:17 PM
> > Subject: Re: AW: Problem with flow and extension activities
> >
> > That's true. If you need a concurrent execution of extension activities
> > you'd need to implement the abstract class for async extensions, fork
> > your own thread and call the ExtensionContext.complete method once your
> > processing has finished. In this case the run method can finish before
> > the processing is done and the navigation continues.
>
> I tried this with ODE 2.0 beta2 and put the complete code of my extension
> activity
> execution in a Runnable to be executed in an own thread, but it doesn't
> work yet.
> The code is basically like this:
>
> class MyExtensionActivity extends AbstractAsyncExtensionOperation {
>
>  static java.util.concurrent.Executor executor =
> Executors.newCachedThreadPool();
>
>  void run(...) {
>    executor.execute(new Runnable() {
>      public void run() {
>          // extension activity code:
>        // read variables from ext context
>        // do something
>          // write variables to ext context
>          // complete ext context
>      }
>    }
>  }
> }
>
> For in-memory=true there is an exception when I try to complete the
> ExtensionContext:
>
> java.lang.NullPointerException
>        at
> org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
>        at
> org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
>        at $Proxy42.completed(Unknown Source)
>        at
> org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.complete(ExtensionContextImpl.java:147)
>
> So the actual execution of the extension code has worked in this case.
>
> For in-memory=false I get an exception when trying to read a variable in my
> separate thread:
>
> java.lang.NullPointerException
>        at
> org.apache.ode.dao.jpa.ProcessInstanceDAOImpl.getScope(ProcessInstanceDAOImpl.java:231)
>        at
> org.apache.ode.bpel.engine.BpelRuntimeContextImpl.fetchVariableData(BpelRuntimeContextImpl.java:354)
>        at
> org.apache.ode.bpel.rtrep.v2.RuntimeInstanceImpl.fetchVariableData(RuntimeInstanceImpl.java:155)
>        at
> org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:90)
>        at
> org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:108)
>
> which means that the DAO impl cannot find it's associated JPA entity
> manager anymore.
> So it seems I cannot access the variables in the extension context in this
> case.
>
> And then there's another exception on completeWithFault() that looks
> similar to the above:
>
> Exception in thread "pool-2-thread-3" java.lang.NullPointerException
>        at
> org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
>        at
> org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
>        at $Proxy40.completed(Unknown Source)
>        at
> org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.completeWithFault(ExtensionContextImpl.java:162)
>
> It doesn't matter if my extension activities are actually called from
> within a <flow> or not.
> It also didn't change anything to let my extension implementation extend
> AbstractAsyncExtensionOperation
> instead of just implementing ExtensionOperation (I also did not find
> anything in the ODE code, where they
> are treated differently). Or have there been changes since 2.0-beta2 that
> make this work?
>
> Or is there just something I am missing or that I have misunderstood? (-;
>

You can't start a thread that will do something at the Jacob level. When you
think of it, the main purpose of Jacob is to avoid multi-threading by using
a cooperative and lightweight threading model. The way you do parrallel
stuff in Jacob is by injecting more threads.

So I guess the question becomes: what do you need a thread for in your
extension?

Matthieu


> Thanks for your patience,
> Juergen.
>
>

Re: Concurrent execution of extension activities

Posted by Tammo van Lessen <tv...@gmail.com>.
Hi Jürgen,

I have noticed your mail but I was quite busy last weeks. Also this week
is very tough, so I hope to find some time for a deep dive afterwards.

But perhaps the other devs have some idea about what's causing that NPE.

Best,
  Tammo

Juergen.Schumacher@empolis.com wrote:
> Hi,
> 
> I posted message below some time ago, but there was no response (or did I miss it? 
> I didn't find anything in the archives, either). 
> 
> Any idea about it? Tammo? 
> 
> Thanks in advance for any hint you can give me.
> 
> Regards,
> Juergen.
> 
> 
> -----Original Message-----
> From: Juergen.Schumacher@empolis.com [mailto:Juergen.Schumacher@empolis.com] 
> Sent: Tuesday, April 14, 2009 3:15 PM
> To: dev@ode.apache.org
> Subject: Concurrent execution of extension activities (RE: Problem with flow and extension activities)
> 
> Hi Tammo,
> 
>> -----Original Message-----
>> From: Tammo van Lessen [mailto:tvanlessen@gmail.com]
>> Sent: Thursday, April 02, 2009 4:17 PM
>> Subject: Re: AW: Problem with flow and extension activities
>>
>> That's true. If you need a concurrent execution of extension activities
>> you'd need to implement the abstract class for async extensions, fork
>> your own thread and call the ExtensionContext.complete method once your
>> processing has finished. In this case the run method can finish before
>> the processing is done and the navigation continues.
> 
> I tried this with ODE 2.0 beta2 and put the complete code of my extension activity 
> execution in a Runnable to be executed in an own thread, but it doesn't work yet.
> The code is basically like this:
> 
> class MyExtensionActivity extends AbstractAsyncExtensionOperation {
> 
>   static java.util.concurrent.Executor executor = Executors.newCachedThreadPool();
> 
>   void run(...) {
>     executor.execute(new Runnable() {
>       public void run() {
> 	  // extension activity code: 
>         // read variables from ext context
>         // do something
> 	  // write variables to ext context
> 	  // complete ext context
>       }
>     }
>   }
> }
> 
> For in-memory=true there is an exception when I try to complete the ExtensionContext:
> 
> java.lang.NullPointerException
> 	at org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
> 	at org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
> 	at $Proxy42.completed(Unknown Source)
> 	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.complete(ExtensionContextImpl.java:147)
> 
> So the actual execution of the extension code has worked in this case.
> 
> For in-memory=false I get an exception when trying to read a variable in my separate thread:
>  
> java.lang.NullPointerException
> 	at org.apache.ode.dao.jpa.ProcessInstanceDAOImpl.getScope(ProcessInstanceDAOImpl.java:231)
> 	at org.apache.ode.bpel.engine.BpelRuntimeContextImpl.fetchVariableData(BpelRuntimeContextImpl.java:354)
> 	at org.apache.ode.bpel.rtrep.v2.RuntimeInstanceImpl.fetchVariableData(RuntimeInstanceImpl.java:155)
> 	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:90)
> 	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:108)
> 
> which means that the DAO impl cannot find it's associated JPA entity manager anymore. 
> So it seems I cannot access the variables in the extension context in this case. 
> 
> And then there's another exception on completeWithFault() that looks similar to the above:
> 
> Exception in thread "pool-2-thread-3" java.lang.NullPointerException
> 	at org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
> 	at org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
> 	at $Proxy40.completed(Unknown Source)
> 	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.completeWithFault(ExtensionContextImpl.java:162)
> 
> It doesn't matter if my extension activities are actually called from within a <flow> or not. 
> It also didn't change anything to let my extension implementation extend AbstractAsyncExtensionOperation 
> instead of just implementing ExtensionOperation (I also did not find anything in the ODE code, where they 
> are treated differently). Or have there been changes since 2.0-beta2 that make this work? 
> 
> Or is there just something I am missing or that I have misunderstood? (-; 
> 
> Thanks for your patience, 
> Juergen.
> 


-- 
Tammo van Lessen - http://www.taval.de

RE: Concurrent execution of extension activities

Posted by Ju...@empolis.com.
Hi,

I posted message below some time ago, but there was no response (or did I miss it? 
I didn't find anything in the archives, either). 

Any idea about it? Tammo? 

Thanks in advance for any hint you can give me.

Regards,
Juergen.


-----Original Message-----
From: Juergen.Schumacher@empolis.com [mailto:Juergen.Schumacher@empolis.com] 
Sent: Tuesday, April 14, 2009 3:15 PM
To: dev@ode.apache.org
Subject: Concurrent execution of extension activities (RE: Problem with flow and extension activities)

Hi Tammo,

> -----Original Message-----
> From: Tammo van Lessen [mailto:tvanlessen@gmail.com]
> Sent: Thursday, April 02, 2009 4:17 PM
> Subject: Re: AW: Problem with flow and extension activities
>
> That's true. If you need a concurrent execution of extension activities
> you'd need to implement the abstract class for async extensions, fork
> your own thread and call the ExtensionContext.complete method once your
> processing has finished. In this case the run method can finish before
> the processing is done and the navigation continues.

I tried this with ODE 2.0 beta2 and put the complete code of my extension activity 
execution in a Runnable to be executed in an own thread, but it doesn't work yet.
The code is basically like this:

class MyExtensionActivity extends AbstractAsyncExtensionOperation {

  static java.util.concurrent.Executor executor = Executors.newCachedThreadPool();

  void run(...) {
    executor.execute(new Runnable() {
      public void run() {
	  // extension activity code: 
        // read variables from ext context
        // do something
	  // write variables to ext context
	  // complete ext context
      }
    }
  }
}

For in-memory=true there is an exception when I try to complete the ExtensionContext:

java.lang.NullPointerException
	at org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
	at org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
	at $Proxy42.completed(Unknown Source)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.complete(ExtensionContextImpl.java:147)

So the actual execution of the extension code has worked in this case.

For in-memory=false I get an exception when trying to read a variable in my separate thread:
 
java.lang.NullPointerException
	at org.apache.ode.dao.jpa.ProcessInstanceDAOImpl.getScope(ProcessInstanceDAOImpl.java:231)
	at org.apache.ode.bpel.engine.BpelRuntimeContextImpl.fetchVariableData(BpelRuntimeContextImpl.java:354)
	at org.apache.ode.bpel.rtrep.v2.RuntimeInstanceImpl.fetchVariableData(RuntimeInstanceImpl.java:155)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:90)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.readVariable(ExtensionContextImpl.java:108)

which means that the DAO impl cannot find it's associated JPA entity manager anymore. 
So it seems I cannot access the variables in the extension context in this case. 

And then there's another exception on completeWithFault() that looks similar to the above:

Exception in thread "pool-2-thread-3" java.lang.NullPointerException
	at org.apache.ode.jacob.vpu.JacobVPU.activeJacobThread(JacobVPU.java:203)
	at org.apache.ode.jacob.vpu.ChannelFactory$ChannelInvocationHandler.invoke(ChannelFactory.java:89)
	at $Proxy40.completed(Unknown Source)
	at org.apache.ode.bpel.rtrep.v2.ExtensionContextImpl.completeWithFault(ExtensionContextImpl.java:162)

It doesn't matter if my extension activities are actually called from within a <flow> or not. 
It also didn't change anything to let my extension implementation extend AbstractAsyncExtensionOperation 
instead of just implementing ExtensionOperation (I also did not find anything in the ODE code, where they 
are treated differently). Or have there been changes since 2.0-beta2 that make this work? 

Or is there just something I am missing or that I have misunderstood? (-; 

Thanks for your patience, 
Juergen.