123456789_123456789_123456789_123456789_123456789_

Class: DRb::DRbConn

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/drb/drb.rb

Overview

Class handling the connection between a DRbObject and the server the real object lives on.

This class maintains a pool of connections, to reduce the overhead of starting and closing down connections for each method call.

This class is used internally by DRbObject. The user does not normally need to deal with it directly.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(remote_uri) ⇒ DRbConn

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1245

def initialize(remote_uri)  # :nodoc:
  @uri = remote_uri
  @protocol = DRbProtocol.open(remote_uri, DRb.config)
end

Class Method Details

.open(remote_uri)

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1210

def self.open(remote_uri)  # :nodoc:
  begin
    conn = nil

    @mutex.synchronize do
      #FIXME
      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
    end

    conn = self.new(remote_uri) unless conn
    succ, result = yield(conn)
    return succ, result

  ensure
    if conn
      if succ
        @mutex.synchronize do
          @pool.unshift(conn)
          @pool.pop.close while @pool.size > POOL_SIZE
        end
      else
        conn.close
      end
    end
  end
end

Instance Attribute Details

#alive?Boolean (readonly)

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1261

def alive?  # :nodoc:
  return false unless @protocol
  @protocol.alive?
end

#uri (readonly)

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1249

attr_reader :uri  # :nodoc:

Instance Method Details

#close

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1256

def close  # :nodoc:
  @protocol.close
  @protocol = nil
end

#send_message(ref, msg_id, arg, block)

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1251

def send_message(ref, msg_id, arg, block)  # :nodoc:
  @protocol.send_request(ref, msg_id, arg, block)
  @protocol.recv_reply
end