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
-
.open(remote_uri) ⇒ Object
:nodoc:.
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:
1246 1247 1248 1249 |
# File 'lib/drb/drb.rb', line 1246 def initialize(remote_uri) # :nodoc: @uri = remote_uri @protocol = DRbProtocol.open(remote_uri, DRb.config) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
:nodoc:
1250 1251 1252 |
# File 'lib/drb/drb.rb', line 1250 def uri @uri end |
Class Method Details
.open(remote_uri) ⇒ Object
:nodoc:
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 |
# File 'lib/drb/drb.rb', line 1211 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:
1262 1263 1264 1265 |
# File 'lib/drb/drb.rb', line 1262 def alive? # :nodoc: return false unless @protocol @protocol.alive? end |
#close ⇒ Object
:nodoc:
1257 1258 1259 1260 |
# File 'lib/drb/drb.rb', line 1257 def close # :nodoc: @protocol.close @protocol = nil end |
#send_message(ref, msg_id, arg, block) ⇒ Object
:nodoc:
1252 1253 1254 1255 |
# File 'lib/drb/drb.rb', line 1252 def (ref, msg_id, arg, block) # :nodoc: @protocol.send_request(ref, msg_id, arg, block) @protocol.recv_reply end |