Class: Worker::Base

Inherits:
Object
  • Object
show all
Includes:
Spark::Constant, Spark::Helper::Serialize, Spark::Helper::System
Defined in:
lib/spark/worker/worker.rb

Direct Known Subclasses

Process, 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

Constants included from Spark::Helper::Serialize

Spark::Helper::Serialize::DIRECTIVE_CHARS, Spark::Helper::Serialize::DIRECTIVE_DOUBLES_BIG_ENDIAN, Spark::Helper::Serialize::DIRECTIVE_DOUBLE_BIG_ENDIAN, Spark::Helper::Serialize::DIRECTIVE_INTEGERS_BIG_ENDIAN, Spark::Helper::Serialize::DIRECTIVE_INTEGER_BIG_ENDIAN, Spark::Helper::Serialize::DIRECTIVE_LONGS_BIG_ENDIAN, Spark::Helper::Serialize::DIRECTIVE_LONG_BIG_ENDIAN, Spark::Helper::Serialize::DIRECTIVE_UNSIGNED_CHARS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Spark::Helper::System

included

Methods included from Spark::Helper::Serialize

#pack_double, #pack_doubles, #pack_int, #pack_ints, #pack_long, #pack_longs, #pack_unsigned_chars, #unpack_chars, #unpack_int, #unpack_long

Constructor Details

#initialize(port) ⇒ Base

Returns a new instance of Base.



27
28
29
30
31
32
33
# File 'lib/spark/worker/worker.rb', line 27

def initialize(port)
  # Open socket to Spark
  @socket = TCPSocket.open('localhost', port)

  # Send back worker ID
  socket.write_long(id)
end

Instance Attribute Details

#socketObject

Returns the value of attribute socket.



25
26
27
# File 'lib/spark/worker/worker.rb', line 25

def socket
  @socket
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
# File 'lib/spark/worker/worker.rb', line 35

def run
  begin
    compute
  rescue => e
    send_error(e)
  else
    successful_finish
  end
end