Class: DRbQS::Worker::SimpleForkedProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/worker/forked_process.rb

Direct Known Subclasses

ForkedProcess

Instance Method Summary collapse

Constructor Details

#initialize(io_r, io_w) ⇒ SimpleForkedProcess

Returns a new instance of SimpleForkedProcess.



4
5
6
7
8
9
# File 'lib/drbqs/worker/forked_process.rb', line 4

def initialize(io_r, io_w)
  @io_r = io_r
  @io_w = io_w
  @queue = []
  @special_task_number = 0
end

Instance Method Details

#calculate(marshal_obj, method_sym, args) ⇒ Object



11
12
13
# File 'lib/drbqs/worker/forked_process.rb', line 11

def calculate(marshal_obj, method_sym, args)
  DRbQS::Task.execute_task(marshal_obj, method_sym, args)
end

#startObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/drbqs/worker/forked_process.rb', line 34

def start
  unpacker = DRbQS::Worker::Serialize::Unpacker.new
  loop do
    if @queue.empty?
      begin
        chunk = @io_r.readpartial(READ_BYTE_SIZE)
        unpacker.feed_each(chunk) do |ary|
          @queue << ary
        end
      rescue EOFError
        break
      end
    else
      obj = @queue.shift
      case obj
      when Array
        handle_task(obj)
      when :prepare_to_exit
        send_response([:finish_preparing_to_exit])
      when :exit
        break
      else
        send_response([:node_error, "Invalid object from server."])
      end  
    end
  end
end