require 'socket'
require 'thread'
require 'fcntl'
require 'drb/eq'
module DRb
class DRbError < RuntimeError; end
class DRbConnError < DRbError; end
class DRbIdConv
def to_obj(ref)
ObjectSpace._id2ref(ref)
end
def to_id(obj)
obj.nil? ? nil : obj.__id__
end
end
module DRbUndumped
def _dump(dummy) raise TypeError, 'can\'t dump'
end
end
class DRbServerNotFound < DRbError; end
class DRbBadURI < DRbError; end
class DRbBadScheme < DRbError; end
class DRbUnknownError < DRbError
def initialize(unknown)
@unknown = unknown
super(unknown.name)
end
attr_reader :unknown
def self._load(s) Marshal::load(s)
end
def _dump(lv) Marshal::dump(@unknown)
end
end
class DRbRemoteError < DRbError
def initialize(error)
@reason = error.class.to_s
super("#{error.message} (#{error.class})")
set_backtrace(error.backtrace)
end
attr_reader :reason
end
class DRbUnknown
def initialize(err, buf)
case err.to_s
when /uninitialized constant (\S+)/
@name = $1
when /undefined class\/module (\S+)/
@name = $1
else
@name = nil
end
@buf = buf
end
attr_reader :name
attr_reader :buf
def self._load(s) begin
Marshal::load(s)
rescue NameError, ArgumentError
DRbUnknown.new($!, s)
end
end
def _dump(lv) @buf
end
def reload
self.class._load(@buf)
end
def exception
DRbUnknownError.new(self)
end
end
class DRbArray
def initialize(ary)
@ary = ary.collect { |obj|
if obj.kind_of? DRbUndumped
DRbObject.new(obj)
else
begin
Marshal.dump(obj)
obj
rescue
DRbObject.new(obj)
end
end
}
end
def self._load(s)
Marshal::load(s)
end
def _dump(lv)
Marshal.dump(@ary)
end
end
class DRbMessage
def initialize(config) @load_limit = config[:load_limit]
@argc_limit = config[:argc_limit]
end
def dump(obj, error=false) obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped
begin
str = Marshal::dump(obj)
rescue
str = Marshal::dump(make_proxy(obj, error))
end
[str.size].pack('N') + str
end
def load(soc) begin
sz = soc.read(4) rescue
raise(DRbConnError, $!.message, $!.backtrace)
end
raise(DRbConnError, 'connection closed') if sz.nil?
raise(DRbConnError, 'premature header') if sz.size < 4
sz = sz.unpack('N')[0]
raise(DRbConnError, "too large packet #{sz}") if @load_limit < sz
begin
str = soc.read(sz)
rescue
raise(DRbConnError, $!.message, $!.backtrace)
end
raise(DRbConnError, 'connection closed') if str.nil?
raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
DRb.mutex.synchronize do
begin
save = Thread.current[:drb_untaint]
Thread.current[:drb_untaint] = []
Marshal::load(str)
rescue NameError, ArgumentError
DRbUnknown.new($!, str)
ensure
Thread.current[:drb_untaint].each do |x|
x.untaint
end
Thread.current[:drb_untaint] = save
end
end
end
def send_request(stream, ref, msg_id, arg, b) ary = []
ary.push(dump(ref.__drbref))
ary.push(dump(msg_id.id2name))
ary.push(dump(arg.length))
arg.each do |e|
ary.push(dump(e))
end
ary.push(dump(b))
stream.write(ary.join(''))
rescue
raise(DRbConnError, $!.message, $!.backtrace)
end
def recv_request(stream) ref = load(stream)
ro = DRb.to_obj(ref)
msg = load(stream)
argc = load(stream)
raise ArgumentError, 'too many arguments' if @argc_limit < argc
argv = Array.new(argc, nil)
argc.times do |n|
argv[n] = load(stream)
end
block = load(stream)
return ro, msg, argv, block
end
def send_reply(stream, succ, result) stream.write(dump(succ) + dump(result, !succ))
rescue
raise(DRbConnError, $!.message, $!.backtrace)
end
def recv_reply(stream) succ = load(stream)
result = load(stream)
[succ, result]
end
private
def make_proxy(obj, error=false)
if error
DRbRemoteError.new(obj)
else
DRbObject.new(obj)
end
end
end
module DRbProtocol
def add_protocol(prot)
@protocol.push(prot)
end
module_function :add_protocol
def open(uri, config, first=true)
@protocol.each do |prot|
begin
return prot.open(uri, config)
rescue DRbBadScheme
rescue DRbConnError
raise($!)
rescue
raise(DRbConnError, "#{uri} - #{$!.inspect}")
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return open(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end
module_function :open
def open_server(uri, config, first=true)
@protocol.each do |prot|
begin
return prot.open_server(uri, config)
rescue DRbBadScheme
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return open_server(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end
module_function :open_server
def uri_option(uri, config, first=true)
@protocol.each do |prot|
begin
uri, opt = prot.uri_option(uri, config)
return uri, opt
rescue DRbBadScheme
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return uri_option(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end
module_function :uri_option
def auto_load(uri, config) if uri =~ /^drb([a-z0-9]+):/
require("drb/#{$1}") rescue nil
end
end
module_function :auto_load
end
class DRbTCPSocket
private
def self.parse_uri(uri)
if uri =~ /^druby:\/\/(.*?):(\d+)(\?(.*))?$/
host = $1
port = $2.to_i
option = $4
[host, port, option]
else
raise(DRbBadScheme, uri) unless uri =~ /^druby:/
raise(DRbBadURI, 'can\'t parse uri:' + uri)
end
end
public
def self.open(uri, config)
host, port, option = parse_uri(uri)
host.untaint
port.untaint
soc = TCPSocket.open(host, port)
self.new(uri, soc, config)
end
def self.getservername
host = Socket::gethostname
begin
Socket::gethostbyname(host)[0]
rescue
'localhost'
end
end
def self.open_server_inaddr_any(host, port)
infos = Socket::getaddrinfo(host, nil,
Socket::AF_UNSPEC,
Socket::SOCK_STREAM,
0,
Socket::AI_PASSIVE)
family = infos.collect { |af, *_| af }.uniq
case family
when ['AF_INET']
return TCPServer.open('0.0.0.0', port)
when ['AF_INET6']
return TCPServer.open('::', port)
else
return TCPServer.open(port)
end
end
def self.open_server(uri, config)
uri = 'druby://:0' unless uri
host, port, opt = parse_uri(uri)
config = {:tcp_original_host => host}.update(config)
if host.size == 0
host = getservername
soc = open_server_inaddr_any(host, port)
else
soc = TCPServer.open(host, port)
end
port = soc.addr[1] if port == 0
config[:tcp_port] = port
uri = "druby://#{host}:#{port}"
self.new(uri, soc, config)
end
def self.uri_option(uri, config)
host, port, option = parse_uri(uri)
return "druby://#{host}:#{port}", option
end
def initialize(uri, soc, config={})
@uri = uri
@socket = soc
@config = config
@acl = config[:tcp_acl]
@msg = DRbMessage.new(config)
set_sockopt(@socket)
end
attr_reader :uri
def peeraddr
@socket.peeraddr
end
def stream; @socket; end
def send_request(ref, msg_id, arg, b)
@msg.send_request(stream, ref, msg_id, arg, b)
end
def recv_request
@msg.recv_request(stream)
end
def send_reply(succ, result)
@msg.send_reply(stream, succ, result)
end
def recv_reply
@msg.recv_reply(stream)
end
public
def close
if @socket
@socket.close
@socket = nil
end
end
def accept
while true
s = @socket.accept
break if (@acl ? @acl.allow_socket?(s) : true)
s.close
end
if @config[:tcp_original_host].to_s.size == 0
uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
else
uri = @uri
end
self.class.new(uri, s, @config)
end
def alive?
return false unless @socket
if IO.select([@socket], nil, nil, 0)
close
return false
end
true
end
def set_sockopt(soc) soc.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
end
end
module DRbProtocol
@protocol = [DRbTCPSocket] end
class DRbURIOption def initialize(option)
@option = option.to_s
end
attr :option
def to_s; @option; end
def ==(other)
return false unless DRbURIOption === other
@option == other.option
end
def hash
@option.hash
end
alias eql? ==
end
class DRbObject
def self._load(s)
uri, ref = Marshal.load(s)
if DRb.here?(uri)
obj = DRb.to_obj(ref)
if ((! obj.tainted?) && Thread.current[:drb_untaint])
Thread.current[:drb_untaint].push(obj)
end
return obj
end
self.new_with(uri, ref)
end
def self.new_with(uri, ref)
it = self.allocate
it.instance_variable_set('@uri', uri)
it.instance_variable_set('@ref', ref)
it
end
def self.new_with_uri(uri)
self.new(nil, uri)
end
def _dump(lv)
Marshal.dump([@uri, @ref])
end
def initialize(obj, uri=nil)
@uri = nil
@ref = nil
if obj.nil?
return if uri.nil?
@uri, option = DRbProtocol.uri_option(uri, DRb.config)
@ref = DRbURIOption.new(option) unless option.nil?
else
@uri = uri ? uri : (DRb.uri rescue nil)
@ref = obj ? DRb.to_id(obj) : nil
end
end
def __drburi
@uri
end
def __drbref
@ref
end
undef :to_s
undef :to_a if respond_to?(:to_a)
def respond_to?(msg_id, priv=false)
case msg_id
when :_dump
true
when :marshal_dump
false
else
method_missing(:respond_to?, msg_id, priv)
end
end
def method_missing(msg_id, *a, &b)
if DRb.here?(@uri)
obj = DRb.to_obj(@ref)
DRb.current_server.check_insecure_method(obj, msg_id)
return obj.__send__(msg_id, *a, &b)
end
succ, result = self.class.with_friend(@uri) do
DRbConn.open(@uri) do |conn|
conn.send_message(self, msg_id, a, b)
end
end
if succ
return result
elsif DRbUnknown === result
raise result
else
bt = self.class.prepare_backtrace(@uri, result)
result.set_backtrace(bt + caller)
raise result
end
end
def self.with_friend(uri)
friend = DRb.fetch_server(uri)
return yield() unless friend
save = Thread.current['DRb']
Thread.current['DRb'] = { 'server' => friend }
return yield
ensure
Thread.current['DRb'] = save if friend
end
def self.prepare_backtrace(uri, result)
prefix = "(#{uri}) "
bt = []
result.backtrace.each do |x|
break if /`__send__'$/ =~ x
if /^\(druby:\/\// =~ x
bt.push(x)
else
bt.push(prefix + x)
end
end
bt
end
def pretty_print(q) # :nodoc:
q.pp_object(self)
end
def pretty_print_cycle(q) # :nodoc:
q.object_address_group(self) {
q.breakable
q.text '...'
}
end
end
# Class handling the connection between a DRbObject and the
# server the real object lives on.
#
# This class maintains a pool of connections, to reduce the
# overhead of starting and closing down connections for each
# method call.
#
# This class is used internally by DRbObject. The user does
# not normally need to deal with it directly.
class DRbConn
POOL_SIZE = 16 # :nodoc:
@mutex = Mutex.new
@pool = []
def self.open(remote_uri) # :nodoc:
begin
conn = nil
@mutex.synchronize do
#FIXME
new_pool = []
@pool.each do |c|
if conn.nil? and c.uri == remote_uri
conn = c if c.alive?
else
new_pool.push c
end
end
@pool = new_pool
end
conn = self.new(remote_uri) unless conn
succ, result = yield(conn)
return succ, result
ensure
if conn
if succ
@mutex.synchronize do
@pool.unshift(conn)
@pool.pop.close while @pool.size > POOL_SIZE
end
else
conn.close
end
end
end
end
def initialize(remote_uri) # :nodoc:
@uri = remote_uri
@protocol = DRbProtocol.open(remote_uri, DRb.config)
end
attr_reader :uri # :nodoc:
def send_message(ref, msg_id, arg, block) # :nodoc:
@protocol.send_request(ref, msg_id, arg, block)
@protocol.recv_reply
end
def close # :nodoc:
@protocol.close
@protocol = nil
end
def alive? # :nodoc:
return false unless @protocol
@protocol.alive?
end
end
# Class representing a drb server instance.
#
# A DRbServer must be running in the local process before any incoming
# dRuby calls can be accepted, or any local objects can be passed as
# dRuby references to remote processes, even if those local objects are
# never actually called remotely. You do not need to start a DRbServer
# in the local process if you are only making outgoing dRuby calls
# passing marshalled parameters.
#
# Unless multiple servers are being used, the local DRbServer is normally
# started by calling DRb.start_service.
class DRbServer
@@acl = nil
@@idconv = DRbIdConv.new
@@secondary_server = nil
@@argc_limit = 256
@@load_limit = 256 * 102400
@@verbose = false
@@safe_level = 0
# Set the default value for the :argc_limit option.
#
# See #new(). The initial default value is 256.
def self.default_argc_limit(argc)
@@argc_limit = argc
end
# Set the default value for the :load_limit option.
#
# See #new(). The initial default value is 25 MB.
def self.default_load_limit(sz)
@@load_limit = sz
end
# Set the default value for the :acl option.
#
# See #new(). The initial default value is nil.
def self.default_acl(acl)
@@acl = acl
end
# Set the default value for the :id_conv option.
#
# See #new(). The initial default value is a DRbIdConv instance.
def self.default_id_conv(idconv)
@@idconv = idconv
end
def self.default_safe_level(level)
@@safe_level = level
end
# Set the default value of the :verbose option.
#
# See #new(). The initial default value is false.
def self.verbose=(on)
@@verbose = on
end
# Get the default value of the :verbose option.
def self.verbose
@@verbose
end
def self.make_config(hash={}) # :nodoc:
default_config = {
:idconv => @@idconv,
:verbose => @@verbose,
:tcp_acl => @@acl,
:load_limit => @@load_limit,
:argc_limit => @@argc_limit,
:safe_level => @@safe_level
}
default_config.update(hash)
end
# Create a new DRbServer instance.
#
# +uri+ is the URI to bind to. This is normally of the form
# 'druby://<hostname>:<port>' where <hostname> is a hostname of
# the local machine. If nil, then the system's default hostname
# will be bound to, on a port selected by the system; these value
# can be retrieved from the +uri+ attribute. 'druby:' specifies
# the default dRuby transport protocol: another protocol, such
# as 'drbunix:', can be specified instead.
#
# +front+ is the front object for the server, that is, the object
# to which remote method calls on the server will be passed. If
# nil, then the server will not accept remote method calls.
#
# If +config_or_acl+ is a hash, it is the configuration to
# use for this server. The following options are recognised:
#
# :idconv :: an id-to-object conversion object. This defaults
# to an instance of the class DRb::DRbIdConv.
# :verbose :: if true, all unsuccessful remote calls on objects
# in the server will be logged to $stdout. false
# by default.
# :tcp_acl :: the access control list for this server. See
# the ACL class from the main dRuby distribution.
# :load_limit :: the maximum message size in bytes accepted by
# the server. Defaults to 25 MB (26214400).
# :argc_limit :: the maximum number of arguments to a remote
# method accepted by the server. Defaults to
# 256.
#
# The default values of these options can be modified on
# a class-wide basis by the class methods #default_argc_limit,
# #default_load_limit, #default_acl, #default_id_conv,
# and #verbose=
#
# If +config_or_acl+ is not a hash, but is not nil, it is
# assumed to be the access control list for this server.
# See the :tcp_acl option for more details.
#
# If no other server is currently set as the primary server,
# this will become the primary server.
#
# The server will immediately start running in its own thread.
def initialize(uri=nil, front=nil, config_or_acl=nil)
if Hash === config_or_acl
config = config_or_acl.dup
else
acl = config_or_acl || @@acl
config = {
:tcp_acl => acl
}
end
@config = self.class.make_config(config)
@protocol = DRbProtocol.open_server(uri, @config)
@uri = @protocol.uri
@front = front
@idconv = @config[:idconv]
@safe_level = @config[:safe_level]
@grp = ThreadGroup.new
@thread = run
DRb.regist_server(self)
end
# The URI of this DRbServer.
attr_reader :uri
# The main thread of this DRbServer.
#
# This is the thread that listens for and accepts connections
# from clients, not that handles each client's request-response
# session.
attr_reader :thread
# The front object of the DRbServer.
#
# This object receives remote method calls made on the server's
# URI alone, with an object id.
attr_reader :front
# The configuration of this DRbServer
attr_reader :config
attr_reader :safe_level
# Set whether to operate in verbose mode.
#
# In verbose mode, failed calls are logged to stdout.
def verbose=(v); @config[:verbose]=v; end
# Get whether the server is in verbose mode.
#
# In verbose mode, failed calls are logged to stdout.
def verbose; @config[:verbose]; end
# Is this server alive?
def alive?
@thread.alive?
end
# Stop this server.
def stop_service
DRb.remove_server(self)
if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
Thread.current['DRb']['stop_service'] = true
else
@thread.kill
end
end
# Convert a dRuby reference to the local object it refers to.
def to_obj(ref)
return front if ref.nil?
return front[ref.to_s] if DRbURIOption === ref
@idconv.to_obj(ref)
end
# Convert a local object to a dRuby reference.
def to_id(obj)
return nil if obj.__id__ == front.__id__
@idconv.to_id(obj)
end
private
def kill_sub_thread
Thread.new do
grp = ThreadGroup.new
grp.add(Thread.current)
list = @grp.list
while list.size > 0
list.each do |th|
th.kill if th.alive?
end
list = @grp.list
end
end
end
def run
Thread.start do
begin
while true
main_loop
end
ensure
@protocol.close if @protocol
kill_sub_thread
end
end
end
# List of insecure methods.
#
# These methods are not callable via dRuby.
INSECURE_METHOD = [
:__send__
]
# Has a method been included in the list of insecure methods?
def insecure_method?(msg_id)
INSECURE_METHOD.include?(msg_id)
end
# Coerce an object to a string, providing our own representation if
# to_s is not defined for the object.
def any_to_s(obj)
obj.to_s + ":#{obj.class}"
rescue
sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
end
# Check that a method is callable via dRuby.
#
# +obj+ is the object we want to invoke the method on. +msg_id+ is the
# method name, as a Symbol.
#
# If the method is an insecure method (see #insecure_method?) a
# SecurityError is thrown. If the method is private or undefined,
# a NameError is thrown.
def check_insecure_method(obj, msg_id)
return true if Proc === obj && msg_id == :__drb_yield
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
if obj.private_methods.include?(msg_id.to_s)
desc = any_to_s(obj)
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
elsif obj.protected_methods.include?(msg_id.to_s)
desc = any_to_s(obj)
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
else
true
end
end
public :check_insecure_method
class InvokeMethod # :nodoc:
def initialize(drb_server, client)
@drb_server = drb_server
@safe_level = drb_server.safe_level
@client = client
end
def perform
@result = nil
@succ = false
setup_message
if $SAFE < @safe_level
info = Thread.current['DRb']
if @block
@result = Thread.new {
Thread.current['DRb'] = info
$SAFE = @safe_level
perform_with_block
}.value
else
@result = Thread.new {
Thread.current['DRb'] = info
$SAFE = @safe_level
perform_without_block
}.value
end
else
if @block
@result = perform_with_block
else
@result = perform_without_block
end
end
@succ = true
if @msg_id == :to_ary && @result.class == Array
@result = DRbArray.new(@result)
end
return @succ, @result
rescue StandardError, ScriptError, Interrupt
@result = $!
return @succ, @result
end
private
def init_with_client
obj, msg, argv, block = @client.recv_request
@obj = obj
@msg_id = msg.intern
@argv = argv
@block = block
end
def check_insecure_method
@drb_server.check_insecure_method(@obj, @msg_id)
end
def setup_message
init_with_client
check_insecure_method
end
def perform_without_block
if Proc === @obj && @msg_id == :__drb_yield
if @argv.size == 1
ary = @argv
else
ary = [@argv]
end
ary.collect(&@obj)[0]
else
@obj.__send__(@msg_id, *@argv)
end
end
end
if RUBY_VERSION >= '1.8'
require 'drb/invokemethod'
class InvokeMethod
include InvokeMethod18Mixin
end
else
require 'drb/invokemethod16'
class InvokeMethod
include InvokeMethod16Mixin
end
end
# The main loop performed by a DRbServer's internal thread.
#
# Accepts a connection from a client, and starts up its own
# thread to handle it. This thread loops, receiving requests
# from the client, invoking them on a local object, and
# returning responses, until the client closes the connection
# or a local method call fails.
def main_loop
Thread.start(@protocol.accept) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
'server' => self }
loop do
begin
succ = false
invoke_method = InvokeMethod.new(self, client)
succ, result = invoke_method.perform
if !succ && verbose
p result
result.backtrace.each do |x|
puts x
end
end
client.send_reply(succ, result) rescue nil
ensure
client.close unless succ
if Thread.current['DRb']['stop_service']
Thread.new { stop_service }
end
break unless succ
end
end
end
end
end
@primary_server = nil
# Start a dRuby server locally.
#
# The new dRuby server will become the primary server, even
# if another server is currently the primary server.
#
# +uri+ is the URI for the server to bind to. If nil,
# the server will bind to random port on the default local host
# name and use the default dRuby protocol.
#
# +front+ is the server's front object. This may be nil.
#
# +config+ is the configuration for the new server. This may
# be nil.
#
# See DRbServer::new.
def start_service(uri=nil, front=nil, config=nil)
@primary_server = DRbServer.new(uri, front, config)
end
module_function :start_service
# The primary local dRuby server.
#
# This is the server created by the #start_service call.
attr_accessor :primary_server
module_function :primary_server=, :primary_server
# Get the 'current' server.
#
# In the context of execution taking place within the main
# thread of a dRuby server (typically, as a result of a remote
# call on the server or one of its objects), the current
# server is that server. Otherwise, the current server is
# the primary server.
#
# If the above rule fails to find a server, a DRbServerNotFound
# error is raised.
def current_server
drb = Thread.current['DRb']
server = (drb && drb['server']) ? drb['server'] : @primary_server
raise DRbServerNotFound unless server
return server
end
module_function :current_server
# Stop the local dRuby server.
#
# This operates on the primary server. If there is no primary
# server currently running, it is a noop.
def stop_service
@primary_server.stop_service if @primary_server
@primary_server = nil
end
module_function :stop_service
# Get the URI defining the local dRuby space.
#
# This is the URI of the current server. See #current_server.
def uri
drb = Thread.current['DRb']
client = (drb && drb['client'])
if client
uri = client.uri
return uri if uri
end
current_server.uri
end
module_function :uri
# Is +uri+ the URI for the current local server?
def here?(uri)
(current_server.uri rescue nil) == uri
end
module_function :here?
# Get the configuration of the current server.
#
# If there is no current server, this returns the default configuration.
# See #current_server and DRbServer::make_config.
def config
current_server.config
rescue
DRbServer.make_config
end
module_function :config
# Get the front object of the current server.
#
# This raises a DRbServerNotFound error if there is no current server.
# See #current_server.
def front
current_server.front
end
module_function :front
# Convert a reference into an object using the current server.
#
# This raises a DRbServerNotFound error if there is no current server.
# See #current_server.
def to_obj(ref)
current_server.to_obj(ref)
end
# Get a reference id for an object using the current server.
#
# This raises a DRbServerNotFound error if there is no current server.
# See #current_server.
def to_id(obj)
current_server.to_id(obj)
end
module_function :to_id
module_function :to_obj
# Get the thread of the primary server.
#
# This returns nil if there is no primary server. See #primary_server.
def thread
@primary_server ? @primary_server.thread : nil
end
module_function :thread
# Set the default id conv object.
#
# See DRbServer#default_id_conv.
def install_id_conv(idconv)
DRbServer.default_id_conv(idconv)
end
module_function :install_id_conv
# Set the default acl.
#
# See DRb::DRbServer.default_acl.
def install_acl(acl)
DRbServer.default_acl(acl)
end
module_function :install_acl
@mutex = Mutex.new
def mutex
@mutex
end
module_function :mutex
@server = {}
def regist_server(server)
@server[server.uri] = server
mutex.synchronize do
@primary_server = server unless @primary_server
end
end
module_function :regist_server
def remove_server(server)
@server.delete(server.uri)
end
module_function :remove_server
def fetch_server(uri)
@server[uri]
end
module_function :fetch_server
end
DRbObject = DRb::DRbObject
DRbUndumped = DRb::DRbUndumped
DRbIdConv = DRb::DRbIdConv