Module: Isono::NodeModules::RpcChannel::RequestContext::RequestSynchronize

Defined in:
lib/isono/node_modules/rpc_channel.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object

Raises:

  • (TypeError)


435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/isono/node_modules/rpc_channel.rb', line 435

def self.extended(mod)
  raise TypeError, "This module is applicable only for RequestContext" unless mod.is_a?(RequestContext)

  # overwrite callbacks
  mod.instance_eval {
    @q = ::Queue.new

    on_success { |r|
      @q << [:success, r]
    }
    on_error { |r|
      @q << [:error, r]
    }
  }
end

Instance Method Details

#waitObject



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/isono/node_modules/rpc_channel.rb', line 452

def wait()
  raise "wait() has to be called at outside of the EventMachine's main loop." if EventMachine.reactor_thread?
  if state == :done && @q.empty?
    logger.warn "Remote procedure call state is 'done' and response queue is empty. " +
                "May be waiting forever for a response. Endpoint: '%s' Command: '%s'" %
                [endpoint, command]
  end

  r = @q.deq

  case r[0]
  when :success
    r[1]
  when :error
    raise RpcError, r[1]
  end
end