Using DRbObservable

A

Andre Nathan

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
 
E

Eric Hodel

--aYDVKSzuImP48n7V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hi
=20
I'm trying to find out how to use the DRbObservable module. This is
what I have so far:
=20
--[ Server ]--
require 'drb/drb'
require 'drb/observer'
=20
class Foo
include DRb::DRbObservable
def run
changed
puts 'Notifying observer'
notify_observers('foo message')
end
end
=20
DRb::start_service("druby://localhost:8888", Foo.new)
DRb::thread.join
=20
--[ Client ]--
require 'drb/drb'
require 'drb/observer'
=20
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
=20
DRb.start_service
obj =3D DRbObject.new(nil, 'druby://localhost:8888')
Warner.new(obj)
obj.run
=20
=20
This is the error I get when I run the client after starting the
server:
=20
$ 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
=20
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]

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--aYDVKSzuImP48n7V
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/5883MypVHHlsnwQRAll5AJ9BoQF6xB3wTOGdePAMOX0IibXarACg535g
091OUBvisR1hwzdrA0KnVeI=
=/e2c
-----END PGP SIGNATURE-----

--aYDVKSzuImP48n7V--
 
A

Andre Nathan

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...

Thanks,
Andre
 
E

Eric Hodel

--cW+P/jduATWpL925
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
g:
=20
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...

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.

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--cW+P/jduATWpL925
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/6M53MypVHHlsnwQRAuOjAKCjbMwBMxcPPvJ3TTgZHvKWbXGWIgCeLvG0
KAtgHAf3J5vpnfwM5dLKYJs=
=ojzc
-----END PGP SIGNATURE-----

--cW+P/jduATWpL925--
 
A

Andre Nathan

Eric Hodel said:
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.

Thanks a lot, Eric.

Andre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top