Class: OpenWFE::CursorExpression

Inherits:
WithTemplateExpression show all
Includes:
CommandMixin
Defined in:
lib/openwfe/expressions/fe_cursor.rb

Overview

The ‘cursor’ is much like a sequence, but you can go back and forth within it, as it reads the field ‘_cursor_command_’ (or the field specified in the ‘command-field’ attribute) at each transition (each time it’s supposed to move from one child expression to the next).

cursor do
    participant "alpha"
    skip :step => "2"
    participant "bravo"
    participant "charly"
    set :field => "__cursor_command__", value => "2"
    participant "delta"
    participant "echo"
    skip 2
    participant "fox"
    #
    # in that cursor example, only the participants alpha, charly and
    # echo will be handed a workitem
    # (notice the last 'skip' with its light syntax)
    #
end

As you can see, you can directly set the value of the field ‘_cursor_command_’ or use a CursorCommandExpression like ‘skip’ or ‘jump’.

Direct Known Subclasses

LoopExpression

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 WithTemplateExpression

#reply_to_parent

Methods inherited from FlowExpression

#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

#current_child_idObject

what is the index of the child we’re currently executing



89
90
91
# File 'lib/openwfe/expressions/fe_cursor.rb', line 89

def current_child_id
  @current_child_id
end

#loop_idObject

the integer identifier for the current loop



84
85
86
# File 'lib/openwfe/expressions/fe_cursor.rb', line 84

def loop_id
  @loop_id
end

Instance Method Details

#apply(workitem) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/openwfe/expressions/fe_cursor.rb', line 92

def apply (workitem)

    new_environment

    @loop_id = 0

    @current_child_id = -1

    clean_children_list

    reply workitem
end

#cancelObject

takes care of cancelling the current child if necessary



167
168
169
170
171
172
173
# File 'lib/openwfe/expressions/fe_cursor.rb', line 167

def cancel

    cfei = current_child_fei
    get_expression_pool.cancel(cfei) if cfei

    super
end

#is_loopObject

Returns false, the child class LoopExpression does return true.



178
179
180
181
# File 'lib/openwfe/expressions/fe_cursor.rb', line 178

def is_loop

    false
end

#reply(workitem) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/openwfe/expressions/fe_cursor.rb', line 105

def reply (workitem)

    return reply_to_parent(workitem) \
        if @children.length < 1
            #
            # well, currently, no infinite empty loop allowed

    command, step = determine_command_and_step workitem

    ldebug { "reply() command is '#{command} #{step}'" }

    if command == C_BREAK or command == C_CANCEL
        return reply_to_parent(workitem)
    end

    if command == C_REWIND or command == C_CONTINUE

        @current_child_id = 0

    elsif command and command.match "^#{C_JUMP}"

        @current_child_id = step
        @current_child_id = 0 if @current_child_id < 0

        @current_child_id = @children.length - 1 \
            if @current_child_id >= @children.length

    else # C_SKIP or C_BACK

        @current_child_id = @current_child_id + step

        @current_child_id = 0 if @current_child_id < 0

        if @current_child_id >= @children.length

            return reply_to_parent(workitem) unless is_loop

            @loop_id += 1
            @current_child_id = 0
        end
    end

    template_fei = @children[@current_child_id]

    #
    # launch the next child as a template

    #@current_child_fei = get_expression_pool.launch_template(
    get_expression_pool.launch_template(
        self, 
        @environment_id, 
        @loop_id, 
        template_fei,
        workitem, 
        nil)

    store_itself
end