Class: Pione::DRbPatch::PioneDRbConn
- Inherits:
-
DRb::DRbConn
- Object
- DRb::DRbConn
- Pione::DRbPatch::PioneDRbConn
- Defined in:
- lib/pione/patch/drb-patch.rb
Overview
+PioneDRbConn+ provides connections to +DRb::DRbObject+. This class is different from original +DRbConn+ at the point of connection reuse.
Class Attribute Summary collapse
-
.cache ⇒ Object
readonly
Returns the value of attribute cache.
Class Method Summary collapse
-
.clear_cache ⇒ Object
Clear connection cache table.
-
.open(remote_uri) ⇒ Object
Open a remote URI.
Instance Method Summary collapse
-
#close ⇒ Object
Close the client-to-server socket.
-
#send_message(ref, msg_id, arg, block) ⇒ Object
Send the message from client to server.
Class Attribute Details
.cache ⇒ Object (readonly)
Returns the value of attribute cache.
226 227 228 |
# File 'lib/pione/patch/drb-patch.rb', line 226 def cache @cache end |
Class Method Details
.clear_cache ⇒ Object
Clear connection cache table.
229 230 231 232 |
# File 'lib/pione/patch/drb-patch.rb', line 229 def clear_cache @cache.values {|connection| connection.close rescue nil} @cache.clear end |
.open(remote_uri) ⇒ Object
Open a remote URI. This method reuse connection if the URI is cached.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/pione/patch/drb-patch.rb', line 235 def open(remote_uri) conn = nil @mutex.synchronize do cache = @cache[remote_uri] # get connection if not(cache.nil?) and cache.alive? conn = cache # use cached connection else conn = self.new(remote_uri) # create a new connection Log::Debug.communication "client created a new connection to %s" % remote_uri.inspect end @cache[remote_uri] = conn end succ, result = yield(conn) @retry[remote_uri] = 0 return succ, result rescue DRb::DRbConnError, ReplyReaderError, Errno::ECONNREFUSED => e Log::Debug.communication "client failed to open a connection to %s." % remote_uri @mutex.synchronize do if @cache[remote_uri] @cache[remote_uri].close @cache.delete(remote_uri) end @retry[remote_uri] ||= 0 @retry[remote_uri] += 1 end if @retry[remote_uri] < 6 sleep 0.1 retry else raise end end |
Instance Method Details
#close ⇒ Object
Close the client-to-server socket.
274 275 276 277 278 279 280 281 |
# File 'lib/pione/patch/drb-patch.rb', line 274 def close Log::Debug.communication("client closed the socket") unless @closed @closed = true self.class.cache.delete(@uri) super end end |
#send_message(ref, msg_id, arg, block) ⇒ Object
Send the message from client to server.
284 285 286 |
# File 'lib/pione/patch/drb-patch.rb', line 284 def (ref, msg_id, arg, block) @protocol.send_request(ref, msg_id, arg, block) end |