Class: DRb::DRbConn
- Inherits:
-
Object
- Object
- DRb::DRbConn
- 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
-
#uri ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
Instance Method Summary collapse
-
#alive? ⇒ Boolean
:nodoc:.
-
#close ⇒ Object
:nodoc:.
-
#initialize(remote_uri) ⇒ DRbConn
constructor
:nodoc:.
-
#send_message(ref, msg_id, arg, block) ⇒ Object
:nodoc:.
Constructor Details
#initialize(remote_uri) ⇒ DRbConn
:nodoc:
1317 1318 1319 1320 |
# File 'lib/drb/drb.rb', line 1317 def initialize(remote_uri) # :nodoc: @uri = remote_uri @protocol = DRbProtocol.open(remote_uri, DRb.config) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
:nodoc:
1321 1322 1323 |
# File 'lib/drb/drb.rb', line 1321 def uri @uri end |
Class Method Details
.make_pool ⇒ Object
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'lib/drb/drb.rb', line 1259 def self.make_pool ThreadObject.new do |queue| pool = [] while true queue._execute do || case([0]) when :take then remote_uri = [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 = [1] pool.unshift(conn) pool.pop.close while pool.size > POOL_SIZE conn else nil end end end end end |
.open(remote_uri) ⇒ Object
:nodoc:
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/drb/drb.rb', line 1297 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 |
.stop_pool ⇒ Object
1292 1293 1294 1295 |
# File 'lib/drb/drb.rb', line 1292 def self.stop_pool @pool_proxy&.kill @pool_proxy = nil end |
Instance Method Details
#alive? ⇒ Boolean
:nodoc:
1333 1334 1335 1336 |
# File 'lib/drb/drb.rb', line 1333 def alive? # :nodoc: return false unless @protocol @protocol.alive? end |
#close ⇒ Object
:nodoc:
1328 1329 1330 1331 |
# File 'lib/drb/drb.rb', line 1328 def close # :nodoc: @protocol.close @protocol = nil end |
#send_message(ref, msg_id, arg, block) ⇒ Object
:nodoc:
1323 1324 1325 1326 |
# File 'lib/drb/drb.rb', line 1323 def (ref, msg_id, arg, block) # :nodoc: @protocol.send_request(ref, msg_id, arg, block) @protocol.recv_reply end |