Hi
I’m trying to find out how to use the DRbObservable module. This is
what I have so far:
–[ Server ]–
require 'drb/drb’
require ‘drb/observer’
class Foo
include DRb::DRbObservable
def run
changed
puts 'Notifying observer’
notify_observers(‘foo message’)
end
end
DRb::start_service(“druby://localhost:8888”, Foo.new)
DRb::thread.join
–[ Client ]–
require 'drb/drb’
require ‘drb/observer’
class Warner
def initialize(obj)
obj.add_observer(self)
end
def update(msg)
puts "Update message: #{msg}"
end
end
DRb.start_service
obj = DRbObject.new(nil, ‘druby://localhost:8888’)
Warner.new(obj)
obj.run
This is the error I get when I run the client after starting the
server:
$ ruby client.rb
(druby://localhost:8888) /usr/local/lib/ruby/1.8/observer.rb:126:in
add_observer': observer needs to respond to
update’ (NoMethodError)
from b.rb:6:in initialize' from b.rb:15:in
new’
from b.rb:15
I don’t understand it, since I’ve defined an ‘update’ method… can
anyone help me on that?
Thanks
Andre
Hi
I’m trying to find out how to use the DRbObservable module. This is
what I have so far:
–[ Server ]–
require ‘drb/drb’
require ‘drb/observer’
class Foo
include DRb::DRbObservable
def run
changed
puts ‘Notifying observer’
notify_observers(‘foo message’)
end
end
DRb::start_service(“druby://localhost:8888”, Foo.new)
DRb::thread.join
–[ Client ]–
require ‘drb/drb’
require ‘drb/observer’
class Warner
include DRb::DRbUndumped # I added this
def initialize(obj)
obj.add_observer(self)
end
def update(msg)
puts “Update message: #{msg}”
end
end
DRb.start_service
obj = DRbObject.new(nil, ‘druby://localhost:8888’)
Warner.new(obj)
obj.run
This is the error I get when I run the client after starting the
server:
$ ruby client.rb
(druby://localhost:8888) /usr/local/lib/ruby/1.8/observer.rb:126:in
add_observer': observer needs to respond to
update’ (NoMethodError)
from b.rb:6:in initialize' from b.rb:15:in
new’
from b.rb:15
I don’t understand it, since I’ve defined an ‘update’ method… can
anyone help me on that?
Other than the line I added above, it worked out-of-the box for me using:
ruby 1.8.1 (2003-10-31) [i386-freebsd4]
···
Andre Nathan (andre@digirati.com.br) wrote:
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
It works! How do I know when I need to include DRb::DRbUndumped? I read
the comments on drb.rb, but I’m afraid I don’t fully understand them…
Thanks,
Andre
···
On Tue, 2003-12-23 at 03:14, Eric Hodel wrote:
include DRb::DRbUndumped # I added this
Other than the line I added above, it worked out-of-the box for me using:
When you include DRb::DRbUndumped in a class, its objects stay on the
host they were created on, and never get passed over the network.
Instead a proxy object (of class DRbObject) gets passed, and operations
on the proxy are sent across the object.
In order to send an object to the other side of the DRb connection, both
sides need to know the class definition for the object, so class Foo
would have to exist on both sides of the connection.
ruby-talk:63281 may also help you.
···
Andre Nathan (andre@digirati.com.br) wrote:
On Tue, 2003-12-23 at 03:14, Eric Hodel wrote:
include DRb::DRbUndumped # I added this
Other than the line I added above, it worked out-of-the box for me using:
It works! How do I know when I need to include DRb::DRbUndumped? I read
the comments on drb.rb, but I’m afraid I don’t fully understand them…
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04