Created
December 24, 2013 08:24
-
-
Save gouf/8110318 to your computer and use it in GitHub Desktop.
DRB によるオブジェクトサーバ
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' | |
require 'eventmachine' | |
require 'pp' | |
EM.run do | |
DRb.start_service() | |
obj = DRbObject.new(nil, 'druby://localhost:9000') | |
EM.add_periodic_timer(2) do | |
3.times{pp obj.pop} | |
end | |
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' | |
require 'eventmachine' | |
require 'pp' | |
EM.run do | |
DRb.start_service() | |
obj = DRbObject.new(nil, 'druby://localhost:9000') | |
EM.add_periodic_timer(3) do | |
5.times{pp obj.push 'test'} | |
end | |
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' | |
class QServer | |
def initialize | |
@q = Queue.new | |
end | |
def push str | |
@q << str | |
end | |
def pop | |
@q.pop | |
end | |
def shift | |
@q.shift | |
end | |
def size | |
@q.size | |
end | |
end | |
server = QServer.new | |
DRb.start_service('druby://localhost:9000', server) | |
DRb.thread.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment