Class OpenWFE::Environment
In: lib/openwfe/expressions/environment.rb
Parent: FlowExpression

An environment is a store for variables. It‘s an expression thus it‘s storable in the expression pool.

Methods

Included Modules

Rufus::Schedulable

Constants

V_PAUSED = VAR_PAUSED[1..-1]

Attributes

variables  [RW]  the variables stored in this environment.

Public Class methods

def initialize (

    fei, parent, environment_id, application_context, attributes)
    super(fei, parent, environment_id, application_context, attributes)
    @variables = {}

end

[Source]

    # File lib/openwfe/expressions/environment.rb, line 69
69:         def initialize
70: 
71:             super
72: 
73:             @variables = {}
74:         end

[Source]

    # File lib/openwfe/expressions/environment.rb, line 76
76:         def self.new_env (
77:             fei, parent_id, environment_id, app_context, attributes)
78: 
79:             env = self.new
80: 
81:             env.fei = fei
82:             env.parent_id = parent_id
83:             env.environment_id = environment_id
84:             env.application_context = app_context
85:             env.attributes = attributes
86: 
87:             env
88:         end

Public Instance methods

Looks up for the value of a variable in this environment.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 93
 93:         def [] (key)
 94: 
 95:             value = @variables[key]
 96: 
 97:             return value \
 98:                 if @variables.has_key?(key) or is_engine_environment?
 99: 
100:             return get_parent[key] if @parent_id
101: 
102:             get_expression_pool.fetch_engine_environment[key]
103:         end

Binds a variable in this environment.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 108
108:         def []= (key, value)
109: 
110:             #ldebug do 
111:             #    "#{fei.to_debug_s} []= "+
112:             #    "'#{key}' => '#{value}' (#{value.class.name})"
113:             #end
114: 
115:             synchronize do
116: 
117:                 @variables[key] = value
118:                 store_itself
119:             end
120:         end

Removes a variable from this environment.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 125
125:         def delete (key)
126:             synchronize do
127: 
128:                 ldebug { "#{fei.to_debug_s} delete() '#{key}'" }
129: 
130:                 @variables.delete key
131:                 store_itself
132:             end
133:         end

Returns a deep copy of this environment.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 230
230:         def dup
231: 
232:             env = Environment.new_env(
233:                 @fei.dup, 
234:                 @parent_id, 
235:                 @environment_id, 
236:                 @application_context, 
237:                 OpenWFE::fulldup(@attributes))
238: 
239:             env.variables = OpenWFE::fulldup self.variables
240: 
241:             env
242:         end

Returns the top environment for the process instance (the environment just before the engine environment).

[Source]

     # File lib/openwfe/expressions/environment.rb, line 210
210:         def get_root_environment
211: 
212:             #ldebug { "get_root_environment\n#{self}" }
213: 
214:             return self unless @parent_id
215: 
216:             get_parent.get_root_environment
217:         end

Returns true if this environment is the engine environment

[Source]

     # File lib/openwfe/expressions/environment.rb, line 162
162:         def is_engine_environment?
163: 
164:             (@fei == get_expression_pool.engine_environment_id)
165:         end

Will reschedule any ‘Schedulable’ variable found in this environment this method especially targets cron expressions that are stored as variables and need to be rescheduled upon engine restart.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 181
181:         def reschedule (scheduler)
182: 
183:             @fei.owfe_version = OPENWFERU_VERSION \
184:                 if @fei.wfurl == 'ee' and @fei.wfname =='ee'
185:                     #
186:                     # so that older versions of engine envs get accepted
187: 
188:             @variables.each do |key, value|
189: 
190:                 #ldebug { "reschedule()  - item of class #{value.class}" }
191: 
192:                 get_expression_pool.paused_instances[@fei.wfid] = true \
193:                     if key == V_PAUSED
194: 
195:                 next unless value.kind_of?(Rufus::Schedulable)
196: 
197:                 linfo { "reschedule() for instance of #{value.class.name}" }
198: 
199:                 value.application_context = @application_context
200:                 value.reschedule(scheduler)
201:             end
202: 
203:             store_itself
204:         end

Should never get used, only the reschedule() method is relevant for the Schedulable aspect of an environment expression.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 171
171:         def trigger (params)
172: 
173:             raise "an environment should never get directly triggered"
174:         end

This method is usually called before the environment gets wiped out of the expression pool. It takes care of removing subprocess templates pointed at by variables in this environment.

[Source]

     # File lib/openwfe/expressions/environment.rb, line 141
141:         def unbind
142: 
143:             #ldebug { "unbind() for #{fei.to_s}" }
144: 
145:             @variables.each do |key, value|
146: 
147:                 #ldebug { "unbind() '#{key}' => #{value.class}" }
148: 
149:                 if value.kind_of?(FlowExpressionId)
150: 
151:                     get_expression_pool.remove(value)
152: 
153:                 #elsif value.kind_of?(FlowExpression)
154:                 #    value.cancel
155:                 end
156:             end
157:         end

[Validate]