class DRb::DRbConn
not normally need to deal with it directly.
This class is used internally by DRbObject. The user does
method call.
overhead of starting and closing down connections for each
This class maintains a pool of connections, to reduce the
server the real object lives on.
Class handling the connection between a DRbObject and the
def self.make_pool
def self.make_pool ThreadObject.new do |queue| pool = [] while true queue._execute do |message| case(message[0]) when :take then remote_uri = message[1] conn = nil new_pool = [] pool.each do |c| if conn.nil? and c.uri == remote_uri conn = c if c.alive? else new_pool.push c end end pool = new_pool conn when :store then conn = message[1] pool.unshift(conn) pool.pop.close while pool.size > POOL_SIZE conn else nil end end end end end
def self.open(remote_uri) # :nodoc:
def self.open(remote_uri) # :nodoc: begin @pool_proxy = make_pool unless @pool_proxy&.alive? conn = @pool_proxy.take(remote_uri) conn = self.new(remote_uri) unless conn succ, result = yield(conn) return succ, result ensure if conn if succ @pool_proxy.store(conn) else conn.close end end end end
def self.stop_pool
def self.stop_pool @pool_proxy&.kill @pool_proxy = nil end
def alive? # :nodoc:
def alive? # :nodoc: return false unless @protocol @protocol.alive? end
def close # :nodoc:
def close # :nodoc: @protocol.close @protocol = nil end
def initialize(remote_uri) # :nodoc:
def initialize(remote_uri) # :nodoc: @uri = remote_uri @protocol = DRbProtocol.open(remote_uri, DRb.config) end
def send_message(ref, msg_id, arg, block) # :nodoc:
def send_message(ref, msg_id, arg, block) # :nodoc: @protocol.send_request(ref, msg_id, arg, block) @protocol.recv_reply end