Hello again,

After testing your process definition, I'm finding some difficulties
using $children, as it's a global variable shared by all process
instances.

Here's my adaptation to ruote-kit's StorageParticipant[1]

---8<---
class FillParticipant < Ruote::StorageParticipant
  def consume(workitem)
    $children ||= 0
    p "in for #{workitem.params['form']} - #{$children} children"
    workitem.fields['form'] = workitem.params['form']
    workitem.fields['launch'] = false

    super(workitem)
  end

  def proceed(workitem)
    if workitem.params['form'] == 'parent'
      $children = $children + 1 if workitem.fields['launch']
    elsif workitem.params['form'] == 'child'
      $children = $children - 1
    end

    super(workitem)
  end
end

--->8---

The idea behind my proof of concept is that several of these kind of
processes can co-exist without interfering one another. Which brings
me to another doubt: What would be the best way to share a common,
synchronized state between parent and children?

Unfortunately, stash_* depends too much on the parent's fei, which
changes after each children is added because of the "rewind". So I
think stash_* would be a complicated approach here.

Maybe a process variable could be set from the participant:

---8<---

class FillParticipant < Ruote::StorageParticipant
  def consume(workitem)
    children = fexp.lookup_variable('children')
    p "in for #{workitem.params['form']} - #{children} children"
    workitem.fields['form'] = workitem.params['form']
    workitem.fields['launch'] = false

    super(workitem)
  end

  def proceed(workitem)
    children = fexp.lookup_variable('children')
    if workitem.params['form'] == 'parent'
       fexp.set_variable('children', children + 1) if
workitem.fields['launch']
    elsif workitem.params['form'] == 'child'
       fexp.set_variable('children', children - 1)
    end

    super(workitem)
  end
end
--->8---

But I get the following error:

----- begin ----
NoMethodError - undefined method `fei' for nil:NilClass:
 /Users/nando/development/abstra/blueMountain/Workflow/ruote-
components/ruote/lib/ruote/part/local_participant.rb:77:in `fei'
 /Users/nando/development/abstra/blueMountain/Workflow/ruote-
components/ruote/lib/ruote/part/local_participant.rb:88:in `fexp'
 /Users/nando/development/abstra/blueMountain/Workflow/participants/
fill_participant.rb:127:in `proceed'
 /Users/nando/development/abstra/blueMountain/Workflow/ruote-
components/ruote-kit/lib/ruote-kit/resources/workitems.rb:116:in `PUT /
_ruote/workitems/:id'
 org/jruby/RubyProc.java:268:in `call'
 org/jruby/RubyMethod.java:121:in `call'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
1151:in `compile!'
 org/jruby/RubyKernel.java:2061:in `instance_eval'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
724:in `route_eval'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
708:in `route!'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
758:in `process_route'
 org/jruby/RubyKernel.java:1191:in `catch'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
755:in `process_route'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
707:in `route!'
 org/jruby/RubyArray.java:1603:in `each'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
706:in `route!'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
843:in `dispatch!'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
644:in `call!'
 org/jruby/RubyKernel.java:2061:in `instance_eval'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
808:in `invoke'
 org/jruby/RubyKernel.java:1191:in `catch'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
808:in `invoke'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
644:in `call!'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
629:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/
methodoverride.rb:24:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/static.rb:53:in
`call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/head.rb:9:in
`call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/commonlogger.rb:
20:in `call'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/
showexceptions.rb:21:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/
methodoverride.rb:24:in `call'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
1272:in `call'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
1303:in `synchronize'
 /Users/nando/.gem/jruby/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:
1272:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/auth/basic.rb:
25:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/
showexceptions.rb:24:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/lint.rb:48:in
`_call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/lint.rb:36:in
`call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/commonlogger.rb:
20:in `call'
 /Users/nando/development/abstra/blueMountain/Workflow/ruote-
components/ruote-kit/config.ru:102:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/lint.rb:48:in
`_call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/lint.rb:36:in
`call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/
showexceptions.rb:24:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/commonlogger.rb:
20:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/chunked.rb:41:in
`call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/
content_length.rb:14:in `call'
 /Users/nando/.gem/jruby/1.8/gems/rack-1.3.1/lib/rack/handler/
webrick.rb:59:in `service'
 file:/Users/nando/.m2/repository/org/jruby/jruby-complete/1.6.3/jruby-
complete-1.6.3.jar!/META-INF/jruby.home/lib/ruby/1.8/webrick/
httpserver.rb:104:in `service'
 file:/Users/nando/.m2/repository/org/jruby/jruby-complete/1.6.3/jruby-
complete-1.6.3.jar!/META-INF/jruby.home/lib/ruby/1.8/webrick/
httpserver.rb:65:in `run'
 file:/Users/nando/.m2/repository/org/jruby/jruby-complete/1.6.3/jruby-
complete-1.6.3.jar!/META-INF/jruby.home/lib/ruby/1.8/webrick/server.rb:
173:in `start_thread'
 org/jruby/RubyProc.java:268:in `call'
 org/jruby/RubyProc.java:232:in `call'

---- end ----

It seems that proceed's fexp.lookup_variable falis.

Any hints?

Thanks a lot,
//nando

[1] In our project, we rescue the good'ol participants.yml, which is
loaded via ruote-kit/config.ru - then, we monkeypatch
Engine.storage_participant so that any subclass of StorageParticipant
is returned, depending on our specific needs.
See https://gist.github.com/1108469

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to