class Pione::DRbPatch::PioneDRbConn

PioneDRbConn provides connections to DRb::DRbObject. This class is different from original DRbConn at the point of connection reuse.

Attributes

cache[R]

Public Class Methods

clear_cache() click to toggle source

Clear connection cache table.

# File lib/pione/patch/drb-patch.rb, line 229
def clear_cache
  @cache.values {|connection| connection.close rescue nil}
  @cache.clear
end
open(remote_uri) { |conn| ... } click to toggle source

Open a remote URI. This method reuse connection if the URI is cached.

# File lib/pione/patch/drb-patch.rb, line 235
def open(remote_uri)
  conn = nil

  @mutex.synchronize do
    cache = @cache[remote_uri]

    # get connection
    if not(cache.nil?) and cache.alive?
      conn = cache # use cached connection
    else
      conn = self.new(remote_uri) # create a new connection
      Log::Debug.communication "client created a new connection to %s" % remote_uri.inspect
    end
    @cache[remote_uri] = conn
  end

  succ, result = yield(conn)
  @retry[remote_uri] = 0
  return succ, result
rescue DRb::DRbConnError, ReplyReaderError, Errno::ECONNREFUSED => e
  Log::Debug.communication "client failed to open a connection to %s." % remote_uri
  @mutex.synchronize do
    if @cache[remote_uri]
      @cache[remote_uri].close
      @cache.delete(remote_uri)
    end
    @retry[remote_uri] ||= 0
    @retry[remote_uri] += 1
  end
  if @retry[remote_uri] < 6
    sleep 0.1
    retry
  else
    raise
  end
end

Public Instance Methods

close() click to toggle source

Close the client-to-server socket.

Calls superclass method
# File lib/pione/patch/drb-patch.rb, line 274
def close
  Log::Debug.communication("client closed the socket")
  unless @closed
    @closed = true
    self.class.cache.delete(@uri)
    super
  end
end
send_message(ref, msg_id, arg, block) click to toggle source

Send the message from client to server.

# File lib/pione/patch/drb-patch.rb, line 284
def send_message(ref, msg_id, arg, block)
  @protocol.send_request(ref, msg_id, arg, block)
end