source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/drb/gw.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 1.9 KB
Line 
1require 'drb/drb'
2require 'monitor'
3
4module DRb
5 class GWIdConv < DRbIdConv
6 def to_obj(ref)
7 if Array === ref && ref[0] == :DRbObject
8 return DRbObject.new_with(ref[1], ref[2])
9 end
10 super(ref)
11 end
12 end
13
14 class GW
15 include MonitorMixin
16 def initialize
17 super()
18 @hash = {}
19 end
20
21 def [](key)
22 synchronize do
23 @hash[key]
24 end
25 end
26
27 def []=(key, v)
28 synchronize do
29 @hash[key] = v
30 end
31 end
32 end
33
34 class DRbObject
35 def self._load(s)
36 uri, ref = Marshal.load(s)
37 if DRb.uri == uri
38 return ref ? DRb.to_obj(ref) : DRb.front
39 end
40
41 self.new_with(DRb.uri, [:DRbObject, uri, ref])
42 end
43
44 def _dump(lv)
45 if DRb.uri == @uri
46 if Array === @ref && @ref[0] == :DRbObject
47 Marshal.dump([@ref[1], @ref[2]])
48 else
49 Marshal.dump([@uri, @ref]) # ??
50 end
51 else
52 Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]])
53 end
54 end
55 end
56end
57
58=begin
59DRb.install_id_conv(DRb::GWIdConv.new)
60
61front = DRb::GW.new
62
63s1 = DRb::DRbServer.new('drbunix:/tmp/gw_b_a', front)
64s2 = DRb::DRbServer.new('drbunix:/tmp/gw_b_c', front)
65
66s1.thread.join
67s2.thread.join
68=end
69
70=begin
71# foo.rb
72
73require 'drb/drb'
74
75class Foo
76 include DRbUndumped
77 def initialize(name, peer=nil)
78 @name = name
79 @peer = peer
80 end
81
82 def ping(obj)
83 puts "#{@name}: ping: #{obj.inspect}"
84 @peer.ping(self) if @peer
85 end
86end
87=end
88
89=begin
90# gw_a.rb
91require 'drb/unix'
92require 'foo'
93
94obj = Foo.new('a')
95DRb.start_service("drbunix:/tmp/gw_a", obj)
96
97robj = DRbObject.new_with_uri('drbunix:/tmp/gw_b_a')
98robj[:a] = obj
99
100DRb.thread.join
101=end
102
103=begin
104# gw_c.rb
105require 'drb/unix'
106require 'foo'
107
108foo = Foo.new('c', nil)
109
110DRb.start_service("drbunix:/tmp/gw_c", nil)
111
112robj = DRbObject.new_with_uri("drbunix:/tmp/gw_b_c")
113
114puts "c->b"
115a = robj[:a]
116sleep 2
117
118a.ping(foo)
119
120DRb.thread.join
121=end
122
Note: See TracBrowser for help on using the repository browser.