ruote 2.1.11 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/CHANGELOG.txt +60 -0
  2. data/CREDITS.txt +22 -4
  3. data/LICENSE.txt +1 -1
  4. data/README.rdoc +6 -7
  5. data/Rakefile +58 -59
  6. data/TODO.txt +137 -65
  7. data/couch_url.txt +1 -0
  8. data/jruby_issue.txt +32 -0
  9. data/lib/ruote.rb +1 -1
  10. data/lib/ruote/context.rb +12 -10
  11. data/lib/ruote/engine.rb +280 -145
  12. data/lib/ruote/engine/process_error.rb +5 -5
  13. data/lib/ruote/engine/process_status.rb +47 -28
  14. data/lib/ruote/exp/command.rb +7 -10
  15. data/lib/ruote/exp/commanded.rb +2 -2
  16. data/lib/ruote/exp/condition.rb +130 -43
  17. data/lib/ruote/exp/fe_add_branches.rb +2 -2
  18. data/lib/ruote/exp/fe_apply.rb +1 -1
  19. data/lib/ruote/exp/fe_cancel_process.rb +3 -3
  20. data/lib/ruote/exp/fe_command.rb +3 -3
  21. data/lib/ruote/exp/fe_concurrence.rb +4 -4
  22. data/lib/ruote/exp/fe_concurrent_iterator.rb +17 -5
  23. data/lib/ruote/exp/fe_cron.rb +3 -3
  24. data/lib/ruote/exp/fe_cursor.rb +5 -5
  25. data/lib/ruote/exp/fe_define.rb +3 -3
  26. data/lib/ruote/exp/fe_echo.rb +3 -3
  27. data/lib/ruote/exp/fe_equals.rb +2 -2
  28. data/lib/ruote/exp/fe_error.rb +2 -2
  29. data/lib/ruote/exp/fe_filter.rb +519 -0
  30. data/lib/ruote/exp/fe_forget.rb +9 -2
  31. data/lib/ruote/exp/fe_given.rb +154 -0
  32. data/lib/ruote/exp/fe_if.rb +16 -13
  33. data/lib/ruote/exp/fe_inc.rb +3 -3
  34. data/lib/ruote/exp/fe_iterator.rb +4 -4
  35. data/lib/ruote/exp/fe_let.rb +75 -0
  36. data/lib/ruote/exp/fe_listen.rb +68 -12
  37. data/lib/ruote/exp/fe_lose.rb +110 -0
  38. data/lib/ruote/exp/fe_noop.rb +1 -1
  39. data/lib/ruote/exp/{fe_when.rb → fe_once.rb} +25 -21
  40. data/lib/ruote/exp/fe_participant.rb +14 -17
  41. data/lib/ruote/exp/fe_redo.rb +10 -6
  42. data/lib/ruote/exp/fe_ref.rb +1 -1
  43. data/lib/ruote/exp/fe_registerp.rb +112 -0
  44. data/lib/ruote/exp/fe_reserve.rb +3 -3
  45. data/lib/ruote/exp/fe_restore.rb +2 -2
  46. data/lib/ruote/exp/fe_save.rb +2 -2
  47. data/lib/ruote/exp/fe_sequence.rb +3 -4
  48. data/lib/ruote/exp/fe_set.rb +16 -7
  49. data/lib/ruote/exp/fe_subprocess.rb +23 -1
  50. data/lib/ruote/exp/fe_that.rb +92 -0
  51. data/lib/ruote/exp/fe_undo.rb +3 -3
  52. data/lib/ruote/exp/fe_unregisterp.rb +71 -0
  53. data/lib/ruote/exp/fe_wait.rb +2 -2
  54. data/lib/ruote/exp/flowexpression.rb +153 -78
  55. data/lib/ruote/exp/iterator.rb +2 -2
  56. data/lib/ruote/exp/merge.rb +2 -2
  57. data/lib/ruote/exp/ro_attributes.rb +14 -12
  58. data/lib/ruote/exp/ro_filters.rb +136 -0
  59. data/lib/ruote/exp/ro_persist.rb +51 -35
  60. data/lib/ruote/exp/ro_variables.rb +18 -27
  61. data/lib/ruote/fei.rb +73 -33
  62. data/lib/ruote/id/mnemo_wfid_generator.rb +1 -1
  63. data/lib/ruote/id/wfid_generator.rb +11 -4
  64. data/lib/ruote/log/default_history.rb +122 -0
  65. data/lib/ruote/log/pretty.rb +36 -8
  66. data/lib/ruote/log/storage_history.rb +37 -5
  67. data/lib/ruote/log/test_logger.rb +26 -24
  68. data/lib/ruote/log/wait_logger.rb +5 -3
  69. data/lib/ruote/part/block_participant.rb +22 -11
  70. data/lib/ruote/part/engine_participant.rb +6 -7
  71. data/lib/ruote/part/local_participant.rb +6 -12
  72. data/lib/ruote/part/no_op_participant.rb +4 -4
  73. data/lib/ruote/part/null_participant.rb +4 -4
  74. data/lib/ruote/part/smtp_participant.rb +4 -4
  75. data/lib/ruote/part/storage_participant.rb +40 -20
  76. data/lib/ruote/part/template.rb +4 -4
  77. data/lib/ruote/participant.rb +0 -1
  78. data/lib/ruote/{parser.rb → reader.rb} +30 -25
  79. data/lib/ruote/{parser → reader}/ruby_dsl.rb +28 -11
  80. data/lib/ruote/{parser → reader}/xml.rb +6 -5
  81. data/lib/ruote/receiver/base.rb +35 -13
  82. data/lib/ruote/storage/base.rb +20 -18
  83. data/lib/ruote/storage/composite_storage.rb +10 -10
  84. data/lib/ruote/storage/fs_storage.rb +17 -10
  85. data/lib/ruote/storage/hash_storage.rb +29 -18
  86. data/lib/ruote/svc/dispatch_pool.rb +41 -14
  87. data/lib/ruote/svc/dollar_sub.rb +50 -17
  88. data/lib/ruote/svc/error_handler.rb +19 -11
  89. data/lib/ruote/svc/expression_map.rb +4 -4
  90. data/lib/ruote/svc/participant_list.rb +105 -100
  91. data/lib/ruote/svc/tracker.rb +58 -18
  92. data/lib/ruote/svc/treechecker.rb +51 -24
  93. data/lib/ruote/tree_dot.rb +4 -4
  94. data/lib/ruote/util/filter.rb +440 -0
  95. data/lib/ruote/util/hashdot.rb +4 -4
  96. data/lib/ruote/util/look.rb +2 -6
  97. data/lib/ruote/util/lookup.rb +9 -7
  98. data/lib/ruote/util/misc.rb +40 -8
  99. data/lib/ruote/util/ometa.rb +1 -1
  100. data/lib/ruote/util/serializer.rb +4 -4
  101. data/lib/ruote/util/subprocess.rb +29 -9
  102. data/lib/ruote/util/time.rb +4 -4
  103. data/lib/ruote/util/tree.rb +3 -3
  104. data/lib/ruote/version.rb +2 -2
  105. data/lib/ruote/worker.rb +55 -32
  106. data/lib/ruote/workitem.rb +64 -11
  107. data/ruote.gemspec +31 -302
  108. data/test/bm/launch_bench.rb +37 -0
  109. data/test/functional/base.rb +60 -18
  110. data/test/functional/concurrent_base.rb +2 -2
  111. data/test/functional/ct_0_concurrence.rb +1 -1
  112. data/test/functional/ct_1_iterator.rb +1 -1
  113. data/test/functional/ct_2_cancel.rb +1 -1
  114. data/test/functional/eft_0_process_definition.rb +2 -2
  115. data/test/functional/eft_10_cancel_process.rb +1 -1
  116. data/test/functional/eft_11_wait.rb +19 -11
  117. data/test/functional/eft_12_listen.rb +79 -13
  118. data/test/functional/eft_13_iterator.rb +13 -10
  119. data/test/functional/eft_14_cursor.rb +98 -9
  120. data/test/functional/eft_15_loop.rb +6 -4
  121. data/test/functional/eft_16_if.rb +12 -0
  122. data/test/functional/eft_18_concurrent_iterator.rb +31 -32
  123. data/test/functional/eft_19_reserve.rb +4 -4
  124. data/test/functional/eft_1_echo.rb +9 -0
  125. data/test/functional/eft_20_save.rb +4 -4
  126. data/test/functional/{eft_28_when.rb → eft_28_once.rb} +33 -7
  127. data/test/functional/eft_30_ref.rb +17 -2
  128. data/test/functional/eft_31_registerp.rb +130 -0
  129. data/test/functional/eft_32_lose.rb +93 -0
  130. data/test/functional/eft_33_let.rb +31 -0
  131. data/test/functional/eft_34_given.rb +123 -0
  132. data/test/functional/eft_35_filter.rb +269 -0
  133. data/test/functional/eft_3_participant.rb +4 -6
  134. data/test/functional/eft_4_set.rb +16 -2
  135. data/test/functional/eft_5_subprocess.rb +2 -4
  136. data/test/functional/eft_6_concurrence.rb +29 -29
  137. data/test/functional/eft_8_undo.rb +39 -3
  138. data/test/functional/eft_9_redo.rb +94 -2
  139. data/test/functional/ft_10_dollar.rb +81 -2
  140. data/test/functional/ft_11_recursion.rb +13 -17
  141. data/test/functional/ft_12_launchitem.rb +9 -5
  142. data/test/functional/ft_13_variables.rb +7 -9
  143. data/test/functional/ft_14_re_apply.rb +6 -9
  144. data/test/functional/ft_15_timeout.rb +18 -18
  145. data/test/functional/ft_16_participant_params.rb +1 -3
  146. data/test/functional/ft_17_conditional.rb +25 -2
  147. data/test/functional/ft_18_kill.rb +65 -12
  148. data/test/functional/ft_1_process_status.rb +147 -71
  149. data/test/functional/ft_20_storage_participant.rb +0 -1
  150. data/test/functional/ft_21_forget.rb +82 -1
  151. data/test/functional/{ft_24_block_participants.rb → ft_24_block_participant.rb} +42 -11
  152. data/test/functional/ft_25_receiver.rb +47 -17
  153. data/test/functional/{ft_26_participant_timeout.rb → ft_26_participant_rtimeout.rb} +56 -19
  154. data/test/functional/ft_29_part_template.rb +6 -5
  155. data/test/functional/ft_2_errors.rb +21 -37
  156. data/test/functional/ft_30_smtp_participant.rb +1 -1
  157. data/test/functional/ft_31_part_blocking.rb +8 -6
  158. data/test/functional/ft_34_cursor_rewind.rb +13 -10
  159. data/test/functional/ft_35_add_service.rb +1 -1
  160. data/test/functional/ft_36_storage_history.rb +24 -1
  161. data/test/functional/ft_37_default_history.rb +109 -0
  162. data/test/functional/ft_38_participant_more.rb +10 -10
  163. data/test/functional/ft_39_wait_for.rb +12 -9
  164. data/test/functional/ft_3_participant_registration.rb +111 -32
  165. data/test/functional/ft_40_wait_logger.rb +2 -1
  166. data/test/functional/ft_41_participants.rb +30 -4
  167. data/test/functional/ft_43_participant_on_reply.rb +6 -23
  168. data/test/functional/ft_45_participant_accept.rb +4 -4
  169. data/test/functional/ft_46_launch_single.rb +36 -2
  170. data/test/functional/ft_47_wfid_generator.rb +54 -0
  171. data/test/functional/ft_48_lose.rb +112 -0
  172. data/test/functional/ft_49_engine_on_error.rb +201 -0
  173. data/test/functional/ft_4_cancel.rb +66 -6
  174. data/test/functional/ft_50_engine_config.rb +22 -0
  175. data/test/functional/ft_51_misc.rb +67 -0
  176. data/test/functional/ft_52_case.rb +134 -0
  177. data/test/functional/ft_53_engine_on_terminate.rb +95 -0
  178. data/test/functional/ft_54_patterns.rb +104 -0
  179. data/test/functional/{ft_37_engine_participant.rb → ft_55_engine_participant.rb} +4 -5
  180. data/test/functional/ft_56_filter_attribute.rb +259 -0
  181. data/test/functional/ft_5_on_error.rb +77 -30
  182. data/test/functional/ft_6_on_cancel.rb +66 -11
  183. data/test/functional/ft_7_tags.rb +94 -5
  184. data/test/functional/ft_8_participant_consumption.rb +36 -5
  185. data/test/functional/ft_9_subprocesses.rb +10 -10
  186. data/test/functional/rt_1_listen.rb +3 -3
  187. data/test/functional/{rt_3_when.rb → rt_3_once.rb} +4 -4
  188. data/test/functional/storage_helper.rb +15 -13
  189. data/test/functional/test.rb +1 -3
  190. data/test/test_helper.rb +0 -8
  191. data/test/unit/storage.rb +154 -10
  192. data/test/unit/{ut_0_ruby_parser.rb → ut_0_ruby_reader.rb} +61 -11
  193. data/test/unit/ut_11_lookup.rb +7 -0
  194. data/test/unit/ut_13_serializer.rb +1 -1
  195. data/test/unit/ut_15_util.rb +23 -0
  196. data/test/unit/{ut_16_parser.rb → ut_16_reader.rb} +11 -13
  197. data/test/unit/ut_1_fei.rb +57 -10
  198. data/test/unit/ut_20_composite_storage.rb +25 -11
  199. data/test/unit/ut_21_participant_list.rb +47 -0
  200. data/test/unit/ut_22_filter.rb +903 -0
  201. data/test/unit/ut_3_wait_logger.rb +2 -6
  202. data/test/unit/ut_6_condition.rb +164 -17
  203. data/test/unit/ut_7_workitem.rb +28 -0
  204. data/test/unit/ut_8_tree_to_dot.rb +1 -1
  205. data/test/unit/{ut_9_xml_parser.rb → ut_9_xml_reader.rb} +5 -5
  206. metadata +108 -84
  207. data/.gitignore +0 -4
  208. data/examples/barley.rb +0 -391
  209. data/examples/flickr_report.rb +0 -107
  210. data/examples/pong.rb +0 -37
  211. data/examples/ruote_quickstart.rb +0 -43
  212. data/examples/web_first_page.rb +0 -68
  213. data/lib/ruote/part/hash_participant.rb +0 -91
  214. data/test/README.rdoc +0 -15
  215. data/test/functional/crunner.sh +0 -19
  216. data/test/pdef.xml +0 -7
  217. data/test/unit/ut_2_wfidgen.rb +0 -21
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -56,7 +56,7 @@ module Ruote::Exp
56
56
  split_list(lookup_val_prefix('on'))
57
57
  end
58
58
 
59
- def split_list (list)
59
+ def split_list(list)
60
60
 
61
61
  if list.is_a?(String)
62
62
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ module Ruote::Exp
41
41
  # in the target workitem. The name of this field is the child_id of the
42
42
  # source workitem (a string from '0' to '99999' and beyond)
43
43
  #
44
- def merge_workitems (index, target, source, type)
44
+ def merge_workitems(index, target, source, type)
45
45
 
46
46
  return source if type == 'override'
47
47
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,7 @@
26
26
  module Ruote::Exp
27
27
 
28
28
  #
29
- # Those methods are mixed in FlowExpression. They were put here to offload
29
+ # Those methods are added in FlowExpression. They were put here to offload
30
30
  # FlowExpression and especially, to gather them around their attribute topic.
31
31
  #
32
32
  class FlowExpression
@@ -34,7 +34,7 @@ module Ruote::Exp
34
34
  # Given a list of attribute names, returns the first attribute name for
35
35
  # which there is a value.
36
36
  #
37
- def has_attribute (*args)
37
+ def has_attribute(*args)
38
38
 
39
39
  args.each { |a| a = a.to_s; return a if attributes[a] != nil }
40
40
 
@@ -45,7 +45,7 @@ module Ruote::Exp
45
45
 
46
46
  # Looks up the value for attribute n.
47
47
  #
48
- def attribute (n, workitem=h.applied_workitem, options={})
48
+ def attribute(n, workitem=h.applied_workitem, options={})
49
49
 
50
50
  n = n.to_s
51
51
 
@@ -72,7 +72,7 @@ module Ruote::Exp
72
72
  # in the array list 'values'. If not, the default value is returned.
73
73
  # By default, the default value is the first element of 'values'.
74
74
  #
75
- def att (key, values, opts={})
75
+ def att(key, values, opts={})
76
76
 
77
77
  default = opts[:default] || values.first
78
78
 
@@ -92,7 +92,7 @@ module Ruote::Exp
92
92
  # prefix = 'on' => will lookup on, on_val, on_value, on_v, on_var,
93
93
  # on_variable, on_f, on_fld, on_field...
94
94
  #
95
- def lookup_val_prefix (prefix, att_options={})
95
+ def lookup_val_prefix(prefix, att_options={})
96
96
 
97
97
  lval(
98
98
  [ prefix ] + [ 'val', 'value' ].map { |s| "#{prefix}_#{s}" },
@@ -101,7 +101,7 @@ module Ruote::Exp
101
101
  att_options)
102
102
  end
103
103
 
104
- def lookup_val (att_options={})
104
+ def lookup_val(att_options={})
105
105
 
106
106
  lval(
107
107
  VV,
@@ -113,7 +113,7 @@ module Ruote::Exp
113
113
  # Returns a Hash containing all attributes set for an expression with
114
114
  # their values resolved.
115
115
  #
116
- def compile_atts (opts={})
116
+ def compile_atts(opts={})
117
117
 
118
118
  attributes.keys.inject({}) { |r, k|
119
119
  r[k] = attribute(k, h.applied_workitem, opts)
@@ -127,7 +127,7 @@ module Ruote::Exp
127
127
  #
128
128
  # set "f:${v:field_name}" => "${v:that_variable}"
129
129
  #
130
- def expand_atts (opts={})
130
+ def expand_atts(opts={})
131
131
 
132
132
  attributes.keys.inject({}) { |r, k|
133
133
  kk = @context.dollar_sub.s(k, self, h.applied_workitem)
@@ -148,7 +148,9 @@ module Ruote::Exp
148
148
  #
149
149
  # will yield 'alpha'.
150
150
  #
151
- def attribute_text (workitem=h.applied_workitem)
151
+ # Note : an empty text returns '', not the nil value.
152
+ #
153
+ def attribute_text(workitem=h.applied_workitem)
152
154
 
153
155
  text = attributes.keys.find { |k| attributes[k] == nil }
154
156
 
@@ -167,12 +169,12 @@ module Ruote::Exp
167
169
  #
168
170
  VV = %w[ val value ]
169
171
 
170
- def s_cartesian (a0, a1)
172
+ def s_cartesian(a0, a1)
171
173
 
172
174
  a0.inject([]) { |a, e0| a + a1.collect { |e1| "#{e0}_#{e1}" } }
173
175
  end
174
176
 
175
- def lval (vals, vars, flds, att_options)
177
+ def lval(vals, vars, flds, att_options)
176
178
 
177
179
  if k = has_att(*vals)
178
180
 
@@ -0,0 +1,136 @@
1
+ #--
2
+ # Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Ruote::Exp
27
+
28
+ #
29
+ # The methods about the :filter attribute are placed in FlowExpression
30
+ # from here.
31
+ #
32
+ class FlowExpression
33
+
34
+ protected
35
+
36
+ # The :filter attribute work is done here, at apply (in) and at reply (out).
37
+ #
38
+ def filter(workitem=nil)
39
+
40
+ filter = lookup_filter(workitem)
41
+
42
+ return unless filter
43
+
44
+ unless filter.is_a?(Array)
45
+ #
46
+ # filter is a participant
47
+
48
+ def filter.receive(wi); end
49
+ # making sure the participant never replies to the engine
50
+
51
+ hwi = workitem || h.applied_workitem
52
+
53
+ if filter.respond_to?(:filter)
54
+ hwi['fields'] = filter.filter(hwi['fields'], workitem ? 'out' : 'in')
55
+ else
56
+ hwi['fields']['__filter_direction__'] = workitem ? 'out' : 'in'
57
+ filter.consume(Ruote::Workitem.new(hwi))
58
+ end
59
+
60
+ hwi['fields'].delete('__filter_direction__')
61
+
62
+ return
63
+ end
64
+
65
+ #
66
+ # filter is a not a participnat
67
+
68
+ unless workitem # in
69
+
70
+ h.fields_pre_filter =
71
+ Rufus::Json.dup(h.applied_workitem['fields'])
72
+ h.applied_workitem['fields'] =
73
+ Ruote.filter(filter, h.applied_workitem['fields'], {})
74
+
75
+ else # out
76
+
77
+ workitem['fields'] =
78
+ Ruote.filter(
79
+ filter, workitem['fields'], :double_tilde => h.fields_pre_filter)
80
+ end
81
+ end
82
+
83
+ # Used by #filter, deals with the various ways to pass filters
84
+ # (directly, via a variable, via a participant, in and out, ...)
85
+ #
86
+ # Returns nil, if there is no filter. Raises an ArgumentError if the
87
+ # filter is not usable. Returns the instantiated participant if the
88
+ # filter points to one.
89
+ #
90
+ def lookup_filter(workitem)
91
+
92
+ f = attribute(:filter)
93
+
94
+ return nil unless f
95
+
96
+ 3.times { f = narrow_filter(f, workitem) }
97
+
98
+ raise ArgumentError.new(
99
+ "found no filter corresponding to '#{f}'"
100
+ ) unless f
101
+
102
+ f
103
+ end
104
+
105
+ # Called successively to dig for the filter (Array or Participant).
106
+ #
107
+ def narrow_filter(fi, workitem)
108
+
109
+ if fi.is_a?(Array) or fi.respond_to?(:consume) or fi.respond_to?(:filter)
110
+
111
+ fi
112
+
113
+ elsif fi.is_a?(Hash)
114
+
115
+ workitem ? fi['out'] || fi['reply'] : fi['in'] || fi['apply']
116
+
117
+ elsif fi.is_a?(String)
118
+
119
+ filter =
120
+ lookup_variable(fi) ||
121
+ @context.plist.lookup(fi, workitem || h.applied_workitem)
122
+
123
+ if filter.respond_to?(:consume) or filter.respond_to?(:filter)
124
+ (workitem || h.applied_workitem)['participant_name'] = fi
125
+ end
126
+
127
+ filter
128
+
129
+ else
130
+
131
+ nil
132
+ end
133
+ end
134
+ end
135
+ end
136
+
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -42,12 +42,11 @@ module Ruote::Exp
42
42
 
43
43
  r = @context.storage.put(@h, :update_rev => true)
44
44
 
45
- raise(
46
- "initial_persist failed for " +
47
- "#{Ruote.to_storage_id(h.fei)} #{tree.first}"
48
- ) if r != nil
45
+ #t = Thread.current.object_id.to_s[-3..-1]
46
+ #puts "+ per #{h.fei['expid']} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
47
+ #Ruote.p_caller('+ per')
49
48
 
50
- nil
49
+ raise_or_return('initial_persist failed', r)
51
50
  end
52
51
 
53
52
  def try_persist
@@ -55,8 +54,8 @@ module Ruote::Exp
55
54
  r = @context.storage.put(@h)
56
55
 
57
56
  #t = Thread.current.object_id.to_s[-3..-1]
58
- #puts "+ per #{h.fei['expid']} #{tree.first} #{h._rev} #{t} -> #{r.class}"
59
- #Ruote.p_caller('+ per') #if r != nil || h.fei['expid'] == '0_0'
57
+ #puts "+ per #{h.fei['expid']} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
58
+ #Ruote.p_caller('+ per')
60
59
 
61
60
  r
62
61
  end
@@ -66,8 +65,8 @@ module Ruote::Exp
66
65
  r = @context.storage.delete(@h)
67
66
 
68
67
  #t = Thread.current.object_id.to_s[-3..-1]
69
- #puts "- unp #{h.fei['expid']} #{tree.first} #{h._rev} #{t} -> #{r.class}"
70
- #Ruote.p_caller('- unp') #if r != nil || h.fei['expid'] == '0_0'
68
+ #puts "- unp #{h.fei['expid']} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
69
+ #Ruote.p_caller('- unp')
71
70
 
72
71
  return r if r
73
72
 
@@ -81,56 +80,73 @@ module Ruote::Exp
81
80
  nil
82
81
  end
83
82
 
84
- #--
85
- # duplication ahead
86
- #++
87
-
88
83
  def persist_or_raise
89
84
 
90
- r = try_persist
91
-
92
- raise(
93
- "persist failed for " +
94
- "#{Ruote.to_storage_id(h.fei)} #{tree.first} #{r.class}"
95
- ) if r
85
+ p_or_raise(true)
96
86
  end
97
87
 
98
88
  def unpersist_or_raise
99
89
 
100
- r = try_unpersist
101
-
102
- raise(
103
- "unpersist failed for " +
104
- "#{Ruote.to_storage_id(h.fei)} #{tree.first} #{r.class}"
105
- ) if r
90
+ p_or_raise(false)
106
91
  end
107
92
 
108
- alias :persist :persist_or_raise
109
- alias :unpersist :unpersist_or_raise
93
+ alias persist persist_or_raise
94
+ alias unpersist unpersist_or_raise
110
95
 
111
96
  def do_persist
112
97
 
113
- do_p(:persist)
98
+ do_p(true)
114
99
  end
115
100
 
116
101
  def do_unpersist
117
102
 
118
- do_p(:unpersist)
103
+ do_p(false)
119
104
  end
120
105
 
121
106
  protected
122
107
 
123
- def do_p (pers)
108
+ def raise_or_return(msg, r)
109
+
110
+ msg = msg.is_a?(String) ?
111
+ msg : (msg ? 'persist' : 'unpersist') + ' failed'
112
+
113
+ raise(
114
+ "#{msg} for " +
115
+ "#{Ruote.to_storage_id(h.fei)} #{tree[0]} #{tree[1].inspect} " +
116
+ 'r(' + (r == true ? 'gone' : "rev : #{r['_rev']}") + ')'
117
+ ) if r
118
+
119
+ r
120
+ end
121
+
122
+ # Does persist or unpersist, returns nothing in particular.
123
+ #
124
+ # Will raise a runtime error if it fails (ie if it happens, there
125
+ # is something wrong with the storage implementation or the engine).
126
+ #
127
+ def p_or_raise(pers)
128
+
129
+ r = pers ? try_persist : try_unpersist
130
+
131
+ raise_or_return(pers, r)
132
+ end
133
+
134
+ # Does persist or unpersist, if successful then return true. If the
135
+ # expression is gone, return false.
136
+ # If there is a 'fresher' version of the expression, re-attempt and return
137
+ # false.
138
+ #
139
+ def do_p(pers)
124
140
 
125
- case r = self.send("try_#{pers}")
141
+ case r = pers ? try_persist : try_unpersist
126
142
  when true
127
- false # don't go on
143
+ false # do not go on
128
144
  when Hash
129
145
  self.h = r
130
146
  self.send("do_#{@msg['action']}", @msg)
131
- false # don't go on
147
+ false # do not go on
132
148
  else
133
- true # success, please go on
149
+ true # success, do go on
134
150
  end
135
151
  end
136
152
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -52,7 +52,7 @@ module Ruote::Exp
52
52
  # Looks up the value of a variable in expression tree
53
53
  # (seen from a leaf, it looks more like a stack than a tree)
54
54
  #
55
- def lookup_variable (var, prefix=nil)
55
+ def lookup_variable(var, prefix=nil)
56
56
 
57
57
  var, prefix = split_prefix(var, prefix)
58
58
 
@@ -91,31 +91,20 @@ module Ruote::Exp
91
91
  # Sets a variable to a given value.
92
92
  # (will set at the appropriate level).
93
93
  #
94
- def set_variable (var, val)
94
+ def set_variable(var, val)
95
95
 
96
96
  fexp, v = locate_var(var)
97
97
 
98
- raise(
99
- ArgumentError.new("cannot set var at engine level : #{var}")
100
- ) if fexp.nil?
101
-
102
- fexp.un_set_variable(:set, v, val, true)
98
+ fexp.un_set_variable(:set, v, val, (fexp.h.fei != h.fei)) if fexp
103
99
  end
104
100
 
105
101
  # Unbinds a variables.
106
102
  #
107
- def unset_variable (var)
103
+ def unset_variable(var)
108
104
 
109
105
  fexp, v = locate_var(var)
110
106
 
111
- raise(
112
- ArgumentError.new("cannot set var at engine level : #{var}")
113
- ) if fexp.nil?
114
-
115
- should_persist = (fexp.h.fei != h.fei)
116
- # don't use a ticket when expression wants to modify its own vars
117
-
118
- fexp.un_set_variable(:unset, v, nil, should_persist)
107
+ fexp.un_set_variable(:unset, v, nil, (fexp.h.fei != h.fei)) if fexp
119
108
  end
120
109
 
121
110
  # TODO : redoc rewrite needed
@@ -123,7 +112,7 @@ module Ruote::Exp
123
112
  # This method is mostly used by the worker when looking up
124
113
  # a process name or participant name bound under a variable.
125
114
  #
126
- def iterative_var_lookup (k)
115
+ def iterative_var_lookup(k)
127
116
 
128
117
  v = lookup_variable(k)
129
118
 
@@ -138,7 +127,7 @@ module Ruote::Exp
138
127
  #
139
128
  # val should be nil in case of 'unset'.
140
129
  #
141
- def un_set_variable (op, var, val, should_persist)
130
+ def un_set_variable(op, var, val, should_persist)
142
131
 
143
132
  if op == :set
144
133
  Ruote.set(h.variables, var, val)
@@ -146,14 +135,12 @@ module Ruote::Exp
146
135
  Ruote.unset(h.variables, var)
147
136
  end
148
137
 
149
- return unless should_persist
150
-
151
- if r = try_persist # persist failed, have to retry
138
+ if should_persist && r = try_persist # persist failed, have to retry
152
139
 
153
140
  @h = r
154
141
  un_set_variable(op, var, val, true)
155
142
 
156
- else # success
143
+ else # success (even when should_persist == false)
157
144
 
158
145
  @context.storage.put_msg("variable_#{op}", 'var' => var, 'fei' => h.fei)
159
146
  end
@@ -164,7 +151,7 @@ module Ruote::Exp
164
151
  # Used by lookup_variable and set_variable to extract the
165
152
  # prefix in a variable name
166
153
  #
167
- def split_prefix (var, prefix)
154
+ def split_prefix(var, prefix)
168
155
 
169
156
  if prefix.nil?
170
157
  var = var.to_s
@@ -179,7 +166,7 @@ module Ruote::Exp
179
166
  # Returns the flow expression that owns a variable (or the one
180
167
  # that should own it) and the var without its potential / prefixes.
181
168
  #
182
- def locate_var (var, prefix=nil)
169
+ def locate_var(var, prefix=nil)
183
170
 
184
171
  var, prefix = split_prefix(var, prefix)
185
172
 
@@ -189,9 +176,13 @@ module Ruote::Exp
189
176
  # no prefix...
190
177
 
191
178
  return [ self, var ] if h.variables
192
- return parent.locate_var(var, prefix) if h.parent_id
193
179
 
194
- raise "uprooted var lookup, something went wrong"
180
+ if par = parent
181
+ return parent.locate_var(var, prefix) rescue nil
182
+ end
183
+
184
+ #raise "uprooted var lookup, something went wrong"
185
+ [ nil, nil ]
195
186
  end
196
187
  end
197
188
  end