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:



1194
1195
1196
1197
# File 'lib/drb/drb.rb', line 1194

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

Instance Attribute Details

#uriObject (readonly)

:nodoc:



1198
1199
1200
# File 'lib/drb/drb.rb', line 1198

def uri
  @uri
end

Class Method Details

.open(remote_uri) ⇒ Object

:nodoc:



1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
# File 'lib/drb/drb.rb', line 1159

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:



1210
1211
1212
1213
# File 'lib/drb/drb.rb', line 1210

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

#closeObject

:nodoc:



1205
1206
1207
1208
# File 'lib/drb/drb.rb', line 1205

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

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

:nodoc:



1200
1201
1202
1203
# File 'lib/drb/drb.rb', line 1200

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