Class: OpenWFE::ReserveExpression

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

Overview

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.

Instance Attribute Summary collapse

Attributes inherited from FlowExpression

#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods inherited from FlowExpression

#cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Methods included from OwfeServiceLocator

#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator

Methods inherited from ObjectWithMeta

#class_def, meta_def, meta_eval, metaclass

Constructor Details

This class inherits a constructor from OpenWFE::FlowExpression

Instance Attribute Details

#applied_workitemObject

An instance variable for storing the applied workitem if the ‘reserve’ cannot be entered immediately.



93
94
95
# File 'lib/openwfe/expressions/fe_reserve.rb', line 93

def applied_workitem
  @applied_workitem
end

#mutex_nameObject

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).



87
88
89
# File 'lib/openwfe/expressions/fe_reserve.rb', line 87

def mutex_name
  @mutex_name
end

Instance Method Details

#apply(workitem) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/openwfe/expressions/fe_reserve.rb', line 96

def apply (workitem)

    return reply_to_parent(workitem) \
        if @children.size < 1

    @mutex_name = lookup_string_attribute :mutex, workitem

    FlowMutex.synchronize do

        mutex = 
            lookup_variable(@mutex_name) || FlowMutex.new(@mutex_name)

        mutex.register self, workitem
    end
end

#enter(workitem = nil) ⇒ Object

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



122
123
124
125
126
# File 'lib/openwfe/expressions/fe_reserve.rb', line 122

def enter (workitem=nil)

    get_expression_pool.apply(
        @children[0], workitem || @applied_workitem)
end

#reply(workitem) ⇒ Object



112
113
114
115
116
117
# File 'lib/openwfe/expressions/fe_reserve.rb', line 112

def reply (workitem)

    lookup_variable(@mutex_name).release self

    reply_to_parent workitem
end