Class: Pione::RuleHandler::BasicHandler
- Inherits:
-
Object
- Object
- Pione::RuleHandler::BasicHandler
- Includes:
- TupleSpaceServerInterface
- Defined in:
- lib/pione/rule-handler/basic-handler.rb
Overview
BasicHandler is a base class for rule handlers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#call_stack ⇒ Object
readonly
Returns the value of attribute call_stack.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#task_id ⇒ Object
readonly
Returns the value of attribute task_id.
-
#variable_table ⇒ Object
readonly
Returns the value of attribute variable_table.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?) private
-
#handle ⇒ Array<Data,Array<Data>>
Handles the rule and returns the outputs.
- #hash ⇒ Object private
-
#initialize(ts_server, rule, inputs, params, call_stack, opts = {}) ⇒ BasicHandler
constructor
Create a new handler for rule.
-
#root? ⇒ Boolean
Returns true if it is root rule handler.
-
#setenv(env) ⇒ void
Puts environment variable into pione variable table.
Methods included from TupleSpaceServerInterface
tuple_space_operation, #tuple_space_server
Constructor Details
#initialize(ts_server, rule, inputs, params, call_stack, opts = {}) ⇒ BasicHandler
Create a new handler for rule.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 45 def initialize(ts_server, rule, inputs, params, call_stack, opts={}) # check arguments raise ArgumentError.new(inputs) unless inputs.kind_of?(Array) raise ArgumentError.new(inputs) unless inputs.size == rule.inputs.size raise ArgumentError.new(params) unless params.kind_of?(Parameters) # set tuple space server set_tuple_space_server(ts_server) # set informations @rule = rule @inputs = inputs @outputs = [] @params = @rule.params.merge(params) @original_params = params @content = rule.body @domain = get_handling_domain(opts) @variable_table = VariableTable.new(@params.data) @base_uri = read(Tuple[:base_uri].any).uri @dry_run = begin read0(Tuple[:dry_run].any).availability rescue false end @task_id = ID.task_id(@inputs, @params) @call_stack = call_stack setup_variable_table end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
30 31 32 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 30 def base_uri @base_uri end |
#call_stack ⇒ Object (readonly)
Returns the value of attribute call_stack.
34 35 36 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 34 def call_stack @call_stack end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
32 33 34 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 32 def domain @domain end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
27 28 29 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 27 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
28 29 30 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 28 def outputs @outputs end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
29 30 31 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 29 def params @params end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
26 27 28 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 26 def rule @rule end |
#task_id ⇒ Object (readonly)
Returns the value of attribute task_id.
31 32 33 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 31 def task_id @task_id end |
#variable_table ⇒ Object (readonly)
Returns the value of attribute variable_table.
33 34 35 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 33 def variable_table @variable_table end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 129 130 131 132 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 126 def ==(other) return false unless @rule == other.rule return false unless @inputs == other.inputs return false unless @outputs == other.outputs return false unless @params == other.params return true end |
#handle ⇒ Array<Data,Array<Data>>
Handles the rule and returns the outputs.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 84 def handle name = self.class. # show begin message ("Start %s Rule: %s" % [name, handler_digest]) # call stack ("call stack:") @call_stack.each_with_index do |domain, i| ("%s:%s" % [i, domain], 1) end # execute the rule outputs = execute # show output list ("%s Rule %s Result:" % [name, handler_digest]) @outputs.compact.each_with_index do |output, i| if output.kind_of?(Array) output.each_with_index do |o, ii| ("%s,%s:%s" % [i, ii, o.name], 1) end else ("%s:%s" % [i, output.name], 1) end end # show end message "End %s Rule: %s" % [name, handler_digest] return outputs.compact end |
#hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
138 139 140 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 138 def hash @rule.hash + @inputs.hash + @outputs.hash + @params.hash end |
#root? ⇒ Boolean
Returns true if it is root rule handler.
121 122 123 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 121 def root? self.kind_of?(RootHandler) end |
#setenv(env) ⇒ void
This method returns an undefined value.
Puts environment variable into pione variable table.
75 76 77 78 79 |
# File 'lib/pione/rule-handler/basic-handler.rb', line 75 def setenv(env) env.each do |key, value| @variable_table.set(Variable.new("ENV_" + key), PioneString.new(value)) end end |