Class: OpenWFE::FlowMutex

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/expressions/fe_reserve.rb

Overview

A FlowMutex is a process variable (thus serializable) that keeps track of the expressions in a critical section (1!) or waiting for entering it.

The current syncrhonization scheme is 1 thread mutex for all the FlowMutex. Shouldn’t be too costly and the operations under sync are quite tiny.

Constant Summary collapse

@@class_mutex =

Granularity level ? “big rock”. Only one FlowMutex operation a a time for the whole business process engine…

Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mutex_name) ⇒ FlowMutex

Returns a new instance of FlowMutex.



149
150
151
152
153
# File 'lib/openwfe/expressions/fe_reserve.rb', line 149

def initialize (mutex_name)

    @mutex_name = mutex_name
    @feis = []
end

Instance Attribute Details

#feisObject

Returns the value of attribute feis.



147
148
149
# File 'lib/openwfe/expressions/fe_reserve.rb', line 147

def feis
  @feis
end

#mutex_nameObject

Returns the value of attribute mutex_name.



146
147
148
# File 'lib/openwfe/expressions/fe_reserve.rb', line 146

def mutex_name
  @mutex_name
end

Class Method Details

.synchronize(&block) ⇒ Object

Used by the ReserveExpression when looking up for a FlowMutex and registering into it.



201
202
203
204
205
206
207
# File 'lib/openwfe/expressions/fe_reserve.rb', line 201

def self.synchronize (&block)

    @@class_mutex.synchronize do

        block.call
    end
end

Instance Method Details

#register(fexp, workitem) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/openwfe/expressions/fe_reserve.rb', line 155

def register (fexp, workitem)

    @feis << fexp.fei

    fexp.set_variable @mutex_name, self

    if @feis.size == 1
        #
        # immediately let the expression enter the critical section
        #
        fexp.store_itself
        fexp.enter workitem
    else
        #
        # later...
        #
        fexp.applied_workitem = workitem
        fexp.store_itself
    end
end

#release(releaser) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/openwfe/expressions/fe_reserve.rb', line 176

def release (releaser)

    next_fei = nil

    @@class_mutex.synchronize do

        current_fei = @feis.delete_at 0

        releaser.set_variable @mutex_name, self

        log.warn "release() BAD! c:#{current_fei} r:#{releaser.fei}" \
            if releaser.fei != current_fei

        next_fei = @feis.first
    end

    return unless next_fei

    releaser.get_expression_pool.fetch_expression(next_fei).enter
end