Class: DRb::DRbConn

Inherits:
Object
  • Object
show all
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 collapse

POOL_SIZE =

:nodoc:

16

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_uri) ⇒ DRbConn

:nodoc:



1214
1215
1216
1217
# File 'lib/drb/drb.rb', line 1214

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

Instance Attribute Details

#uriObject (readonly)

:nodoc:



1218
1219
1220
# File 'lib/drb/drb.rb', line 1218

def uri
  @uri
end

Class Method Details

.open(remote_uri) ⇒ Object

:nodoc:



1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
# File 'lib/drb/drb.rb', line 1179

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 Method Details

#alive?Boolean

:nodoc:

Returns:

  • (Boolean)


1230
1231
1232
1233
# File 'lib/drb/drb.rb', line 1230

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

#closeObject

:nodoc:



1225
1226
1227
1228
# File 'lib/drb/drb.rb', line 1225

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

#send_message(ref, msg_id, arg, block) ⇒ Object

:nodoc:



1220
1221
1222
1223
# File 'lib/drb/drb.rb', line 1220

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