Class: Master::Thread

Inherits:
Base
  • Object
show all
Defined in:
lib/spark/worker/master.rb

Overview

Worker::Thread

Constant Summary

Constants included from Spark::Constant

Spark::Constant::ACCUMULATOR_ACK, Spark::Constant::CREATE_WORKER, Spark::Constant::DATA_EOF, Spark::Constant::KILL_WORKER, Spark::Constant::KILL_WORKER_AND_WAIT, Spark::Constant::SUCCESSFULLY_KILLED, Spark::Constant::UNSUCCESSFUL_KILLING, Spark::Constant::WORKER_DONE, Spark::Constant::WORKER_ERROR

Instance Method Summary collapse

Methods inherited from Base

#kill_worker_and_wait, #receive_message, #run

Constructor Details

#initializeThread

Returns a new instance of Thread.



115
116
117
118
119
120
121
122
123
# File 'lib/spark/worker/master.rb', line 115

def initialize
  ::Thread.abort_on_exception = true

  # For synchronous access to socket IO
  $mutex_for_command  = Mutex.new
  $mutex_for_iterator = Mutex.new

  super
end

Instance Method Details

#create_workerObject



125
126
127
128
129
# File 'lib/spark/worker/master.rb', line 125

def create_worker
  ::Thread.new do
    Worker::Thread.new(@port).run
  end
end

#kill_workerObject



131
132
133
134
135
136
137
138
# File 'lib/spark/worker/master.rb', line 131

def kill_worker
  worker_id = @socket.read_long

  thread = ObjectSpace._id2ref(worker_id)
  thread.kill
rescue
  nil
end