pione 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/History.txt +11 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/bin/pione-log +5 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
- data/lib/pione.rb +14 -35
- data/lib/pione/agent/input-generator.rb +38 -40
- data/lib/pione/agent/logger.rb +52 -19
- data/lib/pione/agent/rule-provider.rb +5 -8
- data/lib/pione/agent/task-worker.rb +25 -32
- data/lib/pione/agent/tuple-space-client.rb +22 -14
- data/lib/pione/command.rb +21 -0
- data/lib/pione/command/basic-command.rb +267 -84
- data/lib/pione/command/child-process.rb +21 -18
- data/lib/pione/command/daemon-process.rb +9 -8
- data/lib/pione/command/front-owner-command.rb +8 -25
- data/lib/pione/command/pione-broker.rb +27 -24
- data/lib/pione/command/pione-clean.rb +6 -6
- data/lib/pione/command/pione-client.rb +143 -128
- data/lib/pione/command/pione-log.rb +61 -0
- data/lib/pione/command/pione-relay-account-db.rb +40 -38
- data/lib/pione/command/pione-relay-client-db.rb +38 -42
- data/lib/pione/command/pione-relay.rb +19 -20
- data/lib/pione/command/pione-syntax-checker.rb +70 -45
- data/lib/pione/command/pione-task-worker.rb +56 -66
- data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
- data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
- data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
- data/lib/pione/location.rb +10 -0
- data/lib/pione/location/basic-location.rb +272 -0
- data/lib/pione/location/dropbox-location.rb +139 -0
- data/lib/pione/location/ftp-location.rb +156 -0
- data/lib/pione/location/local-location.rb +116 -0
- data/lib/pione/log.rb +10 -0
- data/lib/pione/log/domain-info.rb +72 -0
- data/lib/pione/log/process-log.rb +176 -0
- data/lib/pione/log/process-record.rb +189 -0
- data/lib/pione/log/xes-log.rb +105 -0
- data/lib/pione/model/assignment.rb +88 -80
- data/lib/pione/model/binary-operator.rb +74 -68
- data/lib/pione/model/block.rb +218 -207
- data/lib/pione/model/boolean.rb +123 -112
- data/lib/pione/model/call-rule.rb +72 -65
- data/lib/pione/model/data-expr.rb +596 -290
- data/lib/pione/model/float.rb +108 -103
- data/lib/pione/model/integer.rb +133 -129
- data/lib/pione/model/message.rb +79 -72
- data/lib/pione/model/package.rb +42 -38
- data/lib/pione/model/parameters.rb +265 -236
- data/lib/pione/model/rule-expr.rb +247 -242
- data/lib/pione/model/rule-io.rb +137 -133
- data/lib/pione/model/rule.rb +307 -292
- data/lib/pione/model/string.rb +110 -99
- data/lib/pione/model/variable-table.rb +300 -271
- data/lib/pione/model/variable.rb +88 -83
- data/lib/pione/option.rb +13 -0
- data/lib/pione/option/child-process-option.rb +19 -0
- data/lib/pione/{command-option → option}/common-option.rb +6 -5
- data/lib/pione/option/option-interface.rb +73 -0
- data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
- data/lib/pione/option/task-worker-owner-option.rb +24 -0
- data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
- data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
- data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
- data/lib/pione/parser/common-parser.rb +3 -2
- data/lib/pione/parser/expr-parser.rb +6 -1
- data/lib/pione/patch/em-ftpd-patch.rb +21 -0
- data/lib/pione/patch/rinda-patch.rb +31 -23
- data/lib/pione/rule-handler/action-handler.rb +35 -25
- data/lib/pione/rule-handler/basic-handler.rb +92 -18
- data/lib/pione/rule-handler/flow-handler.rb +104 -98
- data/lib/pione/rule-handler/root-handler.rb +11 -0
- data/lib/pione/system/common.rb +10 -0
- data/lib/pione/system/file-cache.rb +103 -84
- data/lib/pione/system/global.rb +67 -12
- data/lib/pione/system/init.rb +20 -0
- data/lib/pione/transformer/expr-transformer.rb +6 -1
- data/lib/pione/tuple-space/data-finder.rb +33 -6
- data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
- data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
- data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
- data/lib/pione/tuple-space/update-criteria.rb +8 -7
- data/lib/pione/tuple/base-location-tuple.rb +9 -0
- data/lib/pione/tuple/basic-tuple.rb +7 -7
- data/lib/pione/tuple/data-tuple.rb +5 -2
- data/lib/pione/tuple/lift-tuple.rb +14 -0
- data/lib/pione/tuple/rule-tuple.rb +1 -1
- data/lib/pione/tuple/task-tuple.rb +5 -1
- data/lib/pione/version.rb +1 -1
- data/pione.gemspec +5 -1
- data/test/location/spec_basic-location.rb +35 -0
- data/test/location/spec_ftp-location.rb +100 -0
- data/test/location/spec_local-location.rb +99 -0
- data/test/log/data/sample.log +1003 -0
- data/test/log/spec_xes-log.rb +11 -0
- data/test/model/spec_data-expr.rb +249 -6
- data/test/model/spec_data-expr.yml +45 -0
- data/test/parser/spec_expr-parser.yml +4 -0
- data/test/spec_data-finder.rb +13 -7
- data/test/spec_data-finder.yml +42 -13
- data/test/system/spec_file-cache.rb +39 -0
- data/test/test-util.rb +226 -1
- data/test/transformer/spec_expr-transformer.rb +12 -1
- metadata +107 -24
- data/bin/pione-search-log +0 -30
- data/lib/pione/command-option/basic-option.rb +0 -42
- data/lib/pione/command-option/child-process-option.rb +0 -17
- data/lib/pione/command-option/daemon-option.rb +0 -12
- data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
- data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
- data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
- data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
- data/lib/pione/resource/basic-resource.rb +0 -92
- data/lib/pione/resource/dropbox-resource.rb +0 -106
- data/lib/pione/resource/ftp.rb +0 -84
- data/lib/pione/resource/local.rb +0 -113
- data/lib/pione/tuple/base-uri-tuple.rb +0 -9
- data/lib/pione/tuple/shift-tuple.rb +0 -13
- data/lib/pione/util/log.rb +0 -79
- data/test/spec_resource.rb +0 -73
data/lib/pione/model/rule-io.rb
CHANGED
@@ -1,166 +1,170 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
# @api private
|
27
|
+
def uri=(uri)
|
28
|
+
@uri = uri.to_pione
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
+
# @api private
|
39
|
+
def hash
|
40
|
+
@value.hash
|
41
|
+
end
|
36
42
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
43
|
+
#
|
44
|
+
# pione method
|
45
|
+
#
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
define_pione_method("==", [TypeRuleIOElement], TypeBoolean) do |rec, other|
|
48
|
+
PioneBoolean.new(rec.values == other.values)
|
49
|
+
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
define_pione_method("!=", [TypeRuleIOElement], TypeBoolean) do |rec, other|
|
52
|
+
PioneBoolean.not(rec.call_pione_method("==", other))
|
53
|
+
end
|
49
54
|
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
define_pione_method("uri", [], TypeString) do |rec, other|
|
56
|
+
PioneString.new(rec.uri)
|
57
|
+
end
|
53
58
|
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
define_pione_method("match", [], TypeList.new(TypeString)) do |rec|
|
60
|
+
rec.match
|
61
|
+
end
|
57
62
|
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
define_pione_method("MATCH", [], TypeList.new(TypeString)) do |rec|
|
64
|
+
rec.call_pione_method("match")
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
67
|
+
define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
|
68
|
+
rec.match[i.value-1]
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
71
|
+
define_pione_method("as_string", [], TypeString) do |rec|
|
72
|
+
rec.name
|
73
|
+
end
|
68
74
|
end
|
69
75
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
76
|
+
# RuleIOList is a input or output list for RuleIOElement.
|
77
|
+
class RuleIOList < BasicModel
|
78
|
+
extend Forwardable
|
74
79
|
|
75
|
-
|
76
|
-
class RuleIOList < BasicModel
|
77
|
-
extend Forwardable
|
80
|
+
set_pione_model_type TypeRuleIOList
|
78
81
|
|
79
|
-
|
82
|
+
attr_accessor :elements
|
83
|
+
def_delegators :@elements, :[], :size, :length
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
132
|
+
# @api private
|
133
|
+
def hash
|
134
|
+
@elements.hash
|
135
|
+
end
|
133
136
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
+
#
|
138
|
+
# pione method
|
139
|
+
#
|
137
140
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
+
define_pione_method("==", [TypeRuleIOList], TypeBoolean) do |rec, other|
|
142
|
+
PioneBoolean.new(rec.values == other.values)
|
143
|
+
end
|
141
144
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
define_pione_method("!=", [TypeRuleIOList], TypeBoolean) do |rec, other|
|
146
|
+
PioneBoolean.not(rec.call_pione_method("==", other))
|
147
|
+
end
|
145
148
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
+
define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
|
150
|
+
rec.elements[i.value-1]
|
151
|
+
end
|
149
152
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
data/lib/pione/model/rule.rb
CHANGED
@@ -1,330 +1,345 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
97
|
+
# Rule is a class for PIONE rule model.
|
98
|
+
class Rule < BasicModel
|
99
|
+
extend Forwardable
|
101
100
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
# Returns rule type.
|
102
|
+
def self.rule_type
|
103
|
+
@rule_type
|
104
|
+
end
|
106
105
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
184
|
+
# Return a rule handler class.
|
185
|
+
#
|
186
|
+
# @api private
|
187
|
+
def handler_class
|
188
|
+
raise NotImplementedError
|
189
|
+
end
|
182
190
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
-
|
200
|
+
alias :eql? :"=="
|
193
201
|
|
194
|
-
|
195
|
-
|
196
|
-
|
202
|
+
# @api private
|
203
|
+
def hash
|
204
|
+
@expr.hash + @condition.hash + @body.hash
|
205
|
+
end
|
197
206
|
end
|
198
|
-
end
|
199
207
|
|
200
|
-
|
201
|
-
|
202
|
-
|
208
|
+
# ActionRule is a rule writing action.
|
209
|
+
class ActionRule < Rule
|
210
|
+
@rule_type = :action
|
203
211
|
|
204
|
-
|
205
|
-
|
206
|
-
|
212
|
+
# @api private
|
213
|
+
def handler_class
|
214
|
+
RuleHandler::ActionHandler
|
215
|
+
end
|
207
216
|
end
|
208
|
-
end
|
209
217
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
223
|
+
# @api private
|
224
|
+
def handler_class
|
225
|
+
RuleHandler::FlowHandler
|
226
|
+
end
|
218
227
|
end
|
219
|
-
end
|
220
228
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
@main
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
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
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
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
|
-
|
282
|
-
|
283
|
-
|
294
|
+
# @api private
|
295
|
+
def handler_class
|
296
|
+
RuleHandler::RootHandler
|
297
|
+
end
|
284
298
|
end
|
285
|
-
end
|
286
299
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
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
|
-
|
321
|
+
private
|
308
322
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
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
|
-
#
|
316
|
-
|
317
|
-
|
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
|
-
|
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
|