weel 1.2.6 → 1.99.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 498fe6c4aea9417706e1fae8604ebd83487badb7
4
- data.tar.gz: a04cc4c473ab811e5dad4c2cf25190f0cd2d8410
3
+ metadata.gz: 759696de1b4d59e435dbb6de3607281a78ae68b9
4
+ data.tar.gz: 56d4d1b419f47d5d5266c15b6f11ee907f8f3693
5
5
  SHA512:
6
- metadata.gz: 51923871cbb6ddfeacf71dc30e819d1a3229148e91a1840fa30378c6ac3e02725ce5472c30f13b6999aa40cbd59e3653bd25c6641fad9511fb3c7f608a39b4ce
7
- data.tar.gz: a1749f5b4d98d23d23967c152c0834ad9c88762a9c12069665a0ebd1853808ac80e26c6df4a08c8a7d109dfbc34bba23f8555a324991530dbaaf389b97e16ac3
6
+ metadata.gz: 2ffd15f62145efb88c1c99b23241681b6ea0ee0ecb390260b44e480c47fe9d0725fcb66813e31b29a3c9dbfef734a4c10658fd1cf8f14d9b6cfc2c2e5253f521
7
+ data.tar.gz: 19789e82488739d93b2eb4b250afc900260ffe03901d575a30d378a4659ddf2b316975b3fb2a57a9e2a6978f7424225c037df04ce538ee11e427d4529eb8b876
@@ -71,7 +71,22 @@ class WEEL
71
71
  class NoLongerNecessary < Exception; end
72
72
  end # }}}
73
73
 
74
- class ManipulateRealization # {{{
74
+ class ReadStructure # {{{
75
+ def initialize(data,endpoints)
76
+ @__weel_data = data
77
+ @__weel_endpoints = endpoints
78
+ @changed_data = []
79
+ @changed_endpoints = []
80
+ end
81
+
82
+ def data
83
+ ReadHash.new(@__weel_data)
84
+ end
85
+ def endpoints
86
+ ReadHash.new(@__weel_endpoints)
87
+ end
88
+ end # }}}
89
+ class ManipulateStructure # {{{
75
90
  def initialize(data,endpoints,status)
76
91
  @__weel_data = data
77
92
  @__weel_endpoints = endpoints
@@ -116,7 +131,6 @@ class WEEL
116
131
  end
117
132
 
118
133
  def method_missing(name,*args)
119
-
120
134
  if args.empty? && @__weel_values.has_key?(name)
121
135
  @__weel_values[name]
122
136
  elsif name.to_s[-1..-1] == "=" && args.length == 1
@@ -164,7 +178,7 @@ class WEEL
164
178
  class HandlerWrapperBase # {{{
165
179
  def initialize(arguments,endpoint=nil,position=nil,continue=nil); end
166
180
 
167
- def activity_handle(passthrough, endpoint, parameters); end
181
+ def activity_handle(passthrough, parameters); end
168
182
 
169
183
  def activity_result_value; end
170
184
  def activity_result_status; end
@@ -183,7 +197,7 @@ class WEEL
183
197
  def inform_position_change(ipc); end
184
198
  def inform_state_change(newstate); end
185
199
 
186
- def vote_sync_before; true; end
200
+ def vote_sync_before(parameters=nil); true; end
187
201
  def vote_sync_after; true; end
188
202
 
189
203
  # type => activity, loop, parallel, choice
@@ -193,6 +207,9 @@ class WEEL
193
207
  def simulate(type,nesting,eid,parent,parameters={}); end
194
208
 
195
209
  def callback(result); end
210
+
211
+ def test_condition(code); true; end
212
+ def manipulate(mr,code,result=nil,status=nil); nil; end
196
213
  end # }}}
197
214
 
198
215
  class Position # {{{
@@ -277,148 +294,17 @@ class WEEL
277
294
  attr_accessor :__weel_search_positions, :__weel_positions, :__weel_main, :__weel_data, :__weel_endpoints, :__weel_handlerwrapper, :__weel_handlerwrapper_args
278
295
  attr_reader :__weel_state, :__weel_status
279
296
 
280
- # DSL-Construct for an atomic activity
281
- # position: a unique identifier within the wf-description (may be used by the search to identify a starting point
282
- # type:
283
- # - :manipulate - just yield a given block
284
- # - :call - order the handlerwrapper to perform a service call
297
+ # DSL-Constructs for atomic calls to external services (calls) and pure context manipulations (manipulate).
298
+ # Calls can also manipulate context (after the invoking the external services)
299
+ # position: a unique identifier within the wf-description (may be used by the search to identify a starting point)
285
300
  # endpoint: (only with :call) ep of the service
286
301
  # parameters: (only with :call) service parameters
287
- def activity(position, type, endpoint=nil, *parameters, &blk)# {{{
288
- position = __weel_position_test position
289
- begin
290
- searchmode = __weel_is_in_search_mode(position)
291
- return if searchmode == true
292
- return if self.__weel_state == :stopping || self.__weel_state == :stopped || Thread.current[:nolongernecessary]
293
-
294
- Thread.current[:continue] = Continue.new
295
- handlerwrapper = @__weel_handlerwrapper.new @__weel_handlerwrapper_args, @__weel_endpoints[endpoint], position, Thread.current[:continue]
296
-
297
- if __weel_sim
298
- handlerwrapper.simulate(:activity,:none,position,Thread.current[:branch_sim_pos],:parameters=>parameters, :endpoint => endpoint, :type => type)
299
- return
300
- end
301
-
302
- ipc = {}
303
- if searchmode == :after
304
- wp = WEEL::Position.new(position, :after, nil)
305
- ipc[:after] = [wp.position]
306
- else
307
- if Thread.current[:branch_parent] && Thread.current[:branch_parent][:branch_position]
308
- @__weel_positions.delete Thread.current[:branch_parent][:branch_position]
309
- ipc[:unmark] ||= []
310
- ipc[:unmark] << Thread.current[:branch_parent][:branch_position].position rescue nil
311
- Thread.current[:branch_parent][:branch_position] = nil
312
- end
313
- if Thread.current[:branch_position]
314
- @__weel_positions.delete Thread.current[:branch_position]
315
- ipc[:unmark] ||= []
316
- ipc[:unmark] << Thread.current[:branch_position].position rescue nil
317
- end
318
- wp = WEEL::Position.new(position, :at, nil)
319
- ipc[:at] = [wp.position]
320
- end
321
- @__weel_positions << wp
322
- Thread.current[:branch_position] = wp
323
-
324
- handlerwrapper.inform_position_change(ipc)
325
-
326
- # searchmode position is after, jump directly to vote_sync_after
327
- raise Signal::Proceed if searchmode == :after
328
-
329
- raise Signal::Stop unless handlerwrapper.vote_sync_before
330
-
331
- case type
332
- when :manipulate
333
- if block_given?
334
- handlerwrapper.inform_activity_manipulate
335
- mr = ManipulateRealization.new(@__weel_data,@__weel_endpoints,@__weel_status)
336
- status = nil
337
- parameters.delete_if do |para|
338
- status = para if para.is_a?(Status)
339
- para.is_a?(Status)
340
- end
341
- case blk.arity
342
- when 1; mr.instance_exec(parameters,&blk)
343
- when 2; mr.instance_exec(parameters,status,&blk)
344
- else
345
- mr.instance_eval(&blk)
346
- end
347
- handlerwrapper.inform_manipulate_change(
348
- (mr.changed_status ? @__weel_status : nil),
349
- (mr.changed_data.any? ? mr.changed_data.uniq : nil),
350
- (mr.changed_endpoints.any? ? mr.changed_endpoints.uniq : nil)
351
- )
352
- handlerwrapper.inform_activity_done
353
- wp.detail = :after
354
- handlerwrapper.inform_position_change :after => [wp.position]
355
- end
356
- when :call
357
- params = { }
358
- passthrough = @__weel_search_positions[position] ? @__weel_search_positions[position].passthrough : nil
359
- parameters.each do |p|
360
- if p.class == Hash && parameters.length == 1
361
- params = p
362
- else
363
- if !p.is_a?(Symbol) || !@__weel_data.include?(p)
364
- raise("not all passed parameters are data elements")
365
- end
366
- params[p] = @__weel_data[p]
367
- end
368
- end
369
- # handshake call and wait until it finished
370
- handlerwrapper.activity_handle passthrough, params
371
- Thread.current[:continue].wait unless Thread.current[:nolongernecessary] || self.__weel_state == :stopping || self.__weel_state == :stopped
372
-
373
- if Thread.current[:nolongernecessary]
374
- handlerwrapper.activity_no_longer_necessary
375
- raise Signal::NoLongerNecessary
376
- end
377
- if self.__weel_state == :stopping
378
- handlerwrapper.activity_stop
379
- wp.passthrough = handlerwrapper.activity_passthrough_value
380
- end
381
-
382
- if wp.passthrough.nil? && block_given?
383
- handlerwrapper.inform_activity_manipulate
384
- mr = ManipulateRealization.new(@__weel_data,@__weel_endpoints,@__weel_status)
385
- status = handlerwrapper.activity_result_status
386
- case blk.arity
387
- when 1; mr.instance_exec(handlerwrapper.activity_result_value,&blk)
388
- when 2; mr.instance_exec(handlerwrapper.activity_result_value,(status.is_a?(Status)?status:nil),&blk)
389
- else
390
- mr.instance_eval(&blk)
391
- end
392
- handlerwrapper.inform_manipulate_change(
393
- (mr.changed_status ? @__weel_status : nil),
394
- (mr.changed_data.any? ? mr.changed_data.uniq : nil),
395
- (mr.changed_endpoints.any? ? mr.changed_endpoints.uniq : nil)
396
- )
397
- end
398
- if wp.passthrough.nil?
399
- handlerwrapper.inform_activity_done
400
- wp.detail = :after
401
- handlerwrapper.inform_position_change :after => [wp.position]
402
- end
403
- end
404
- raise Signal::Proceed
405
- rescue Signal::SkipManipulate, Signal::Proceed
406
- if self.__weel_state != :stopping && !handlerwrapper.vote_sync_after
407
- self.__weel_state = :stopping
408
- wp.detail = :unmark
409
- end
410
- rescue Signal::NoLongerNecessary
411
- @__weel_positions.delete wp
412
- Thread.current[:branch_position] = nil
413
- wp.detail = :unmark
414
- handlerwrapper.inform_position_change :unmark => [wp.position]
415
- rescue Signal::StopSkipManipulate, Signal::Stop
416
- self.__weel_state = :stopping
417
- rescue => err
418
- handlerwrapper.inform_activity_failed err
419
- self.__weel_state = :stopping
420
- end
421
- end # }}}
302
+ def call(position, endpoint, parameters={}, code=nil, &blk)
303
+ __weel_activity(position,:call,endpoint,parameters,code||blk)
304
+ end
305
+ def manipulate(position, code=nil, &blk)
306
+ __weel_activity(position,:manipulate,nil,{},code||blk)
307
+ end
422
308
 
423
309
  # Parallel DSL-Construct
424
310
  # Defines Workflow paths that can be executed parallel.
@@ -555,6 +441,10 @@ class WEEL
555
441
  Thread.current[:mutex] ||= Mutex.new
556
442
  Thread.current[:mutex].synchronize do
557
443
  return if Thread.current[:alternative_mode] == :exclusive && Thread.current[:alternative_executed][-1] = true
444
+ if condition.is_a?(String) && !__weel_sim
445
+ handlerwrapper = @__weel_handlerwrapper.new @__weel_handlerwrapper_args
446
+ condition = handlerwrapper.test_condition(ReadStructure.new(@__weel_data,@__weel_endpoints),__condition)
447
+ end
558
448
  Thread.current[:alternative_executed][-1] = true if condition
559
449
  end
560
450
  yield if __weel_is_in_search_mode || __weel_sim || condition
@@ -583,7 +473,7 @@ class WEEL
583
473
 
584
474
  # Defines a Cycle (loop/iteration)
585
475
  def loop(condition)# {{{
586
- unless condition.is_a?(Array) && condition[0].is_a?(Proc) && [:pre_test,:post_test].include?(condition[1])
476
+ unless condition.is_a?(Array) && (condition[0].is_a?(Proc) || condition[0].is_a?(String)) && [:pre_test,:post_test].include?(condition[1])
587
477
  raise "condition must be called pre_test{} or post_test{}"
588
478
  end
589
479
  return if self.__weel_state == :stopping || self.__weel_state == :stopped || Thread.current[:nolongernecessary]
@@ -596,20 +486,21 @@ class WEEL
596
486
  yield
597
487
  __weel_sim_stop(:loop,hw,pos,:testing=>condition[1])
598
488
  return
599
- end
489
+ end
490
+ handlerwrapper = @__weel_handlerwrapper.new @__weel_handlerwrapper_args unless condition[0].is_a?(Proc)
600
491
  case condition[1]
601
492
  when :pre_test
602
- yield while condition[0].call && self.__weel_state != :stopping && self.__weel_state != :stopped
493
+ yield while (condition[0].is_a?(Proc) ? condition[0].call : handlerwrapper.test_condition(ReadStructure.new(@__weel_data,@__weel_endpoints),condition[0])) && self.__weel_state != :stopping && self.__weel_state != :stopped
603
494
  when :post_test
604
- begin; yield; end while condition[0].call && self.__weel_state != :stopping && self.__weel_state != :stopped
495
+ begin; yield; end while (condition[0].is_a?(Proc) ? condition[0].call : handlerwrapper.test_condition(ReadStructure.new(@__weel_data,@__weel_endpoints),condition[0])) && self.__weel_state != :stopping && self.__weel_state != :stopped
605
496
  end
606
497
  end # }}}
607
498
 
608
- def pre_test(&blk)# {{{
609
- [blk, :pre_test]
499
+ def pre_test(code=nil,&blk)# {{{
500
+ [code || blk, :pre_test]
610
501
  end # }}}
611
- def post_test(&blk)# {{{
612
- [blk, :post_test]
502
+ def post_test(code=nil,&blk)# {{{
503
+ [code || blk, :post_test]
613
504
  end # }}}
614
505
 
615
506
  def status # {{{
@@ -623,6 +514,159 @@ class WEEL
623
514
  end # }}}
624
515
 
625
516
  private
517
+ def __weel_activity(position, type, endpoint, parameters, code)# {{{
518
+ position = __weel_position_test position
519
+ begin
520
+ searchmode = __weel_is_in_search_mode(position)
521
+ return if searchmode == true
522
+ return if self.__weel_state == :stopping || self.__weel_state == :stopped || Thread.current[:nolongernecessary]
523
+
524
+ Thread.current[:continue] = Continue.new
525
+ handlerwrapper = @__weel_handlerwrapper.new @__weel_handlerwrapper_args, @__weel_endpoints[endpoint], position, Thread.current[:continue]
526
+
527
+ if __weel_sim
528
+ handlerwrapper.simulate(:activity,:none,position,Thread.current[:branch_sim_pos],:parameters=>parameters, :endpoint => endpoint, :type => type)
529
+ return
530
+ end
531
+
532
+ ipc = {}
533
+ if searchmode == :after
534
+ wp = WEEL::Position.new(position, :after, nil)
535
+ ipc[:after] = [wp.position]
536
+ else
537
+ if Thread.current[:branch_parent] && Thread.current[:branch_parent][:branch_position]
538
+ @__weel_positions.delete Thread.current[:branch_parent][:branch_position]
539
+ ipc[:unmark] ||= []
540
+ ipc[:unmark] << Thread.current[:branch_parent][:branch_position].position rescue nil
541
+ Thread.current[:branch_parent][:branch_position] = nil
542
+ end
543
+ if Thread.current[:branch_position]
544
+ @__weel_positions.delete Thread.current[:branch_position]
545
+ ipc[:unmark] ||= []
546
+ ipc[:unmark] << Thread.current[:branch_position].position rescue nil
547
+ end
548
+ wp = WEEL::Position.new(position, :at, nil)
549
+ ipc[:at] = [wp.position]
550
+ end
551
+ @__weel_positions << wp
552
+ Thread.current[:branch_position] = wp
553
+
554
+ handlerwrapper.inform_position_change(ipc)
555
+
556
+ # searchmode position is after, jump directly to vote_sync_after
557
+ raise Signal::Proceed if searchmode == :after
558
+
559
+ case type
560
+ when :manipulate
561
+ raise Signal::Stop unless handlerwrapper.vote_sync_before
562
+
563
+ if code.is_a?(Proc) || code.is_a?(String)
564
+ handlerwrapper.inform_activity_manipulate
565
+ if code.is_a?(Proc)
566
+ mr = ManipulateStructure.new(@__weel_data,@__weel_endpoints,@__weel_status)
567
+ mr.instance_eval(&code)
568
+ elsif code.is_a?(String)
569
+ mr = ManipulateStructure.new(@__weel_data,@__weel_endpoints,@__weel_status)
570
+ handlerwrapper.manipulate(mr,code)
571
+ end
572
+ handlerwrapper.inform_manipulate_change(
573
+ ((mr && mr.changed_status) ? @__weel_status : nil),
574
+ ((mr && mr.changed_data.any?) ? mr.changed_data.uniq : nil),
575
+ ((mr && mr.changed_endpoints.any?) ? mr.changed_endpoints.uniq : nil)
576
+ )
577
+ handlerwrapper.inform_activity_done
578
+ wp.detail = :after
579
+ handlerwrapper.inform_position_change :after => [wp.position]
580
+ end
581
+ when :call
582
+ params = { }
583
+ case parameters
584
+ when String
585
+ code = parameters
586
+ parameters = nil
587
+ when Hash
588
+ parameters.each do |k,p|
589
+ if p.is_a?(Symbol) && @__weel_data.include?(p)
590
+ params[k] = @__weel_data[p]
591
+ elsif k == :code && p.is_a?(String)
592
+ code = p
593
+ else
594
+ params[k] = p
595
+ end
596
+ end
597
+ when Array
598
+ parameters.each_with_index do |p,i|
599
+ if p.is_a?(Symbol) && @__weel_data.include?(p)
600
+ params[p] = @__weel_data[p]
601
+ else
602
+ params[i] = p
603
+ end
604
+ end
605
+ else
606
+ raise("invalid parameters")
607
+ end
608
+ raise Signal::Stop unless handlerwrapper.vote_sync_before(params)
609
+
610
+ passthrough = @__weel_search_positions[position] ? @__weel_search_positions[position].passthrough : nil
611
+ # handshake call and wait until it finished
612
+ handlerwrapper.activity_handle passthrough, params
613
+ Thread.current[:continue].wait unless Thread.current[:nolongernecessary] || self.__weel_state == :stopping || self.__weel_state == :stopped
614
+
615
+ if Thread.current[:nolongernecessary]
616
+ handlerwrapper.activity_no_longer_necessary
617
+ raise Signal::NoLongerNecessary
618
+ end
619
+ if self.__weel_state == :stopping
620
+ handlerwrapper.activity_stop
621
+ wp.passthrough = handlerwrapper.activity_passthrough_value
622
+ end
623
+
624
+ if wp.passthrough.nil? && (code.is_a?(Proc) || code.is_a?(String))
625
+ handlerwrapper.inform_activity_manipulate
626
+ status = handlerwrapper.activity_result_status
627
+ if code.is_a?(Proc)
628
+ mr = ManipulateStructure.new(@__weel_data,@__weel_endpoints,@__weel_status)
629
+ case code.arity
630
+ when 1; mr.instance_exec(handlerwrapper.activity_result_value,&code)
631
+ when 2; mr.instance_exec(handlerwrapper.activity_result_value,(status.is_a?(Status)?status:nil),&code)
632
+ else
633
+ mr.instance_eval(&code)
634
+ end
635
+ elsif code.is_a?(String)
636
+ mr = ManipulateStructure.new(@__weel_data,@__weel_endpoints,@__weel_status)
637
+ handlerwrapper.manipulate(mr,code,handlerwrapper.activity_result_value,(status.is_a?(Status)?status:nil))
638
+ end
639
+ handlerwrapper.inform_manipulate_change(
640
+ (mr.changed_status ? @__weel_status : nil),
641
+ (mr.changed_data.any? ? mr.changed_data.uniq : nil),
642
+ (mr.changed_endpoints.any? ? mr.changed_endpoints.uniq : nil)
643
+ )
644
+ end
645
+ if wp.passthrough.nil?
646
+ handlerwrapper.inform_activity_done
647
+ wp.detail = :after
648
+ handlerwrapper.inform_position_change :after => [wp.position]
649
+ end
650
+ end
651
+ raise Signal::Proceed
652
+ rescue Signal::SkipManipulate, Signal::Proceed
653
+ if self.__weel_state != :stopping && !handlerwrapper.vote_sync_after
654
+ self.__weel_state = :stopping
655
+ wp.detail = :unmark
656
+ end
657
+ rescue Signal::NoLongerNecessary
658
+ @__weel_positions.delete wp
659
+ Thread.current[:branch_position] = nil
660
+ wp.detail = :unmark
661
+ handlerwrapper.inform_position_change :unmark => [wp.position]
662
+ rescue Signal::StopSkipManipulate, Signal::Stop
663
+ self.__weel_state = :stopping
664
+ rescue => err
665
+ handlerwrapper.inform_activity_failed err
666
+ self.__weel_state = :stopping
667
+ end
668
+ end # }}}
669
+
626
670
  def __weel_recursive_print(thread,indent='')# {{{
627
671
  p "#{indent}#{thread}"
628
672
  if thread[:branches]
@@ -85,4 +85,11 @@ class TestHandlerWrapper < WEEL::HandlerWrapperBase
85
85
  $long_track += "---> STATE #{newstate}\n"
86
86
  $short_track << "|#{newstate}|"
87
87
  end
88
+
89
+ def manipulate(mr,code,result=nil,status=nil)
90
+ mr.instance_eval(code)
91
+ end
92
+ def test_condition(mr,code)
93
+ mr.instance_eval(code)
94
+ end
88
95
  end
@@ -10,26 +10,26 @@ class TestWorkflow < WEEL
10
10
  data :x => 'begin_'
11
11
 
12
12
  control flow do
13
- activity :a1_1, :call, :endpoint1 do |result|
13
+ call :a1_1, :endpoint1 do |result|
14
14
  data.x += "#{result}"
15
15
  end
16
16
  parallel :wait => 2 do
17
17
  parallel_branch do
18
- activity :a2_1_1, :call, :endpoint1
18
+ call :a2_1_1, :endpoint1
19
19
  end
20
20
  parallel_branch do
21
- activity :a2_2_1, :call, :endpoint1
21
+ call :a2_2_1, :endpoint1
22
22
  end
23
23
  end
24
- activity :a3, :manipulate do
24
+ manipulate :a3 do
25
25
  data.x += '_end'
26
26
  end
27
27
  choose do
28
28
  alternative data.x != nil do
29
- activity :a4a, :call, :endpoint1
29
+ call :a4a, :endpoint1
30
30
  end
31
31
  otherwise do
32
- activity :a4b, :call, :endpoint1
32
+ call :a4b, :endpoint1
33
33
  end
34
34
  end
35
35
  end