Parent

Class/Module Index [+]

Quicksearch

Ruote::Exp::ReserveExpression

Prevents two process branches from executing at the same time.

pdef = Ruote.process_definition :name => 'test' do
  concurrence do
    reserve :mutex => 'a' do
      alpha
    end
    reserve 'a' do
      alpha
    end
  end
end

(Nice and tiny example, turns a concurrence into a sequence...)

Public Instance Methods

apply() click to toggle source
# File lib/ruote/exp/fe_reserve.rb, line 48
def apply

  return reply_to_parent(h.applied_workitem) if tree_children.empty?

  h.mutex_name = attribute(:mutex) || attribute_text
  h.mutex_name = 'reserve' if h.mutex_name.strip == ''

  raise(
    ArgumentError.new("can't bind reserve mutex at engine level")
  ) if h.mutex_name.match(/^\/\//)

  set_mutex
end
cancel(flavour) click to toggle source
# File lib/ruote/exp/fe_reserve.rb, line 69
def cancel (flavour)

  super

  release_mutex
end
enter() click to toggle source
# File lib/ruote/exp/fe_reserve.rb, line 76
def enter

  apply_child(0, h.applied_workitem)
end
reply(workitem) click to toggle source
# File lib/ruote/exp/fe_reserve.rb, line 62
def reply (workitem)

  release_mutex

  reply_to_parent(workitem)
end

Protected Instance Methods

release_mutex() click to toggle source
# File lib/ruote/exp/fe_reserve.rb, line 108
def release_mutex

  target, var = locate_var(h.mutex_name)

  mutex = target.variables[var]

  mutex.last.shift

  r = target.try_persist

  return release_mutex if r != nil

  next_fei = mutex.last.first

  Ruote::Exp::FlowExpression.fetch(@context, next_fei).enter if next_fei
end
set_mutex() click to toggle source
# File lib/ruote/exp/fe_reserve.rb, line 83
def set_mutex

  target, var = locate_var(h.mutex_name)

  val = target.variables[var]

  # [ 'mutex', name, [ fei0, fei1, ... ] ]

  mutex = val ? val : [ 'mutex', var, [] ]

  mutex.last << h.fei

  target.variables[var] = mutex

  r = target.try_persist

  return set_mutex if r != nil

  if mutex.last.first == h.fei
    enter
  else
    persist_or_raise
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.