openwferu 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/examples/engine_template.rb +182 -0
  2. data/examples/openwferu.rb +6 -7
  3. data/lib/openwfe/contextual.rb +8 -6
  4. data/lib/openwfe/engine/engine.rb +49 -14
  5. data/lib/openwfe/expool/expressionpool.rb +48 -17
  6. data/lib/openwfe/expool/history.rb +64 -14
  7. data/lib/openwfe/expool/journal.rb +66 -28
  8. data/lib/openwfe/expool/journal_replay.rb +190 -48
  9. data/lib/openwfe/expool/wfidgen.rb +51 -6
  10. data/lib/openwfe/expressions/condition.rb +49 -5
  11. data/lib/openwfe/expressions/environment.rb +9 -37
  12. data/lib/openwfe/expressions/expressionmap.rb +15 -1
  13. data/lib/openwfe/expressions/fe_concurrence.rb +4 -4
  14. data/lib/openwfe/expressions/fe_cron.rb +1 -5
  15. data/lib/openwfe/expressions/fe_do.rb +96 -26
  16. data/lib/openwfe/expressions/fe_equals.rb +190 -0
  17. data/lib/openwfe/expressions/fe_fqv.rb +25 -7
  18. data/lib/openwfe/expressions/fe_if.rb +262 -0
  19. data/lib/openwfe/expressions/fe_iterator.rb +3 -4
  20. data/lib/openwfe/expressions/fe_losfor.rb +0 -1
  21. data/lib/openwfe/expressions/fe_misc.rb +4 -5
  22. data/lib/openwfe/expressions/fe_participant.rb +2 -3
  23. data/lib/openwfe/expressions/fe_raw.rb +71 -31
  24. data/lib/openwfe/expressions/fe_reserve.rb +141 -0
  25. data/lib/openwfe/expressions/fe_sequence.rb +0 -1
  26. data/lib/openwfe/expressions/fe_sleep.rb +3 -58
  27. data/lib/openwfe/expressions/fe_subprocess.rb +6 -5
  28. data/lib/openwfe/expressions/fe_value.rb +20 -121
  29. data/lib/openwfe/expressions/fe_wait.rb +79 -0
  30. data/lib/openwfe/expressions/fe_when.rb +31 -96
  31. data/lib/openwfe/expressions/flowexpression.rb +112 -19
  32. data/lib/openwfe/expressions/raw_prog.rb +8 -116
  33. data/lib/openwfe/expressions/simplerep.rb +197 -0
  34. data/lib/openwfe/expressions/time.rb +266 -0
  35. data/lib/openwfe/expressions/timeout.rb +2 -2
  36. data/lib/openwfe/flowexpressionid.rb +22 -0
  37. data/lib/openwfe/listeners/socketlisteners.rb +15 -1
  38. data/lib/openwfe/participants/participantmap.rb +12 -1
  39. data/lib/openwfe/participants/participants.rb +7 -1
  40. data/lib/openwfe/rudefinitions.rb +1 -6
  41. data/lib/openwfe/service.rb +8 -0
  42. data/lib/openwfe/util/irb.rb +86 -0
  43. data/lib/openwfe/util/ometa.rb +3 -3
  44. data/lib/openwfe/util/safe.rb +26 -34
  45. data/lib/openwfe/util/scheduler.rb +133 -76
  46. data/lib/openwfe/utils.rb +1 -1
  47. data/lib/openwfe/version.rb +2 -2
  48. data/lib/openwfe/workitem.rb +38 -0
  49. data/lib/openwfe/worklist/storeparticipant.rb +27 -2
  50. data/test/console_test.rb +15 -0
  51. data/test/flowtestbase.rb +20 -28
  52. data/test/ft_12_blockparticipant.rb +24 -0
  53. data/test/ft_14b_subprocess.rb +18 -0
  54. data/test/ft_22_history.rb +22 -1
  55. data/test/ft_23_when.rb +29 -2
  56. data/test/ft_23b_when.rb +17 -0
  57. data/test/ft_23c_wait.rb +87 -0
  58. data/test/ft_2_concurrence.rb +15 -14
  59. data/test/ft_2b_concurrence.rb +4 -4
  60. data/test/ft_32_journal.rb +29 -6
  61. data/test/ft_32b_journal.rb +76 -0
  62. data/test/ft_36_subprocids.rb +96 -0
  63. data/test/ft_37_pnames.rb +55 -0
  64. data/test/ft_38_tag.rb +128 -0
  65. data/test/ft_39_reserve.rb +119 -0
  66. data/test/ft_3_equals.rb +20 -1
  67. data/test/ft_40_defined.rb +72 -0
  68. data/test/ft_41_case.rb +124 -0
  69. data/test/ft_4_misc.rb +17 -0
  70. data/test/ft_5_time.rb +15 -20
  71. data/test/ft_7_lose.rb +2 -3
  72. data/test/ft_8_forget.rb +1 -1
  73. data/test/ft_tests.rb +9 -0
  74. data/test/hparticipant_test.rb +47 -1
  75. data/test/nut_0_irb.rb +20 -0
  76. data/test/raw_prog_test.rb +6 -0
  77. data/test/safely_test.rb +31 -41
  78. data/test/wfid_test.rb +43 -0
  79. metadata +21 -4
  80. data/lib/openwfe/expressions/fe_utils.rb +0 -151
@@ -39,11 +39,12 @@
39
39
  # John Mettraux at openwfe.org
40
40
  #
41
41
 
42
- #require 'openwfe/util/model'
43
42
  require 'openwfe/expressions/environment'
44
43
  require 'openwfe/expressions/fe_define'
45
44
  require 'openwfe/expressions/fe_misc'
46
45
  require 'openwfe/expressions/fe_value'
46
+ require 'openwfe/expressions/fe_if'
47
+ require 'openwfe/expressions/fe_equals'
47
48
  require 'openwfe/expressions/fe_sequence'
48
49
  require 'openwfe/expressions/fe_subprocess'
49
50
  require 'openwfe/expressions/fe_concurrence'
@@ -51,11 +52,14 @@ require 'openwfe/expressions/fe_participant'
51
52
  require 'openwfe/expressions/fe_sleep'
52
53
  require 'openwfe/expressions/fe_cron'
53
54
  require 'openwfe/expressions/fe_when'
55
+ require 'openwfe/expressions/fe_wait'
56
+ require 'openwfe/expressions/fe_reserve'
54
57
  require 'openwfe/expressions/fe_losfor'
55
58
  require 'openwfe/expressions/fe_cursor'
56
59
  require 'openwfe/expressions/fe_iterator'
57
60
  require 'openwfe/expressions/fe_fqv'
58
61
  require 'openwfe/expressions/fe_cancel'
62
+ require 'openwfe/expressions/fe_do'
59
63
 
60
64
 
61
65
  module OpenWFE
@@ -85,12 +89,19 @@ module OpenWFE
85
89
  register SetValueExpression
86
90
  register UnsetValueExpression
87
91
 
92
+ register DefinedExpression
93
+
88
94
  register IfExpression
95
+ register CaseExpression
96
+
89
97
  register EqualsExpression
90
98
 
91
99
  register SleepExpression
92
100
  register CronExpression
93
101
  register WhenExpression
102
+ register WaitExpression
103
+
104
+ register ReserveExpression
94
105
 
95
106
  register RevalExpression
96
107
  register PrintExpression
@@ -109,6 +120,9 @@ module OpenWFE
109
120
 
110
121
  register CancelProcessExpression
111
122
 
123
+ register UndoExpression
124
+ register RedoExpression
125
+
112
126
  register Environment
113
127
  #
114
128
  # only used by get_expression_names()
@@ -384,7 +384,7 @@ module OpenWFE
384
384
  return -1 if not s
385
385
  i = s.to_i
386
386
  return -1 if i < 1
387
- return i
387
+ i
388
388
  end
389
389
 
390
390
  #
@@ -467,7 +467,7 @@ module OpenWFE
467
467
  #puts result.to_s
468
468
  #puts
469
469
 
470
- return result
470
+ result
471
471
  end
472
472
 
473
473
  protected
@@ -509,7 +509,7 @@ module OpenWFE
509
509
 
510
510
  return wiSource if override?
511
511
 
512
- wiSource.attributes.each do | k, v |
512
+ wiSource.attributes.each do |k, v|
513
513
 
514
514
  #puts "merge() '#{k}' => '#{v}'"
515
515
 
@@ -519,7 +519,7 @@ module OpenWFE
519
519
  wiTarget.attributes[nk] = nv
520
520
  end
521
521
 
522
- return wiTarget
522
+ wiTarget
523
523
  end
524
524
  end
525
525
 
@@ -43,13 +43,9 @@
43
43
  require 'openwfe/utils'
44
44
  require 'openwfe/util/otime'
45
45
  require 'openwfe/util/scheduler'
46
- require 'openwfe/expressions/fe_sleep'
46
+ require 'openwfe/expressions/time'
47
47
 
48
48
 
49
- #
50
- # expressions like 'sleep' and 'cron'
51
- #
52
-
53
49
  module OpenWFE
54
50
 
55
51
  #
@@ -39,61 +39,131 @@
39
39
  # John Mettraux at openwfe.org
40
40
  #
41
41
 
42
+ require 'openwfe/utils'
42
43
  require 'openwfe/expressions/flowexpression'
43
44
 
44
45
 
45
46
  #
46
- # do / redo / undo
47
+ # redo / undo (cancel)
47
48
  #
48
49
 
49
50
  module OpenWFE
50
51
 
51
52
  #
52
- # in preparation.
53
+ # Every expression in OpenWFEru accepts a 'tag' attribute. This tag
54
+ # can later be referenced by an 'undo' or 'redo' expression.
55
+ # Tags are active as soon as an expression is applied and they vanish
56
+ # when the expression replies to its parent expression or is cancelled.
53
57
  #
54
- class DoExpression < FlowExpression
55
-
56
- attr_accessor \
57
- :name
58
+ # Calling for the undo of a non-existent tag throws no error, the flow
59
+ # simply resumes.
60
+ #
61
+ # concurrence do
62
+ # sequence :tag => "side_job" do
63
+ # participant "alice"
64
+ # participant "bob"
65
+ # end
66
+ # sequence do
67
+ # participant "charly"
68
+ # undo :ref => "side_job"
69
+ # end
70
+ # end
71
+ #
72
+ # In this example, as soon as the participant charly is over, the sequence
73
+ # 'side_job' gets undone (cancelled). If the sequence 'side_job' was
74
+ # already over, the "undo" will have no effect.
75
+ #
76
+ class UndoExpression < FlowExpression
58
77
 
59
- #
60
- # apply / reply
78
+ names :undo
61
79
 
62
80
  def apply (workitem)
63
- end
64
81
 
65
- def reply (workitem)
66
- end
67
- end
82
+ tag = lookup_tag(workitem)
68
83
 
69
- #
70
- # in preparation.
71
- #
72
- class UndoExpression < FlowExpression
84
+ undo_self = false
85
+
86
+ if tag
87
+ #OpenWFE::call_in_thread(fei.expression_name, self) do
88
+ process_tag(tag)
89
+ #end
90
+
91
+ undo_self = tag.fei.ancestor_of?(@fei)
92
+ end
93
+
94
+ reply_to_parent(workitem) unless undo_self
95
+ end
73
96
 
74
97
  #
75
- # apply / reply
98
+ # Calls the expression pool cancel() method upon the tagged
99
+ # expression.
100
+ #
101
+ def process_tag (tag)
76
102
 
77
- def apply (workitem)
103
+ ldebug do
104
+ "process_tag() #{fei.to_debug_s} to undo #{tag.fei.to_debug_s}"
105
+ end
106
+
107
+ #get_expression_pool.cancel_and_reply_to_parent(
108
+ # tag.raw_expression.fei, tag.workitem)
109
+
110
+ exp = get_expression_pool.fetch_expression(tag.raw_expression.fei)
111
+
112
+ get_expression_pool.cancel(tag.raw_expression.fei)
113
+
114
+ get_expression_pool.reply_to_parent(exp, tag.workitem, false)
115
+ #
116
+ # 'remove' is set to false, cancel already removed the
117
+ # expression
78
118
  end
79
119
 
80
120
  #def reply (workitem)
81
121
  #end
122
+
123
+ protected
124
+
125
+ def lookup_tag (workitem)
126
+
127
+ tagname = lookup_attribute(:ref, workitem)
128
+
129
+ tag = lookup_variable(tagname)
130
+
131
+ lwarn { "lookup_tag() no tag named '#{tagname}' found" } \
132
+ unless tag
133
+
134
+ tag
135
+ end
82
136
  end
83
137
 
84
138
  #
85
- # in preparation.
139
+ # Every expression in OpenWFEru accepts a 'tag' attribute. This tag
140
+ # can later be referenced by an 'undo' or 'redo' expression.
86
141
  #
87
- class RedoExpression < FlowExpression
142
+ # Calling for the undo of a non-existent tag throws no error, the flow
143
+ # simply resumes.
144
+ #
145
+ class RedoExpression < UndoExpression
88
146
 
89
- #
90
- # apply / reply
147
+ names :redo
91
148
 
92
- def apply (workitem)
93
- end
149
+ def process_tag (tag)
94
150
 
95
- #def reply (workitem)
96
- #end
151
+ ldebug do
152
+ "process_tag() #{fei.to_debug_s} to redo #{tag.fei.to_debug_s}"
153
+ end
154
+
155
+ #
156
+ # cancel
157
+
158
+ get_expression_pool.cancel(tag.fei)
159
+
160
+ #
161
+ # [re]apply
162
+
163
+ tag.raw_expression.application_context = @application_context
164
+
165
+ get_expression_pool.apply(tag.raw_expression, tag.workitem)
166
+ end
97
167
  end
98
168
 
99
169
  end
@@ -0,0 +1,190 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2006-2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # "made in Japan"
38
+ #
39
+ # John Mettraux at openwfe.org
40
+ #
41
+
42
+ require 'openwfe/workitem'
43
+ require 'openwfe/flowexpressionid'
44
+ require 'openwfe/expressions/flowexpression'
45
+
46
+
47
+ #
48
+ # expressions like 'set' and 'unset' and their utility methods
49
+ #
50
+
51
+ module OpenWFE
52
+
53
+ #
54
+ # A parent class for the 'equals' expression.
55
+ #
56
+ class ComparisonExpression < FlowExpression
57
+
58
+ def apply (workitem)
59
+
60
+ #
61
+ # preparing for children handling... later...
62
+ #
63
+
64
+ reply workitem
65
+ end
66
+
67
+ def reply (workitem)
68
+
69
+ value_a, value_b = lookup_values workitem
70
+
71
+ result = compare value_a, value_b
72
+
73
+ ldebug { "apply() result is '#{result}' #{@fei.to_debug_s}" }
74
+
75
+ workitem.set_result result
76
+
77
+ reply_to_parent workitem
78
+ end
79
+
80
+ protected
81
+
82
+ #
83
+ # The bulk job of looking up the values to compare
84
+ #
85
+ def lookup_values (workitem)
86
+
87
+ value_a = lookup_value workitem
88
+ value_b = lookup_value workitem, 'other'
89
+
90
+ value_c = lookup_variable_or_field workitem
91
+
92
+ if not value_a and value_b
93
+ value_a = value_c
94
+ elsif value_a and not value_b
95
+ value_b = value_c
96
+ end
97
+
98
+ [ value_a, value_b ]
99
+ end
100
+
101
+ #
102
+ # Returns the value pointed at by the variable attribute or by
103
+ # the field attribute, in that order.
104
+ #
105
+ def lookup_variable_or_field (workitem)
106
+
107
+ v = lookup_attribute :variable, workitem
108
+ return lookup_variable(v) if v
109
+
110
+ f = lookup_attribute :field, workitem
111
+ return workitem.attributes[f] if f
112
+
113
+ nil
114
+ end
115
+
116
+ #
117
+ # This method has to be implemented by extending classes
118
+ #
119
+ def compare (a, b)
120
+
121
+ raise "not yet implemented : '#{@fei.expressionName}'"
122
+ end
123
+ end
124
+
125
+ #
126
+ # <equals/>
127
+ #
128
+ class EqualsExpression < ComparisonExpression
129
+
130
+ names :equals
131
+
132
+ protected
133
+
134
+ def compare (a, b)
135
+ #ldebug { "compare() #{fei.to_debug_s}" }
136
+ #ldebug { "compare() '#{a}' == '#{b}'" }
137
+ return a == b
138
+ end
139
+ end
140
+
141
+ #
142
+ # This expression class actually implements 'defined' and 'undefined'.
143
+ #
144
+ class DefinedExpression < FlowExpression
145
+
146
+ names :defined, :undefined
147
+
148
+ def apply (workitem)
149
+
150
+ fname = lookup_attribute(:field_value, workitem)
151
+ fname = lookup_attribute(:field, workitem) unless fname
152
+
153
+ fmatch = lookup_attribute(:field_match, workitem)
154
+
155
+ vname = lookup_attribute(:variable_value, workitem)
156
+ vname = lookup_attribute(:variable, workitem) unless vname
157
+
158
+ result = if fname
159
+ workitem.has_attribute? fname
160
+ elsif vname
161
+ lookup_variable(vname) != nil
162
+ elsif fmatch
163
+ field_match?(workitem, fmatch)
164
+ else
165
+ false
166
+ end
167
+
168
+ result = ( ! result) if result != nil \
169
+ if fei.expression_name == 'undefined'
170
+
171
+ workitem.set_result result
172
+
173
+ reply_to_parent workitem
174
+ end
175
+
176
+ protected
177
+
178
+ def field_match? (workitem, regex)
179
+
180
+ workitem.attributes.each do |k, v|
181
+
182
+ return true if k.match(regex)
183
+ end
184
+
185
+ false
186
+ end
187
+ end
188
+
189
+ end
190
+
@@ -49,8 +49,29 @@ require 'openwfe/expressions/flowexpression'
49
49
  module OpenWFE
50
50
 
51
51
  #
52
- # The 'cursor' is much like a sequence, but you can go
53
- # back and forth within it.
52
+ # This expression implementation gathers the 'f', 'q' and 'v' expressions,
53
+ # along with their fullname 'field', 'variable' and 'quote'.
54
+ #
55
+ # These expressions place the value of the corresponding, field, variable
56
+ # or quoted (direct value) in the 'result' field of the current workitem.
57
+ #
58
+ # sequence do
59
+ #
60
+ # set :field => "f0", :value => "fox"
61
+ # set :variable => "v0", :value => "vixen"
62
+ #
63
+ # set :field => "f1" do
64
+ # v "v0"
65
+ # end
66
+ # set :variable => "v1" do
67
+ # f "f0"
68
+ # end
69
+ # set :variable => "v2" do
70
+ # f "f0"
71
+ # end
72
+ # end
73
+ #
74
+ # Well, this is perhaps not the best example.
54
75
  #
55
76
  class FqvExpression < FlowExpression
56
77
 
@@ -62,20 +83,17 @@ module OpenWFE
62
83
  def apply (workitem)
63
84
 
64
85
  name = @fei.expression_name[0, 1]
65
- text = OpenWFE::fetch_text_content(self, workitem)
86
+ text = fetch_text_content(workitem)
66
87
 
67
88
  method = MAP[name]
68
89
 
69
90
  result = self.send(method, text, workitem)
70
91
 
71
- OpenWFE::set_result(workitem, result) if result != nil
92
+ workitem.set_result(result) if result != nil
72
93
 
73
94
  reply_to_parent(workitem)
74
95
  end
75
96
 
76
- #def reply (workitem)
77
- #end
78
-
79
97
  protected
80
98
 
81
99
  MAP = {