S
Stephan Kämper
Hi all and have a happy new year everybody!
I'm trying to built a set of programs that
- may run on different machines, or as different processes on one machine
- I'd like to have one program to notify other(s) of certain events
Now I thought that combining DRb and the Observer pattern might be the
way to go, but as I'm posting a question I apparently ran into an error.
BTW, I'm running a SuSE Linux 9.0 with ruby 1.8.1
[884] stk@tao ~/devel/util: ruby -v
ruby 1.8.1 (2003-12-25) [i686-linux]
I boiled down the server part to this:
==> File: Notifier.rb
require "drb/drb"
require "observer"
class Notifier
include Observable
def change( i )
puts "Changing: #{'%2d' % i}"
changed( true )
notify_observers( Time.now, i )
end
end
DRb.start_service( 'druby://localhost:4711', Notifier.new )
puts DRb.uri
DRb.thread.join
The program using that service got shortened to this:
require 'drb'
class Dummy
def initialize( observed )
observed.add_observer( self )
end
# define update as required by the Observer module
def update( *args )
puts "!!!"
p *args
end
end
notifier = DRbObject.new( nil, 'druby://localhost:4711' )
d = Dummy.new( notifier )
# Do something with the notifier to get d's 'update' called
notifier.change( rand( 10 ) )
Now, running the notifier works fine, but starting the client leaves me
with this:
[884] stk@tao ~/devel/util: ruby dummy.rb
(druby://localhost:4711) /usr/local/lib/ruby/1.8/observer.rb:126:in
`add_observer': Observer <Dummy> needs to respond to 'update'.
(NoMethodError)
from dummy.rb:5:in `initialize'
from dummy.rb:15:in `new'
from dummy.rb:15
{ Note that I changed the part of 'observer.rb' to give some information
about the observer that leads to the exception - just to be sure that
it's an Object of class Dummy that rose the exception. }
Now, why do I get the exception? I defined 'update' of objects of class
Dummy, didn't I?
Where's my mistake? Is it that way a good way anyway?
Happy rubying!
Stephan
I'm trying to built a set of programs that
- may run on different machines, or as different processes on one machine
- I'd like to have one program to notify other(s) of certain events
Now I thought that combining DRb and the Observer pattern might be the
way to go, but as I'm posting a question I apparently ran into an error.
BTW, I'm running a SuSE Linux 9.0 with ruby 1.8.1
[884] stk@tao ~/devel/util: ruby -v
ruby 1.8.1 (2003-12-25) [i686-linux]
I boiled down the server part to this:
==> File: Notifier.rb
require "drb/drb"
require "observer"
class Notifier
include Observable
def change( i )
puts "Changing: #{'%2d' % i}"
changed( true )
notify_observers( Time.now, i )
end
end
DRb.start_service( 'druby://localhost:4711', Notifier.new )
puts DRb.uri
DRb.thread.join
The program using that service got shortened to this:
require 'drb'
class Dummy
def initialize( observed )
observed.add_observer( self )
end
# define update as required by the Observer module
def update( *args )
puts "!!!"
p *args
end
end
notifier = DRbObject.new( nil, 'druby://localhost:4711' )
d = Dummy.new( notifier )
# Do something with the notifier to get d's 'update' called
notifier.change( rand( 10 ) )
Now, running the notifier works fine, but starting the client leaves me
with this:
[884] stk@tao ~/devel/util: ruby dummy.rb
(druby://localhost:4711) /usr/local/lib/ruby/1.8/observer.rb:126:in
`add_observer': Observer <Dummy> needs to respond to 'update'.
(NoMethodError)
from dummy.rb:5:in `initialize'
from dummy.rb:15:in `new'
from dummy.rb:15
{ Note that I changed the part of 'observer.rb' to give some information
about the observer that leads to the exception - just to be sure that
it's an Object of class Dummy that rose the exception. }
Now, why do I get the exception? I defined 'update' of objects of class
Dummy, didn't I?
Where's my mistake? Is it that way a good way anyway?
Happy rubying!
Stephan