class Pione::DRbPatch::ReplyReader

Public Class Methods

new() click to toggle source
# File lib/pione/patch/drb-patch.rb, line 24
def initialize
  @watcher_lock = Mutex.new
  @watchers = Set.new
end

Public Instance Methods

add_watcher(watcher) click to toggle source

Makes reader thread for receiving unordered replies.

# File lib/pione/patch/drb-patch.rb, line 56
def add_watcher(watcher)
  @watcher_lock.synchronize do
    @watchers << watcher
  end
end
remove_watcher(watcher) click to toggle source

Remove the request reader thread watcher.

# File lib/pione/patch/drb-patch.rb, line 63
def remove_watcher(watcher)
  @watcher_lock.synchronize do
    @watchers.delete_if {|th| th == watcher}
  end
end
start(protocol) click to toggle source
# File lib/pione/patch/drb-patch.rb, line 29
def start(protocol)
  @thread ||= Thread.new do
    begin
      # loop for receiving reply and waiting the result
      while true
        # receive a replay
        req_id, succ, result = protocol.recv_reply
        # register it to waiter table
        DRbPatch.waiter_table.push(req_id, [succ, result])
      end
    rescue => e
      @watcher_lock.synchronize do
        # pass the exception to watchers
        @watchers.each do |watcher|
          Log::Debug.communication("connection error happened in receiving reply.")
          Log::Debug.communication(e)
          watcher.raise(ReplyReaderError.new(e)) if watcher.alive?
        end

        # remove dead watchers
        @watchers.delete_if {|watcher| not(watcher.alive?)}
      end
    end
  end
end