Created
November 24, 2009 20:53
-
-
Save seki/242201 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tweet | |
$ irb | |
irb(main):001:0> require 'drb/drb' | |
=> true | |
irb(main):002:0> DRb.start_service | |
=> #<DRb::DRbServer:...> | |
irb(main):003:0> ro = DRbObject.new_with_uri('druby://localhost:54321') | |
=> #<DRb::DRbObject:0...> | |
irb(main):004:0> ro.notify('tweet') | |
=> 1 | |
irb(main):005:0> ro.notify('Hello, World') | |
=> 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rinda/tuplespace' | |
require 'drb/drb' | |
class Notifier | |
def initialize | |
@ts = Rinda::TupleSpace.new | |
@ts.write([:tail, 0]) | |
end | |
def notify(it) | |
tuple = @ts.take([:tail, nil]) | |
tail = tuple[1] + 1 | |
@ts.write([tail, it]) | |
@ts.write([:tail, tail]) | |
tail | |
end | |
def receive(key) | |
@ts.read([key, nil]) | |
end | |
end | |
DRb.start_service('druby://localhost:54321', Notifier.new) | |
while true | |
sleep 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'drb/drb' | |
DRb.start_service | |
ro = DRbObject.new_with_uri('druby://localhost:54321') | |
key = 0 | |
while true | |
key, obj = ro.receive(key + 1) | |
p [key, obj] | |
sleep(3) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment