Last active
April 24, 2025 15:39
-
-
Save seki/773ab9ffe403a5197e82e1a90cb2c583 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
require 'monitor' | |
require 'drb' | |
module DRb | |
class DRbObjectSpace | |
include Singleton | |
include MonitorMixin | |
def initialize | |
super() | |
@map = ObjectSpace::WeakMap.new | |
end | |
def to_id(obj) | |
synchronize do | |
@map[obj.__id__] = obj | |
obj.__id__ | |
end | |
end | |
def to_obj(ref) | |
synchronize do | |
raise RangeError.new("invalid reference") unless @map.include?(ref) | |
@map[ref] | |
end | |
end | |
end | |
class DRbIdConv | |
def to_obj(ref) | |
DRbObjectSpace.instance.to_obj(ref) | |
end | |
def to_id(obj) | |
obj.nil? ? nil : DRbObjectSpace.instance.to_id(obj) | |
end | |
end | |
WeakIdConv = DRbIdConv | |
end | |
if __FILE__ == $0 | |
DRb.start_service(nil, {'stdout' => $stdout, 'ENV' => ENV}) | |
puts DRb.uri | |
DRb.thread.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
drb/drb.rbをこんな風に変更して、drb/weakidconv.rbの中身は40行目だけにしたいのだがどうしたらよいのか