Class OpenWFE::ReserveExpression
In: lib/openwfe/expressions/fe_reserve.rb
Parent: FlowExpression

The ‘reserve’ expression ensures that its nested child expression executes while a reserved mutex is set.

Thus

    concurrence do
        reserve :mutex => :m0 do
            sequence do
                participant :alpha
                participant :bravo
            end
        end
        reserve :mutex => :m0 do
            participant :charly
        end
        participant :delta
    end

The sequence will not but run while the participant charly is active and vice versa. The participant delta is not concerned.

The mutex is a regular variable name, thus a mutex named "//toto" could be used to prevent segments of totally different process instances from running.

Methods

apply   enter   reply  

Attributes

applied_workitem  [RW]  An instance variable for storing the applied workitem if the ‘reserve’ cannot be entered immediately.
mutex_name  [RW]  The name of the mutex this expressions uses. It‘s a variable name, that means it can be prefixed with {nothing} (local scope), ’/’ (process scope) and ’//’ (engine / global scope).

Public Instance methods

[Source]

     # File lib/openwfe/expressions/fe_reserve.rb, line 96
 96:         def apply (workitem)
 97: 
 98:             return reply_to_parent(workitem) \
 99:                 if @children.size < 1
100: 
101:             @mutex_name = lookup_string_attribute :mutex, workitem
102: 
103:             FlowMutex.synchronize do
104: 
105:                 mutex = 
106:                     lookup_variable(@mutex_name) || FlowMutex.new(@mutex_name)
107: 
108:                 mutex.register self, workitem
109:             end
110:         end

Called by the FlowMutex to enter the ‘reserved/critical’ section.

[Source]

     # File lib/openwfe/expressions/fe_reserve.rb, line 122
122:         def enter (workitem=nil)
123: 
124:             get_expression_pool.apply(
125:                 @children[0], workitem || @applied_workitem)
126:         end

[Source]

     # File lib/openwfe/expressions/fe_reserve.rb, line 112
112:         def reply (workitem)
113: 
114:             lookup_variable(@mutex_name).release self
115: 
116:             reply_to_parent workitem
117:         end

[Validate]