Skip to content

Instantly share code, notes, and snippets.

@shikhalev shikhalev/01_c.rb
Created Oct 12, 2013

Embed
What would you like to do?
Примеры для статьи «Распределенный Ruby»
# 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")
# 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
# 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
# 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
# encoding: utf-8
require 'drb'
DRb.start_service
s = DRbObject.new nil, 'druby://localhost:9000'
s.doSmth do |srv|
puts '--- client'
p srv
end
# 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
# 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"'
# encoding: utf-8
require 'drb'
class Server
end
DRb.start_service 'druby://localhost:9000', Server.new,
:safe_level => 1
DRb.thread.join
# encoding: utf-8
require 'drb'
DRb.start_service
s = DRbObject.new nil, 'druby://localhost:9000'
p s.dummy
# 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
# 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
# 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
# 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
You can’t perform that action at this time.