Created
October 12, 2013 02:56
-
-
Save shikhalev/6945234 to your computer and use it in GitHub Desktop.
Примеры для статьи «Распределенный Ruby»
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
# encoding: utf-8 | |
require 'drb' | |
# DRb.start_service | |
a = DRbObject.new nil, 'druby://localhost:9000' | |
p a.alpha(1) | |
p a.alpha(nil) | |
p a.alpha("beta") |
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
# encoding: utf-8 | |
require 'drb' | |
class Server | |
def alpha arg | |
puts "Alpha called with #{arg.inspect}" | |
[:alpha, arg] | |
end | |
end | |
DRb.start_service 'druby://localhost:9000', Server.new | |
DRb.thread.join |
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
# encoding: utf-8 | |
require 'drb' | |
require './beta' | |
DRb.start_service | |
s = DRbObject.new nil, 'druby://localhost:9000' | |
a = s.alpha | |
p a | |
# p a.dummy | |
b = s.beta | |
p b | |
p b.dummy | |
c = s.gamma | |
p c | |
p c.dummy | |
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
# encoding: utf-8 | |
require 'drb' | |
class Alpha | |
def dummy | |
:dummy | |
end | |
end | |
require './beta' | |
class Gamma | |
include DRbUndumped | |
def dummy | |
puts 'Dummy called' | |
:dummy | |
end | |
end | |
class Server | |
def alpha | |
Alpha.new | |
end | |
def beta | |
Beta.new | |
end | |
def gamma | |
Gamma.new | |
end | |
end | |
DRb.start_service 'druby://localhost:9000', Server.new | |
DRb.thread.join | |
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
# encoding: utf-8 | |
require 'drb' | |
DRb.start_service | |
s = DRbObject.new nil, 'druby://localhost:9000' | |
s.doSmth do |srv| | |
puts '--- client' | |
p srv | |
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
# encoding: utf-8 | |
require 'drb' | |
class Server | |
include DRbUndumped | |
def doSmth &block | |
puts '--- server' | |
p block | |
block.call self | |
end | |
end | |
DRb.start_service 'druby://localhost:9000', Server.new | |
DRb.thread.join |
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
# encoding: utf-8 | |
require 'drb' | |
DRb.start_service | |
s = DRbObject.new nil, 'druby://localhost:9000' | |
s.instance_eval 'undef :instance_eval' | |
s.instance_eval 'p "client str"' |
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
# encoding: utf-8 | |
require 'drb' | |
class Server | |
end | |
DRb.start_service 'druby://localhost:9000', Server.new, | |
:safe_level => 1 | |
DRb.thread.join | |
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
# encoding: utf-8 | |
require 'drb' | |
DRb.start_service | |
s = DRbObject.new nil, 'druby://localhost:9000' | |
p s.dummy |
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
# encoding: utf-8 | |
require 'drb' | |
require 'drb/acl' | |
class Server | |
def dummy | |
:dummy | |
end | |
end | |
acl = ACL.new(%w( | |
deny all | |
allow localhost | |
allow ::1 | |
allow 192.168.1.* | |
)) | |
DRb.start_service 'druby://localhost:9000', Server.new, | |
:tcp_acl => acl | |
DRb.thread.join |
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
# encoding: utf-8 | |
require 'drb' | |
DRb.start_service 'druby://127.0.0.1:9001' | |
s = DRbObject.new nil, 'druby://127.0.0.1:9000' | |
p s.dummy |
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
# encoding: utf-8 | |
require 'drb' | |
class Server | |
def dummy | |
:dummy | |
end | |
end | |
DRb.start_service 'druby://127.0.0.1:9000', Server.new | |
DRb.thread.join |
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
# encoding: utf-8 | |
class Beta | |
def dummy | |
:dummy | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment