Class: DRbQS::Task
- Inherits:
-
Object
- Object
- DRbQS::Task
- Defined in:
- lib/drbqs/task/task.rb,
lib/drbqs/task/registrar.rb,
lib/drbqs/task/task_generator.rb
Overview
The tasks defined by this class are sent to nodes and calculated by the nodes.
Direct Known Subclasses
Defined Under Namespace
Classes: Generator, Registrar, TaskSet
Constant Summary collapse
- DEFAULT_GROUP =
:default
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#group ⇒ Object
Returns the value of attribute group.
-
#hook ⇒ Object
readonly
Returns the value of attribute hook.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#note ⇒ Object
Returns the value of attribute note.
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
Class Method Summary collapse
- .call_task_method(obj, method_name, args) ⇒ Object
- .execute_task(marshal_obj, method_name, marshal_args) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #drb_args(task_id) ⇒ Object
- #exec_hook(server, result) ⇒ Object
-
#initialize(obj, method_name, opts = {}, &hook) ⇒ Task
constructor
Nodes calculate by obj.method_name(*opts[:args]) and send the result to their server.
- #simple_drb_args ⇒ Object
Constructor Details
#initialize(obj, method_name, opts = {}, &hook) ⇒ Task
Changes of obj on a node are not sent to a server. That is, opts[:hook] must not depend on changes of instance variables on a node.
Nodes calculate by obj.method_name(*opts[:args]) and send the result to their server. Then the server executes &hook with a server instance and an object of result. For the communication of a server and nodes we must convert obj to a string by Marshal.dump. If we set both opts[:hook] and &hook then &hook is prior to opts[:hook].
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/drbqs/task/task.rb', line 36 def initialize(obj, method_name, opts = {}, &hook) @obj = obj begin @marshal_obj = Marshal.dump(@obj) rescue raise "Can not dump #{@obj.inspect}." end @method_name = method_name.intern @args = opts[:args] || [] unless Array === @args raise "Arguments of task must be an array." end begin @marshal_args = Marshal.dump(@args) rescue raise "Can not dump #{@args.inspect}." end @note = opts[:note] @hook = hook || opts[:hook] @group = opts[:group] || DRbQS::Task::DEFAULT_GROUP end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
14 15 16 |
# File 'lib/drbqs/task/task.rb', line 14 def args @args end |
#group ⇒ Object
Returns the value of attribute group.
17 18 19 |
# File 'lib/drbqs/task/task.rb', line 17 def group @group end |
#hook ⇒ Object (readonly)
Returns the value of attribute hook.
16 17 18 |
# File 'lib/drbqs/task/task.rb', line 16 def hook @hook end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
15 16 17 |
# File 'lib/drbqs/task/task.rb', line 15 def method_name @method_name end |
#note ⇒ Object
Returns the value of attribute note.
17 18 19 |
# File 'lib/drbqs/task/task.rb', line 17 def note @note end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
13 14 15 |
# File 'lib/drbqs/task/task.rb', line 13 def obj @obj end |
Class Method Details
.call_task_method(obj, method_name, args) ⇒ Object
93 94 95 |
# File 'lib/drbqs/task/task.rb', line 93 def self.call_task_method(obj, method_name, args) obj.__send__(method_name, *args) end |
.execute_task(marshal_obj, method_name, marshal_args) ⇒ Object
97 98 99 |
# File 'lib/drbqs/task/task.rb', line 97 def self.execute_task(marshal_obj, method_name, marshal_args) self.call_task_method(Marshal.load(marshal_obj), method_name, Marshal.load(marshal_args)) end |
Instance Method Details
#==(other) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/drbqs/task/task.rb', line 78 def ==(other) if @marshal_obj == other.instance_variable_get(:@marshal_obj) && @method_name == other.instance_variable_get(:@method_name) && @marshal_args == other.instance_variable_get(:@marshal_args) if Proc === @hook && Proc === other.hook # Return false at this time. false else @hook == other.hook end else false end end |
#drb_args(task_id) ⇒ Object
62 63 64 |
# File 'lib/drbqs/task/task.rb', line 62 def drb_args(task_id) [@group, task_id] + simple_drb_args end |
#exec_hook(server, result) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/drbqs/task/task.rb', line 66 def exec_hook(server, result) case @hook when Proc @hook.call(server, result) when Symbol, String @obj.__send__(@hook, server, result) else return nil end true end |
#simple_drb_args ⇒ Object
58 59 60 |
# File 'lib/drbqs/task/task.rb', line 58 def simple_drb_args [@marshal_obj, @method_name, @marshal_args] end |