aboutsummaryrefslogtreecommitdiffstats
path: root/lib/drb/gw.rb
diff options
context:
space:
mode:
authorseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-18 15:45:12 +0000
committerseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-18 15:45:12 +0000
commit151f1241c665b0307234e931bec2c32bfea0138d (patch)
tree6ca5c5e535d66aaf094e954446846955f2e18a88 /lib/drb/gw.rb
parent34cdb70d14ea1fdddf3f3991f6097fe5c24310ba (diff)
downloadruby-151f1241c665b0307234e931bec2c32bfea0138d.tar.gz
import from drb-2.0.4b3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/drb/gw.rb')
-rw-r--r--lib/drb/gw.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/drb/gw.rb b/lib/drb/gw.rb
new file mode 100644
index 0000000000..012a2b0a11
--- /dev/null
+++ b/lib/drb/gw.rb
@@ -0,0 +1,60 @@
+require 'drb/drb'
+require 'monitor'
+
+module DRb
+ class GWIdConv < DRbIdConv
+ def to_obj(ref)
+ if Array === ref && ref[0] == :DRbObject
+ it = DRbObject.new(nil)
+ it.reinit(ref[1], ref[2])
+ return it
+ end
+ super(ref)
+ end
+ end
+
+ class GW
+ include MonitorMixin
+ def initialize
+ super()
+ @hash = {}
+ end
+
+ def [](key)
+ synchronize do
+ @hash[key]
+ end
+ end
+
+ def []=(key, v)
+ synchronize do
+ @hash[key] = v
+ end
+ end
+ end
+
+ class DRbObject
+ def self._load(s)
+ uri, ref = Marshal.load(s)
+ if DRb.uri == uri
+ return ref ? DRb.to_obj(ref) : DRb.front
+ end
+
+ it = self.new(nil)
+ it.reinit(DRb.uri, [:DRbObject, uri, ref])
+ it
+ end
+
+ def _dump(lv)
+ if DRb.uri == @uri
+ if Array === @ref && @ref[0] == :DRbObject
+ Marshal.dump([@ref[1], @ref[2]])
+ else
+ Marshal.dump([@uri, @ref]) # ??
+ end
+ else
+ Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]])
+ end
+ end
+ end
+end