diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index afa4424..c980b41 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -51,6 +51,7 @@ require 'monitor' require_relative 'eq' require_relative 'version' +require_relative 'weakidconv' # # == Overview @@ -348,39 +349,6 @@ class DRbError < RuntimeError; end # protocol. class DRbConnError < DRbError; end - # Class responsible for converting between an object and its id. - # - # This, the default implementation, uses an object's local ObjectSpace - # __id__ as its id. This means that an object's identification over - # drb remains valid only while that object instance remains alive - # within the server runtime. - # - # For alternative mechanisms, see DRb::TimerIdConv in drb/timeridconv.rb - # and DRbNameIdConv in sample/name.rb in the full drb distribution. - class DRbIdConv - - # Convert an object reference id to an object. - # - # This implementation looks up the reference id in the local object - # space and returns the object it refers to. - def to_obj(ref) - ObjectSpace._id2ref(ref) - end - - # Convert an object into a reference id. - # - # This implementation returns the object's __id__ in the local - # object space. - def to_id(obj) - case obj - when Object - obj.nil? ? nil : obj.__id__ - when BasicObject - obj.__id__ - end - end - end - # Mixin module making an object undumpable or unmarshallable. # # If an object which includes this module is returned by method @@ -1349,7 +1317,7 @@ def alive? # :nodoc: # started by calling DRb.start_service. class DRbServer @@acl = nil - @@idconv = DRbIdConv.new + @@idconv = WeakIdConv.new @@secondary_server = nil @@argc_limit = 256 @@load_limit = 0xffffffff @@ -1940,4 +1908,4 @@ def fetch_server(uri) # :stopdoc: DRbObject = DRb::DRbObject DRbUndumped = DRb::DRbUndumped -DRbIdConv = DRb::DRbIdConv +DRbIdConv = DRb::WeakIdConv diff --git a/lib/drb/id2refconv.rb b/lib/drb/id2refconv.rb new file mode 100644 index 0000000..fc1c748 --- /dev/null +++ b/lib/drb/id2refconv.rb @@ -0,0 +1,27 @@ +# Deprecated: Uses internal API ObjectSpace._id2ref and is replaced +# by WeakIdConv. +module DRb + class DRbIdConv + + # Convert an object reference id to an object. + # + # This implementation looks up the reference id in the local object + # space and returns the object it refers to. + def to_obj(ref) + ObjectSpace._id2ref(ref) + end + + # Convert an object into a reference id. + # + # This implementation returns the object's __id__ in the local + # object space. + def to_id(obj) + case obj + when Object + obj.nil? ? nil : obj.__id__ + when BasicObject + obj.__id__ + end + end + end +end diff --git a/lib/drb/timeridconv.rb b/lib/drb/timeridconv.rb index 3ead98a..c72d7d5 100644 --- a/lib/drb/timeridconv.rb +++ b/lib/drb/timeridconv.rb @@ -12,7 +12,7 @@ module DRb # # DRb.install_id_conv TimerIdConv.new 60 # one minute - class TimerIdConv < DRbIdConv + class TimerIdConv class TimerHolder2 # :nodoc: include MonitorMixin diff --git a/lib/drb/weakidconv.rb b/lib/drb/weakidconv.rb index ecf0bf5..690c824 100644 --- a/lib/drb/weakidconv.rb +++ b/lib/drb/weakidconv.rb @@ -1,14 +1,9 @@ # frozen_string_literal: false -require_relative 'drb' require 'monitor' module DRb - # To use WeakIdConv: - # - # DRb.start_service(nil, nil, {:idconv => DRb::WeakIdConv.new}) - - class WeakIdConv < DRbIdConv + class WeakIdConv class WeakSet include MonitorMixin def initialize