Class: DRbQS::Task
- Inherits:
-
Object
- Object
- DRbQS::Task
- Defined in:
- lib/drbqs/task.rb
Overview
The tasks defined by this class are sent to nodes and calculated by the nodes. After the node returns the result of calculation to server, the server execute the hook.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hook ⇒ Object
readonly
Returns the value of attribute hook.
Class Method Summary collapse
Instance Method Summary collapse
- #drb_args(task_id) ⇒ Object
-
#initialize(obj, method_sym, args = [], &hook) ⇒ Task
constructor
Nodes execute obj.method_sym(*args).
- #same_target?(other) ⇒ Boolean
Constructor Details
#initialize(obj, method_sym, args = [], &hook) ⇒ Task
Nodes execute obj.method_sym(*args). Server executes &hook with a server instance and an object of result after the server accepts the results from nodes.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/drbqs/task.rb', line 13 def initialize(obj, method_sym, args = [], &hook) begin @marshal_obj = Marshal.dump(obj) rescue raise "Can not dump an instance of #{obj.class}." end unless Array === args raise "Arguments of task must be an array." end @method_sym = method_sym.intern @args = args @hook = hook end |
Instance Attribute Details
#hook ⇒ Object (readonly)
Returns the value of attribute hook.
8 9 10 |
# File 'lib/drbqs/task.rb', line 8 def hook @hook end |
Class Method Details
.execute_task(marshal_obj, method_sym, args) ⇒ Object
37 38 39 40 |
# File 'lib/drbqs/task.rb', line 37 def self.execute_task(marshal_obj, method_sym, args) obj = Marshal.load(marshal_obj) obj.__send__(method_sym, *args) end |
Instance Method Details
#drb_args(task_id) ⇒ Object
27 28 29 |
# File 'lib/drbqs/task.rb', line 27 def drb_args(task_id) [task_id, @marshal_obj, @method_sym, @args] end |
#same_target?(other) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/drbqs/task.rb', line 31 def same_target?(other) @marshal_obj == other.instance_variable_get(:@marshal_obj) && @method_sym == other.instance_variable_get(:@method_sym) && @args == other.instance_variable_get(:@args) end |