Class: Arsenicum::Core::Worker
- Inherits:
-
Object
- Object
- Arsenicum::Core::Worker
- Defined in:
- lib/arsenicum/core/worker.rb
Defined Under Namespace
Classes: InvokerThread
Constant Summary collapse
- RESULT_SUCCESS =
0
- RESULT_FAILURE =
0x80
- CONTROL_STOP =
0xFF
- CONTROL_PING =
0x30
Constants included from IOHelper
IOHelper::TYPE_INT, IOHelper::TYPE_STRING
Constants included from Commands
Commands::COMMAND_STOP, Commands::COMMAND_STRING_STOP, Commands::COMMAND_STRING_TASK, Commands::COMMAND_TASK
Instance Attribute Summary collapse
-
#active ⇒ Object
(also: #active?)
readonly
Returns the value of attribute active.
-
#broker ⇒ Object
readonly
Returns the value of attribute broker.
-
#ctrl_in_child ⇒ Object
readonly
Returns the value of attribute ctrl_in_child.
-
#ctrl_in_parent ⇒ Object
readonly
Returns the value of attribute ctrl_in_parent.
-
#ctrl_out_child ⇒ Object
readonly
Returns the value of attribute ctrl_out_child.
-
#ctrl_out_parent ⇒ Object
readonly
Returns the value of attribute ctrl_out_parent.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#in_child ⇒ Object
readonly
Returns the value of attribute in_child.
-
#in_parent ⇒ Object
readonly
Returns the value of attribute in_parent.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#out_child ⇒ Object
readonly
Returns the value of attribute out_child.
-
#out_parent ⇒ Object
readonly
Returns the value of attribute out_parent.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
-
#work_at ⇒ Object
readonly
Returns the value of attribute work_at.
Instance Method Summary collapse
- #==(another) ⇒ Object
- #ask(task_id, *parameters) ⇒ Object
- #ask_async(success_handler, failure_handler, task_id, *parameters) ⇒ Object
-
#initialize(broker, index, worker_configuration) ⇒ Worker
constructor
A new instance of Worker.
- #return_to_broker ⇒ Object
- #stop ⇒ Object
Methods included from IOHelper
Constructor Details
#initialize(broker, index, worker_configuration) ⇒ Worker
Returns a new instance of Worker.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/arsenicum/core/worker.rb', line 22 def initialize(broker, index, worker_configuration) @broker = WeakRef.new broker # avoiding circular references. @index = index @serializer = worker_configuration[:serializer] @formatter = worker_configuration[:formatter] @thread = InvokerThread.new(self) @work_at = :parent @state = :parent run end |
Instance Attribute Details
#active ⇒ Object (readonly) Also known as: active?
Returns the value of attribute active.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def active @active end |
#broker ⇒ Object (readonly)
Returns the value of attribute broker.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def broker @broker end |
#ctrl_in_child ⇒ Object (readonly)
Returns the value of attribute ctrl_in_child.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def ctrl_in_child @ctrl_in_child end |
#ctrl_in_parent ⇒ Object (readonly)
Returns the value of attribute ctrl_in_parent.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def ctrl_in_parent @ctrl_in_parent end |
#ctrl_out_child ⇒ Object (readonly)
Returns the value of attribute ctrl_out_child.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def ctrl_out_child @ctrl_out_child end |
#ctrl_out_parent ⇒ Object (readonly)
Returns the value of attribute ctrl_out_parent.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def ctrl_out_parent @ctrl_out_parent end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def formatter @formatter end |
#in_child ⇒ Object (readonly)
Returns the value of attribute in_child.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def in_child @in_child end |
#in_parent ⇒ Object (readonly)
Returns the value of attribute in_parent.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def in_parent @in_parent end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def index @index end |
#out_child ⇒ Object (readonly)
Returns the value of attribute out_child.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def out_child @out_child end |
#out_parent ⇒ Object (readonly)
Returns the value of attribute out_parent.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def out_parent @out_parent end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def pid @pid end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def serializer @serializer end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def state @state end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def thread @thread end |
#work_at ⇒ Object (readonly)
Returns the value of attribute work_at.
13 14 15 |
# File 'lib/arsenicum/core/worker.rb', line 13 def work_at @work_at end |
Instance Method Details
#==(another) ⇒ Object
34 35 36 37 38 |
# File 'lib/arsenicum/core/worker.rb', line 34 def ==(another) return false unless another.is_a? ::Arsenicum::Core::Worker return another.pid == self.pid end |
#ask(task_id, *parameters) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/arsenicum/core/worker.rb', line 40 def ask(task_id, *parameters) out_parent, task_id, serialize(parameters) loop do rs, = select([in_parent], [], [], 5) break if rs sleep 0.5 end result, marshaled_exception = in_parent return if result == RESULT_SUCCESS raise Marshal.load(marshaled_exception) end |
#ask_async(success_handler, failure_handler, task_id, *parameters) ⇒ Object
53 54 55 |
# File 'lib/arsenicum/core/worker.rb', line 53 def ask_async(success_handler, failure_handler, task_id, *parameters) thread.ask success_handler, failure_handler, task_id, *parameters end |
#return_to_broker ⇒ Object
69 70 71 |
# File 'lib/arsenicum/core/worker.rb', line 69 def return_to_broker broker.get_back_worker self end |
#stop ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/arsenicum/core/worker.rb', line 57 def stop thread.terminate return unless child_process_alive? ctrl_out_parent, COMMAND_STOP Process.waitpid pid end |