Class: DRb::DRbConn
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
- POOL_SIZE =
:nodoc:
16
Instance Attribute Summary (collapse)
-
- (Object) uri
readonly
:nodoc:.
Class Method Summary (collapse)
-
+ (Object) open(remote_uri)
:nodoc:.
Instance Method Summary (collapse)
-
- (Boolean) alive?
:nodoc:.
-
- (Object) close
:nodoc:.
-
- (DRbConn) initialize(remote_uri)
constructor
:nodoc:.
-
- (Object) send_message(ref, msg_id, arg, block)
:nodoc:.
Constructor Details
- (DRbConn) initialize(remote_uri)
:nodoc:
1189 1190 1191 1192 |
# File 'lib/drb/drb.rb', line 1189 def initialize(remote_uri) # :nodoc: @uri = remote_uri @protocol = DRbProtocol.open(remote_uri, DRb.config) end |
Instance Attribute Details
- (Object) uri (readonly)
:nodoc:
1193 1194 1195 |
# File 'lib/drb/drb.rb', line 1193 def uri @uri end |
Class Method Details
+ (Object) open(remote_uri)
:nodoc:
1154 1155 1156 1157 1158 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 |
# File 'lib/drb/drb.rb', line 1154 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
- (Boolean) alive?
:nodoc:
1205 1206 1207 1208 |
# File 'lib/drb/drb.rb', line 1205 def alive? # :nodoc: return false unless @protocol @protocol.alive? end |
- (Object) close
:nodoc:
1200 1201 1202 1203 |
# File 'lib/drb/drb.rb', line 1200 def close # :nodoc: @protocol.close @protocol = nil end |
- (Object) send_message(ref, msg_id, arg, block)
:nodoc:
1195 1196 1197 1198 |
# File 'lib/drb/drb.rb', line 1195 def (ref, msg_id, arg, block) # :nodoc: @protocol.send_request(ref, msg_id, arg, block) @protocol.recv_reply end |