pione 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +2 -1
  2. data/History.txt +11 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/bin/pione-log +5 -0
  6. data/example/CountChar/CountChar.pione +1 -1
  7. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
  8. data/lib/pione.rb +14 -35
  9. data/lib/pione/agent/input-generator.rb +38 -40
  10. data/lib/pione/agent/logger.rb +52 -19
  11. data/lib/pione/agent/rule-provider.rb +5 -8
  12. data/lib/pione/agent/task-worker.rb +25 -32
  13. data/lib/pione/agent/tuple-space-client.rb +22 -14
  14. data/lib/pione/command.rb +21 -0
  15. data/lib/pione/command/basic-command.rb +267 -84
  16. data/lib/pione/command/child-process.rb +21 -18
  17. data/lib/pione/command/daemon-process.rb +9 -8
  18. data/lib/pione/command/front-owner-command.rb +8 -25
  19. data/lib/pione/command/pione-broker.rb +27 -24
  20. data/lib/pione/command/pione-clean.rb +6 -6
  21. data/lib/pione/command/pione-client.rb +143 -128
  22. data/lib/pione/command/pione-log.rb +61 -0
  23. data/lib/pione/command/pione-relay-account-db.rb +40 -38
  24. data/lib/pione/command/pione-relay-client-db.rb +38 -42
  25. data/lib/pione/command/pione-relay.rb +19 -20
  26. data/lib/pione/command/pione-syntax-checker.rb +70 -45
  27. data/lib/pione/command/pione-task-worker.rb +56 -66
  28. data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
  29. data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
  30. data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
  31. data/lib/pione/location.rb +10 -0
  32. data/lib/pione/location/basic-location.rb +272 -0
  33. data/lib/pione/location/dropbox-location.rb +139 -0
  34. data/lib/pione/location/ftp-location.rb +156 -0
  35. data/lib/pione/location/local-location.rb +116 -0
  36. data/lib/pione/log.rb +10 -0
  37. data/lib/pione/log/domain-info.rb +72 -0
  38. data/lib/pione/log/process-log.rb +176 -0
  39. data/lib/pione/log/process-record.rb +189 -0
  40. data/lib/pione/log/xes-log.rb +105 -0
  41. data/lib/pione/model/assignment.rb +88 -80
  42. data/lib/pione/model/binary-operator.rb +74 -68
  43. data/lib/pione/model/block.rb +218 -207
  44. data/lib/pione/model/boolean.rb +123 -112
  45. data/lib/pione/model/call-rule.rb +72 -65
  46. data/lib/pione/model/data-expr.rb +596 -290
  47. data/lib/pione/model/float.rb +108 -103
  48. data/lib/pione/model/integer.rb +133 -129
  49. data/lib/pione/model/message.rb +79 -72
  50. data/lib/pione/model/package.rb +42 -38
  51. data/lib/pione/model/parameters.rb +265 -236
  52. data/lib/pione/model/rule-expr.rb +247 -242
  53. data/lib/pione/model/rule-io.rb +137 -133
  54. data/lib/pione/model/rule.rb +307 -292
  55. data/lib/pione/model/string.rb +110 -99
  56. data/lib/pione/model/variable-table.rb +300 -271
  57. data/lib/pione/model/variable.rb +88 -83
  58. data/lib/pione/option.rb +13 -0
  59. data/lib/pione/option/child-process-option.rb +19 -0
  60. data/lib/pione/{command-option → option}/common-option.rb +6 -5
  61. data/lib/pione/option/option-interface.rb +73 -0
  62. data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
  63. data/lib/pione/option/task-worker-owner-option.rb +24 -0
  64. data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
  65. data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
  66. data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
  67. data/lib/pione/parser/common-parser.rb +3 -2
  68. data/lib/pione/parser/expr-parser.rb +6 -1
  69. data/lib/pione/patch/em-ftpd-patch.rb +21 -0
  70. data/lib/pione/patch/rinda-patch.rb +31 -23
  71. data/lib/pione/rule-handler/action-handler.rb +35 -25
  72. data/lib/pione/rule-handler/basic-handler.rb +92 -18
  73. data/lib/pione/rule-handler/flow-handler.rb +104 -98
  74. data/lib/pione/rule-handler/root-handler.rb +11 -0
  75. data/lib/pione/system/common.rb +10 -0
  76. data/lib/pione/system/file-cache.rb +103 -84
  77. data/lib/pione/system/global.rb +67 -12
  78. data/lib/pione/system/init.rb +20 -0
  79. data/lib/pione/transformer/expr-transformer.rb +6 -1
  80. data/lib/pione/tuple-space/data-finder.rb +33 -6
  81. data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
  82. data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
  83. data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
  84. data/lib/pione/tuple-space/update-criteria.rb +8 -7
  85. data/lib/pione/tuple/base-location-tuple.rb +9 -0
  86. data/lib/pione/tuple/basic-tuple.rb +7 -7
  87. data/lib/pione/tuple/data-tuple.rb +5 -2
  88. data/lib/pione/tuple/lift-tuple.rb +14 -0
  89. data/lib/pione/tuple/rule-tuple.rb +1 -1
  90. data/lib/pione/tuple/task-tuple.rb +5 -1
  91. data/lib/pione/version.rb +1 -1
  92. data/pione.gemspec +5 -1
  93. data/test/location/spec_basic-location.rb +35 -0
  94. data/test/location/spec_ftp-location.rb +100 -0
  95. data/test/location/spec_local-location.rb +99 -0
  96. data/test/log/data/sample.log +1003 -0
  97. data/test/log/spec_xes-log.rb +11 -0
  98. data/test/model/spec_data-expr.rb +249 -6
  99. data/test/model/spec_data-expr.yml +45 -0
  100. data/test/parser/spec_expr-parser.yml +4 -0
  101. data/test/spec_data-finder.rb +13 -7
  102. data/test/spec_data-finder.yml +42 -13
  103. data/test/system/spec_file-cache.rb +39 -0
  104. data/test/test-util.rb +226 -1
  105. data/test/transformer/spec_expr-transformer.rb +12 -1
  106. metadata +107 -24
  107. data/bin/pione-search-log +0 -30
  108. data/lib/pione/command-option/basic-option.rb +0 -42
  109. data/lib/pione/command-option/child-process-option.rb +0 -17
  110. data/lib/pione/command-option/daemon-option.rb +0 -12
  111. data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
  112. data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
  113. data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
  114. data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
  115. data/lib/pione/resource/basic-resource.rb +0 -92
  116. data/lib/pione/resource/dropbox-resource.rb +0 -106
  117. data/lib/pione/resource/ftp.rb +0 -84
  118. data/lib/pione/resource/local.rb +0 -113
  119. data/lib/pione/tuple/base-uri-tuple.rb +0 -9
  120. data/lib/pione/tuple/shift-tuple.rb +0 -13
  121. data/lib/pione/util/log.rb +0 -79
  122. data/test/spec_resource.rb +0 -73
@@ -1,166 +1,170 @@
1
- module Pione::Model
2
- # RuleIOElement is a special PIONE model object for matched data name result.
3
- class RuleIOElement < BasicModel
4
- set_pione_model_type TypeRuleIOElement
5
-
6
- attr_accessor :name
7
- attr_accessor :uri
8
- attr_accessor :match
9
-
10
- # Creates a element with the name.
11
- # @param [PioneString, String] name
12
- # element name
13
- def initialize(name)
14
- @name = name.kind_of?(PioneString) ? name : PioneString.new(name)
15
- @uri = PioneString.new("")
16
- @match = PioneList.new()
17
- end
1
+ module Pione
2
+ module Model
3
+ # RuleIOElement is a special PIONE model object for matched data name result.
4
+ class RuleIOElement < BasicModel
5
+ set_pione_model_type TypeRuleIOElement
6
+
7
+ attr_accessor :name
8
+ attr_accessor :uri
9
+ attr_accessor :match
10
+
11
+ # Create a element with the name.
12
+ #
13
+ # @param name [PioneString, String]
14
+ # element name
15
+ def initialize(name)
16
+ @name = name.kind_of?(PioneString) ? name : PioneString.new(name)
17
+ @uri = PioneString.new("")
18
+ @match = PioneList.new()
19
+ end
18
20
 
19
- # @api private
20
- def textize
21
- "rule-io-element(%s,%s,%s)" % [@name.to_ruby, @uri.textize, @match.textize]
22
- end
21
+ # @api private
22
+ def textize
23
+ "rule-io-element(%s,%s,%s)" % [@name.to_ruby, @uri.textize, @match.textize]
24
+ end
23
25
 
24
- # @api private
25
- def uri=(uri)
26
- @uri = uri.to_pione
27
- end
26
+ # @api private
27
+ def uri=(uri)
28
+ @uri = uri.to_pione
29
+ end
28
30
 
29
- # @api private
30
- def ==(other)
31
- return false unless other.kind_of?(self.class)
32
- @name == other.name && @uri == other.uri && @match == other.match
33
- end
31
+ # @api private
32
+ def ==(other)
33
+ return false unless other.kind_of?(self.class)
34
+ @name == other.name && @uri == other.uri && @match == other.match
35
+ end
36
+ alias :eql? :"=="
34
37
 
35
- alias :eql? :"=="
38
+ # @api private
39
+ def hash
40
+ @value.hash
41
+ end
36
42
 
37
- # @api private
38
- def hash
39
- @value.hash
40
- end
43
+ #
44
+ # pione method
45
+ #
41
46
 
42
- #
43
- # pione method
44
- #
47
+ define_pione_method("==", [TypeRuleIOElement], TypeBoolean) do |rec, other|
48
+ PioneBoolean.new(rec.values == other.values)
49
+ end
45
50
 
46
- define_pione_method("==", [TypeRuleIOElement], TypeBoolean) do |rec, other|
47
- PioneBoolean.new(rec.values == other.values)
48
- end
51
+ define_pione_method("!=", [TypeRuleIOElement], TypeBoolean) do |rec, other|
52
+ PioneBoolean.not(rec.call_pione_method("==", other))
53
+ end
49
54
 
50
- define_pione_method("!=", [TypeRuleIOElement], TypeBoolean) do |rec, other|
51
- PioneBoolean.not(rec.call_pione_method("==", other))
52
- end
55
+ define_pione_method("uri", [], TypeString) do |rec, other|
56
+ PioneString.new(rec.uri)
57
+ end
53
58
 
54
- define_pione_method("uri", [], TypeString) do |rec, other|
55
- PioneString.new(rec.uri)
56
- end
59
+ define_pione_method("match", [], TypeList.new(TypeString)) do |rec|
60
+ rec.match
61
+ end
57
62
 
58
- define_pione_method("match", [], TypeList.new(TypeString)) do |rec|
59
- rec.match
60
- end
63
+ define_pione_method("MATCH", [], TypeList.new(TypeString)) do |rec|
64
+ rec.call_pione_method("match")
65
+ end
61
66
 
62
- define_pione_method("MATCH", [], TypeList.new(TypeString)) do |rec|
63
- rec.call_pione_method("match")
64
- end
67
+ define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
68
+ rec.match[i.value-1]
69
+ end
65
70
 
66
- define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
67
- rec.match[i.value-1]
71
+ define_pione_method("as_string", [], TypeString) do |rec|
72
+ rec.name
73
+ end
68
74
  end
69
75
 
70
- define_pione_method("as_string", [], TypeString) do |rec|
71
- rec.name
72
- end
73
- end
76
+ # RuleIOList is a input or output list for RuleIOElement.
77
+ class RuleIOList < BasicModel
78
+ extend Forwardable
74
79
 
75
- # RuleIOList is a input or output list for RuleIOElement.
76
- class RuleIOList < BasicModel
77
- extend Forwardable
80
+ set_pione_model_type TypeRuleIOList
78
81
 
79
- set_pione_model_type TypeRuleIOList
82
+ attr_accessor :elements
83
+ def_delegators :@elements, :[], :size, :length
80
84
 
81
- attr_accessor :elements
82
- def_delegators :@elements, :[], :size, :length
83
-
84
- # Creates a list object.
85
- # @param [Array<RuleIOElement>] elts
86
- # list elements
87
- def initialize(elts = [])
88
- @elements = elts
89
- end
90
-
91
- # Returns new list which appended the element.
92
- # @param [RuleIOElement] elt
93
- # target element
94
- # @return [RuleIOList]
95
- # new list object that added the element
96
- def add(elt)
97
- unless elt.kind_of?(RuleIOElement) || elt.kind_of?(self.class)
98
- raise ArgumentError.new(elt)
85
+ # Create a list object.
86
+ #
87
+ # @param elts [Array<RuleIOElement>]
88
+ # list elements
89
+ def initialize(elts = [])
90
+ @elements = elts
99
91
  end
100
- self.class.new(@elements + [elt])
101
- end
102
92
 
103
- # Adds the element to this list.
104
- # @param [RuleIOElement] elt
105
- # target element
106
- # @return [void]
107
- def add!(elt)
108
- unless elt.kind_of?(RuleIOElement) || elt.kinf_of?(self.class)
109
- raise ArgumentError.new(elt)
93
+ # Return new list which appended the element.
94
+ #
95
+ # @param elt [RuleIOElement]
96
+ # target element
97
+ # @return [RuleIOList]
98
+ # new list object that added the element
99
+ def add(elt)
100
+ unless elt.kind_of?(RuleIOElement) || elt.kind_of?(self.class)
101
+ raise ArgumentError.new(elt)
102
+ end
103
+ self.class.new(@elements + [elt])
110
104
  end
111
- @elements << elt
112
- end
113
105
 
114
- # @api private
115
- def textize
116
- "rule-io-list(%s)" % @elements.map{|elt|
117
- elt.textize
118
- }.join(DataExpr::SEPARATOR)
119
- end
106
+ # Add the element to this list.
107
+ #
108
+ # @param elt [RuleIOElement]
109
+ # target element
110
+ # @return [void]
111
+ def add!(elt)
112
+ unless elt.kind_of?(RuleIOElement) || elt.kinf_of?(self.class)
113
+ raise ArgumentError.new(elt)
114
+ end
115
+ @elements << elt
116
+ end
120
117
 
121
- # @api private
122
- def ==(other)
123
- return false unless other.kind_of?(self.class)
124
- @elements == other.elements
125
- end
118
+ # @api private
119
+ def textize
120
+ "rule-io-list(%s)" % @elements.map{|elt|
121
+ elt.textize
122
+ }.join(DataExpr::SEPARATOR)
123
+ end
126
124
 
127
- alias :eql? :"=="
125
+ # @api private
126
+ def ==(other)
127
+ return false unless other.kind_of?(self.class)
128
+ @elements == other.elements
129
+ end
130
+ alias :eql? :"=="
128
131
 
129
- # @api private
130
- def hash
131
- @elements.hash
132
- end
132
+ # @api private
133
+ def hash
134
+ @elements.hash
135
+ end
133
136
 
134
- #
135
- # pione method
136
- #
137
+ #
138
+ # pione method
139
+ #
137
140
 
138
- define_pione_method("==", [TypeRuleIOList], TypeBoolean) do |rec, other|
139
- PioneBoolean.new(rec.values == other.values)
140
- end
141
+ define_pione_method("==", [TypeRuleIOList], TypeBoolean) do |rec, other|
142
+ PioneBoolean.new(rec.values == other.values)
143
+ end
141
144
 
142
- define_pione_method("!=", [TypeRuleIOList], TypeBoolean) do |rec, other|
143
- PioneBoolean.not(rec.call_pione_method("==", other))
144
- end
145
+ define_pione_method("!=", [TypeRuleIOList], TypeBoolean) do |rec, other|
146
+ PioneBoolean.not(rec.call_pione_method("==", other))
147
+ end
145
148
 
146
- define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
147
- rec.elements[i.value-1]
148
- end
149
+ define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
150
+ rec.elements[i.value-1]
151
+ end
149
152
 
150
- define_pione_method("join", [TypeString], TypeString) do |rec, connective|
151
- PioneString.new(
152
- rec.elements.map{|elt|
153
- elt.call_pione_method("as_string").to_ruby
154
- }.join(connective.to_ruby)
155
- )
156
- end
153
+ define_pione_method("join", [TypeString], TypeString) do |rec, connective|
154
+ PioneString.new(
155
+ rec.elements.map{|elt|
156
+ elt.call_pione_method("as_string").to_ruby
157
+ }.join(connective.to_ruby)
158
+ )
159
+ end
157
160
 
158
- define_pione_method("as_string", [], TypeString) do |rec|
159
- PioneString.new(
160
- rec.elements.map{|elt|
161
- elt.call_pione_method("as_string").to_ruby
162
- }.join(DataExpr::SEPARATOR)
163
- )
161
+ define_pione_method("as_string", [], TypeString) do |rec|
162
+ PioneString.new(
163
+ rec.elements.map{|elt|
164
+ elt.call_pione_method("as_string").to_ruby
165
+ }.join(DataExpr::SEPARATOR)
166
+ )
167
+ end
164
168
  end
165
169
  end
166
170
  end
@@ -1,330 +1,345 @@
1
- module Pione::Model
2
- # RuleCondition represents rule condition.
3
- class RuleCondition < BasicModel
4
- # the value of attribute inputs
5
- #
6
- # @return [Array<DataExpr, Array<DataExpr>>]
7
- # rule inputs condition
8
- attr_reader :inputs
9
-
10
- # the value of attribute outputs
11
- #
12
- # @return [Array<DataExpr, Array<DataExpr>>]
13
- # rule outputs condition
14
- attr_reader :outputs
15
-
16
- # the value of attribute params
17
- #
18
- # @return [Parameters]
19
- # rule parameters table
20
- attr_reader :params
21
-
22
- # the value of attribute features
23
- #
24
- # @return [Feature]
25
- # rule feature condition
26
- attr_reader :features
27
-
28
- # input ticket expression
29
- #
30
- # @return [TicketExpr]
31
- # input ticket expression
32
- attr_reader :input_ticket_expr
33
-
34
- # output ticket expression
35
- #
36
- # @return [TicketExpr]
37
- # output ticket
38
- attr_reader :output_ticket_expr
39
-
40
- # Create a rule condition.
41
- #
42
- # @param inputs [Array<DataExpr, Array<DataExpr>>]
43
- # rule inputs
44
- # @param outputs [Array<DataExpr, Array<DataExpr>>]
45
- # rule outputs
46
- # @param params [Parameters]
47
- # rule parameters
48
- # @param features [Feature]
49
- # rule features
50
- # @param input_ticket_expr [TicketExpr]
51
- # input ticket expression
52
- # @param output_ticket_expr [TicketExpr]
53
- # output ticket expression
54
- def initialize(inputs, outputs, params, features, input_ticket_expr, output_ticket_expr)
55
- check_argument_type(params, Parameters)
56
- check_argument_type(features, Feature::Expr)
57
- @inputs = inputs
58
- @outputs = outputs
59
- @params = params
60
- @features = features
61
- @input_ticket_expr = input_ticket_expr
62
- @output_ticket_expr = output_ticket_expr
63
- super()
64
- end
65
-
66
- # Return true if the condition includes variable.
67
- #
68
- # @return [Boolean]
69
- # true if the condition includes variable, or false
70
- def include_variable?
71
- [ @inputs.any? {|input| input.include_variable?},
72
- @outputs.any? {|output| output.include_variable?},
73
- @params.include_variable?,
74
- @features.include_variable?,
75
- @input_tickets.any? {|ticket| ticket.include_variable?},
76
- @output_tickets.any? {|ticket| ticket.include_variable?}
77
- ].any?
78
- end
1
+ module Pione
2
+ module Model
3
+ # RuleCondition represents rule condition.
4
+ class RuleCondition < BasicModel
5
+ # the value of attribute inputs
6
+ #
7
+ # @return [Array<DataExpr, Array<DataExpr>>]
8
+ # rule inputs condition
9
+ attr_reader :inputs
10
+
11
+ # the value of attribute outputs
12
+ #
13
+ # @return [Array<DataExpr, Array<DataExpr>>]
14
+ # rule outputs condition
15
+ attr_reader :outputs
16
+
17
+ # the value of attribute params
18
+ #
19
+ # @return [Parameters]
20
+ # rule parameters table
21
+ attr_reader :params
22
+
23
+ # the value of attribute features
24
+ #
25
+ # @return [Feature]
26
+ # rule feature condition
27
+ attr_reader :features
28
+
29
+ # input ticket expression
30
+ #
31
+ # @return [TicketExpr]
32
+ # input ticket expression
33
+ attr_reader :input_ticket_expr
34
+
35
+ # output ticket expression
36
+ #
37
+ # @return [TicketExpr]
38
+ # output ticket
39
+ attr_reader :output_ticket_expr
40
+
41
+ # Create a rule condition.
42
+ #
43
+ # @param inputs [Array<DataExpr, Array<DataExpr>>]
44
+ # rule inputs
45
+ # @param outputs [Array<DataExpr, Array<DataExpr>>]
46
+ # rule outputs
47
+ # @param params [Parameters]
48
+ # rule parameters
49
+ # @param features [Feature]
50
+ # rule features
51
+ # @param input_ticket_expr [TicketExpr]
52
+ # input ticket expression
53
+ # @param output_ticket_expr [TicketExpr]
54
+ # output ticket expression
55
+ def initialize(inputs, outputs, params, features, input_ticket_expr, output_ticket_expr)
56
+ check_argument_type(params, Parameters)
57
+ check_argument_type(features, Feature::Expr)
58
+ @inputs = inputs
59
+ @outputs = outputs
60
+ @params = params
61
+ @features = features
62
+ @input_ticket_expr = input_ticket_expr
63
+ @output_ticket_expr = output_ticket_expr
64
+ super()
65
+ end
79
66
 
80
- # @api private
81
- def ==(other)
82
- return false unless @inputs == other.inputs
83
- return false unless @outputs == other.outputs
84
- return false unless @params == other.params
85
- return false unless @features == other.features
86
- return true
87
- end
67
+ # Return true if the condition includes variable.
68
+ #
69
+ # @return [Boolean]
70
+ # true if the condition includes variable, or false
71
+ def include_variable?
72
+ [ @inputs.any? {|input| input.include_variable?},
73
+ @outputs.any? {|output| output.include_variable?},
74
+ @params.include_variable?,
75
+ @features.include_variable?,
76
+ @input_tickets.any? {|ticket| ticket.include_variable?},
77
+ @output_tickets.any? {|ticket| ticket.include_variable?}
78
+ ].any?
79
+ end
88
80
 
89
- # @api private
90
- alias :eql? :"=="
81
+ # @api private
82
+ def ==(other)
83
+ return false unless @inputs == other.inputs
84
+ return false unless @outputs == other.outputs
85
+ return false unless @params == other.params
86
+ return false unless @features == other.features
87
+ return true
88
+ end
89
+ alias :eql? :"=="
91
90
 
92
- # @api private
93
- def hash
94
- @inputs.hash + @outputs.hash + @params.hash + @features.hash
91
+ # @api private
92
+ def hash
93
+ @inputs.hash + @outputs.hash + @params.hash + @features.hash
94
+ end
95
95
  end
96
- end
97
96
 
98
- # Rule is a class for PIONE rule model.
99
- class Rule < BasicModel
100
- extend Forwardable
97
+ # Rule is a class for PIONE rule model.
98
+ class Rule < BasicModel
99
+ extend Forwardable
101
100
 
102
- # Returns rule type.
103
- def self.rule_type
104
- @rule_type
105
- end
101
+ # Returns rule type.
102
+ def self.rule_type
103
+ @rule_type
104
+ end
106
105
 
107
- # Returns the value of attribute expr.
108
- # @return [Array<DataExpr, Array<DataExpr>>]
109
- # rule inputs condition
110
- attr_reader :expr
111
-
112
- attr_reader :condition
113
- attr_reader :body
114
-
115
- def_delegators :@condition, :inputs, :outputs, :params, :features
116
- def_delegators :@condition, :input_ticket_expr, :output_ticket_expr
117
-
118
- # Creates a rule.
119
- # @param [RuleExpr] expr
120
- # rule expression
121
- # @param [RuleCondition] condition
122
- # rule condition
123
- # @param [Block] body
124
- # rule body block
125
- def initialize(expr, condition, body)
126
- @expr = expr
127
- @condition = condition
128
- @body = body
129
- end
106
+ # Return the value of attribute expr.
107
+ #
108
+ # @return [Array<DataExpr, Array<DataExpr>>]
109
+ # rule inputs condition
110
+ attr_reader :expr
111
+
112
+ attr_reader :condition
113
+ attr_reader :body
114
+
115
+ forward! :@condition, :inputs, :outputs, :params, :features
116
+ forward! :@condition, :input_ticket_expr, :output_ticket_expr
117
+ forward :class, :rule_type
118
+
119
+ # Create a rule.
120
+ #
121
+ # @param expr [RuleExpr]
122
+ # rule expression
123
+ # @param condition [RuleCondition]
124
+ # rule condition
125
+ # @param [Block] body
126
+ # rule body block
127
+ def initialize(expr, condition, body)
128
+ @expr = expr
129
+ @condition = condition
130
+ @body = body
131
+ end
130
132
 
131
- # Returns the rule path.
132
- # @return [String]
133
- # rule path
134
- def rule_path
135
- @expr.rule_path
136
- end
133
+ # Return the rule path.
134
+ #
135
+ # @return [String]
136
+ # rule path
137
+ def rule_path
138
+ @expr.rule_path
139
+ end
137
140
 
138
- # Returns true if expression, condition, or body include variables.
139
- # @return [Boolean]
140
- # true if expression, condition, or body include variables
141
- def include_variable?
142
- return true if @expr.include_variable?
143
- return true if @condition.include_variable?
144
- return true if @body.include_variable?
145
- return false
146
- end
141
+ # Return true if expression, condition, or body include variables.
142
+ #
143
+ # @return [Boolean]
144
+ # true if expression, condition, or body include variables
145
+ def include_variable?
146
+ return true if @expr.include_variable?
147
+ return true if @condition.include_variable?
148
+ return true if @body.include_variable?
149
+ return false
150
+ end
147
151
 
148
- # Returns true if this is a kind of action rule.
149
- # @return [Boolean]
150
- # true if this is a kind of action rule, or false
151
- def action?
152
- self.class.rule_type == :action
153
- end
152
+ # Return true if this is a kind of action rule.
153
+ #
154
+ # @return [Boolean]
155
+ # true if this is a kind of action rule, or false
156
+ def action?
157
+ rule_type == :action
158
+ end
154
159
 
155
- # Returns true if this is a kind of flow rule.
156
- # @return [Boolean]
157
- # true if this is a kind of flow rule, or false
158
- def flow?
159
- self.class.rule_type == :flow
160
- end
160
+ # Return true if this is a kind of flow rule.
161
+ #
162
+ # @return [Boolean]
163
+ # true if this is a kind of flow rule, or false
164
+ def flow?
165
+ rule_type == :flow
166
+ end
161
167
 
162
- # Makes a task handler object for the rule.
163
- # @param [TupleSpaceServer] ts_server
164
- # tuple space server
165
- # @param [Array<Data, Array<Data>>] inputs
166
- # input tuples
167
- # @param [Parameters] params
168
- # rule parameters
169
- # @param [Array<String>] call_stack
170
- # call stack
171
- # @return [RuleHandler]
172
- # rule handler object
173
- def make_handler(ts_server, inputs, params, call_stack, opts={})
174
- handler_class.new(ts_server, self, inputs, params, call_stack, opts)
175
- end
168
+ # Make a task handler object for the rule.
169
+ #
170
+ # @param ts_server [TupleSpaceServer]
171
+ # tuple space server
172
+ # @param inputs [Array<Data, Array<Data>>]
173
+ # input tuples
174
+ # @param params [Parameters]
175
+ # rule parameters
176
+ # @param call_stack [Array<String>]
177
+ # call stack
178
+ # @return [RuleHandler]
179
+ # rule handler object
180
+ def make_handler(ts_server, inputs, params, call_stack, opts={})
181
+ handler_class.new(ts_server, self, inputs, params, call_stack, opts)
182
+ end
176
183
 
177
- # Returns a rule handler class.
178
- # @api private
179
- def handler_class
180
- raise NotImplementedError
181
- end
184
+ # Return a rule handler class.
185
+ #
186
+ # @api private
187
+ def handler_class
188
+ raise NotImplementedError
189
+ end
182
190
 
183
- # @api private
184
- def ==(other)
185
- return false unless other.kind_of?(self.class)
186
- return false unless @expr == other.expr
187
- return false unless @condition == other.condition
188
- return false unless @body == other.body
189
- return true
190
- end
191
+ # @api private
192
+ def ==(other)
193
+ return false unless other.kind_of?(self.class)
194
+ return false unless @expr == other.expr
195
+ return false unless @condition == other.condition
196
+ return false unless @body == other.body
197
+ return true
198
+ end
191
199
 
192
- alias :eql? :"=="
200
+ alias :eql? :"=="
193
201
 
194
- # @api private
195
- def hash
196
- @expr.hash + @condition.hash + @body.hash
202
+ # @api private
203
+ def hash
204
+ @expr.hash + @condition.hash + @body.hash
205
+ end
197
206
  end
198
- end
199
207
 
200
- # ActionRule is a rule writing action.
201
- class ActionRule < Rule
202
- @rule_type = :action
208
+ # ActionRule is a rule writing action.
209
+ class ActionRule < Rule
210
+ @rule_type = :action
203
211
 
204
- # @api private
205
- def handler_class
206
- RuleHandler::ActionHandler
212
+ # @api private
213
+ def handler_class
214
+ RuleHandler::ActionHandler
215
+ end
207
216
  end
208
- end
209
217
 
210
- # FlowRule represents a flow structured rule. This rule is consisted by flow
211
- # elements and executes elements actions.
212
- class FlowRule < Rule
213
- @rule_type = :flow
218
+ # FlowRule represents a flow structured rule. This rule is consisted by flow
219
+ # elements and executes elements actions.
220
+ class FlowRule < Rule
221
+ @rule_type = :flow
214
222
 
215
- # @api private
216
- def handler_class
217
- RuleHandler::FlowHandler
223
+ # @api private
224
+ def handler_class
225
+ RuleHandler::FlowHandler
226
+ end
218
227
  end
219
- end
220
228
 
221
- # RootRule is a hidden toplevel flow rule like the following:
222
- # Rule Root
223
- # input '*'.all
224
- # output '*'.all.except('{$INPUT[1]}')
225
- # Flow
226
- # rule &main:Main
227
- # End
228
- class RootRule < FlowRule
229
- INPUT_DOMAIN = 'input'
230
-
231
- # root domain has no digest and no package
232
- ROOT_DOMAIN = 'root'
233
-
234
- attr_reader :main
235
-
236
- # Makes a rule.
237
- def initialize(main, params=Parameters.empty)
238
- @main = main
239
- @params = params
240
- condition = make_condition
241
- super(
242
- RuleExpr.new(Package.new("root"), "Root", Parameters.empty, TicketExpr.empty, TicketExpr.empty),
243
- condition,
244
- FlowBlock.new(CallRule.new(@main.expr.set_params(@params)))
245
- )
246
- @domain = ROOT_DOMAIN
247
- end
229
+ # RootRule is a hidden toplevel flow rule like the following:
230
+ # Rule Root
231
+ # input '*'.all
232
+ # output '*'.all.except('{$INPUT[1]}')
233
+ # Flow
234
+ # rule &main:Main
235
+ # End
236
+ class RootRule < FlowRule
237
+ INPUT_DOMAIN = 'input'
238
+
239
+ # root domain has no digest and no package
240
+ ROOT_DOMAIN = 'root'
241
+
242
+ attr_reader :main
243
+
244
+ # Make a rule.
245
+ #
246
+ # @param main [Rule]
247
+ # main rule
248
+ # @param params [Parameters]
249
+ # main rule's parameters
250
+ def initialize(main, params=Parameters.empty)
251
+ @main = main
252
+ @params = params
253
+ condition = make_condition
254
+ super(
255
+ RuleExpr.new(Package.new("root"), "Root", Parameters.empty, TicketExpr.empty, TicketExpr.empty),
256
+ condition,
257
+ FlowBlock.new(CallRule.new(@main.expr.set_params(@params)))
258
+ )
259
+ @domain = ROOT_DOMAIN
260
+ end
248
261
 
249
- # @api private
250
- def make_handler(ts_server)
251
- finder = DataFinder.new(ts_server, INPUT_DOMAIN)
252
- results = finder.find(:input, inputs, @params.as_variable_table)
253
- if results.empty? and not(@main.inputs.empty?)
254
- return nil
262
+ # @api private
263
+ def make_handler(ts_server)
264
+ finder = DataFinder.new(ts_server, INPUT_DOMAIN)
265
+ results = finder.find(:input, inputs, @params.as_variable_table)
266
+ if results.empty? and not(@main.inputs.empty?)
267
+ return nil
268
+ end
269
+ inputs = @main.inputs.empty? ? [] : results.first.combination
270
+ handler_class.new(
271
+ ts_server,
272
+ self,
273
+ inputs,
274
+ @params,
275
+ [],
276
+ {:domain => @domain}
277
+ )
255
278
  end
256
- inputs = @main.inputs.empty? ? [] : results.first.combination
257
- handler_class.new(
258
- ts_server,
259
- self,
260
- inputs,
261
- @params,
262
- [],
263
- {:domain => @domain}
264
- )
265
- end
266
279
 
267
- private
268
-
269
- # @api private
270
- def make_condition
271
- RuleCondition.new(
272
- @main.inputs,
273
- @main.outputs,
274
- Parameters.empty,
275
- Feature.empty,
276
- TicketExpr.empty,
277
- TicketExpr.empty
278
- )
279
- end
280
+ private
281
+
282
+ # @api private
283
+ def make_condition
284
+ RuleCondition.new(
285
+ @main.inputs,
286
+ @main.outputs,
287
+ Parameters.empty,
288
+ Feature.empty,
289
+ TicketExpr.empty,
290
+ TicketExpr.empty
291
+ )
292
+ end
280
293
 
281
- # @api private
282
- def handler_class
283
- RuleHandler::RootHandler
294
+ # @api private
295
+ def handler_class
296
+ RuleHandler::RootHandler
297
+ end
284
298
  end
285
- end
286
299
 
287
- # SystemRule represents built-in rule definition. System rules belong to
288
- # 'system' package.
289
- class SystemRule < ActionRule
290
- # Creates a system rule model.
291
- # @param [String] name
292
- # rule name
293
- # @param [Proc] b
294
- # rule process
295
- def initialize(name, &b)
296
- expr = RuleExpr.new(
297
- Package.new('system'),
298
- name,
299
- Parameters.empty,
300
- TicketExpr.empty,
301
- TicketExpr.empty
302
- )
303
- condition = make_condition
304
- super(expr, condition, b)
305
- end
300
+ # SystemRule represents built-in rule definition. System rules belong to
301
+ # 'system' package.
302
+ class SystemRule < ActionRule
303
+ # Create a system rule model.
304
+ #
305
+ # @param name [String]
306
+ # rule name
307
+ # @param [Proc] b
308
+ # rule process
309
+ def initialize(name, &b)
310
+ expr = RuleExpr.new(
311
+ Package.new('system'),
312
+ name,
313
+ Parameters.empty,
314
+ TicketExpr.empty,
315
+ TicketExpr.empty
316
+ )
317
+ condition = make_condition
318
+ super(expr, condition, b)
319
+ end
306
320
 
307
- private
321
+ private
308
322
 
309
- # @api private
310
- def make_condition
311
- inputs = [DataExpr.new('*')]
312
- RuleCondition.new(inputs, [], Parameters.empty, Feature::EmptyFeature.new, TicketExpr.empty, TicketExpr.empty)
323
+ # @api private
324
+ def make_condition
325
+ inputs = [DataExpr.new('*')]
326
+ RuleCondition.new(inputs, [], Parameters.empty, Feature::EmptyFeature.new, TicketExpr.empty, TicketExpr.empty)
327
+ end
328
+
329
+ # @api private
330
+ def handler_class
331
+ RuleHandler::SystemHandler
332
+ end
313
333
  end
314
334
 
315
- # @api private
316
- def handler_class
317
- RuleHandler::SystemHandler
335
+ # &System:Terminate rule
336
+ SYSTEM_TERMINATE = SystemRule.new('Terminate') do |tuple_space_server|
337
+ user_message "!!!!!!!!!!!!!!!!!"
338
+ user_message "!!! Terminate !!!"
339
+ user_message "!!!!!!!!!!!!!!!!!"
340
+ tuple_space_server.write(Tuple[:command].new("terminate"))
318
341
  end
319
- end
320
342
 
321
- # &System:Terminate rule
322
- SYSTEM_TERMINATE = SystemRule.new('Terminate') do |tuple_space_server|
323
- user_message "!!!!!!!!!!!!!!!!!"
324
- user_message "!!! Terminate !!!"
325
- user_message "!!!!!!!!!!!!!!!!!"
326
- tuple_space_server.write(Tuple[:command].new("terminate"))
343
+ SYSTEM_RULES = [ SYSTEM_TERMINATE ]
327
344
  end
328
-
329
- SYSTEM_RULES = [ SYSTEM_TERMINATE ]
330
345
  end