Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/drb
File: drb.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# = drb/drb.rb
[2] Fix | Delete
#
[3] Fix | Delete
# Distributed Ruby: _dRuby_ version 2.0.4
[4] Fix | Delete
#
[5] Fix | Delete
# Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or
[6] Fix | Delete
# modify it under the same terms as Ruby.
[7] Fix | Delete
#
[8] Fix | Delete
# Author:: Masatoshi SEKI
[9] Fix | Delete
#
[10] Fix | Delete
# Documentation:: William Webber (william@williamwebber.com)
[11] Fix | Delete
#
[12] Fix | Delete
# == Overview
[13] Fix | Delete
#
[14] Fix | Delete
# dRuby is a distributed object system for Ruby. It allows an object in one
[15] Fix | Delete
# Ruby process to invoke methods on an object in another Ruby process on the
[16] Fix | Delete
# same or a different machine.
[17] Fix | Delete
#
[18] Fix | Delete
# The Ruby standard library contains the core classes of the dRuby package.
[19] Fix | Delete
# However, the full package also includes access control lists and the
[20] Fix | Delete
# Rinda tuple-space distributed task management system, as well as a
[21] Fix | Delete
# large number of samples. The full dRuby package can be downloaded from
[22] Fix | Delete
# the dRuby home page (see *References*).
[23] Fix | Delete
#
[24] Fix | Delete
# For an introduction and examples of usage see the documentation to the
[25] Fix | Delete
# DRb module.
[26] Fix | Delete
#
[27] Fix | Delete
# == References
[28] Fix | Delete
#
[29] Fix | Delete
# [http://www2a.biglobe.ne.jp/~seki/ruby/druby.html]
[30] Fix | Delete
# The dRuby home page, in Japanese. Contains the full dRuby package
[31] Fix | Delete
# and links to other Japanese-language sources.
[32] Fix | Delete
#
[33] Fix | Delete
# [http://www2a.biglobe.ne.jp/~seki/ruby/druby.en.html]
[34] Fix | Delete
# The English version of the dRuby home page.
[35] Fix | Delete
#
[36] Fix | Delete
# [http://pragprog.com/book/sidruby/the-druby-book]
[37] Fix | Delete
# The dRuby Book: Distributed and Parallel Computing with Ruby
[38] Fix | Delete
# by Masatoshi Seki and Makoto Inoue
[39] Fix | Delete
#
[40] Fix | Delete
# [http://www.ruby-doc.org/docs/ProgrammingRuby/html/ospace.html]
[41] Fix | Delete
# The chapter from *Programming* *Ruby* by Dave Thomas and Andy Hunt
[42] Fix | Delete
# which discusses dRuby.
[43] Fix | Delete
#
[44] Fix | Delete
# [http://www.clio.ne.jp/home/web-i31s/Flotuard/Ruby/PRC2K_seki/dRuby.en.html]
[45] Fix | Delete
# Translation of presentation on Ruby by Masatoshi Seki.
[46] Fix | Delete
[47] Fix | Delete
require 'socket'
[48] Fix | Delete
require 'io/wait'
[49] Fix | Delete
require 'monitor'
[50] Fix | Delete
require_relative 'eq'
[51] Fix | Delete
[52] Fix | Delete
#
[53] Fix | Delete
# == Overview
[54] Fix | Delete
#
[55] Fix | Delete
# dRuby is a distributed object system for Ruby. It is written in
[56] Fix | Delete
# pure Ruby and uses its own protocol. No add-in services are needed
[57] Fix | Delete
# beyond those provided by the Ruby runtime, such as TCP sockets. It
[58] Fix | Delete
# does not rely on or interoperate with other distributed object
[59] Fix | Delete
# systems such as CORBA, RMI, or .NET.
[60] Fix | Delete
#
[61] Fix | Delete
# dRuby allows methods to be called in one Ruby process upon a Ruby
[62] Fix | Delete
# object located in another Ruby process, even on another machine.
[63] Fix | Delete
# References to objects can be passed between processes. Method
[64] Fix | Delete
# arguments and return values are dumped and loaded in marshalled
[65] Fix | Delete
# format. All of this is done transparently to both the caller of the
[66] Fix | Delete
# remote method and the object that it is called upon.
[67] Fix | Delete
#
[68] Fix | Delete
# An object in a remote process is locally represented by a
[69] Fix | Delete
# DRb::DRbObject instance. This acts as a sort of proxy for the
[70] Fix | Delete
# remote object. Methods called upon this DRbObject instance are
[71] Fix | Delete
# forwarded to its remote object. This is arranged dynamically at run
[72] Fix | Delete
# time. There are no statically declared interfaces for remote
[73] Fix | Delete
# objects, such as CORBA's IDL.
[74] Fix | Delete
#
[75] Fix | Delete
# dRuby calls made into a process are handled by a DRb::DRbServer
[76] Fix | Delete
# instance within that process. This reconstitutes the method call,
[77] Fix | Delete
# invokes it upon the specified local object, and returns the value to
[78] Fix | Delete
# the remote caller. Any object can receive calls over dRuby. There
[79] Fix | Delete
# is no need to implement a special interface, or mixin special
[80] Fix | Delete
# functionality. Nor, in the general case, does an object need to
[81] Fix | Delete
# explicitly register itself with a DRbServer in order to receive
[82] Fix | Delete
# dRuby calls.
[83] Fix | Delete
#
[84] Fix | Delete
# One process wishing to make dRuby calls upon another process must
[85] Fix | Delete
# somehow obtain an initial reference to an object in the remote
[86] Fix | Delete
# process by some means other than as the return value of a remote
[87] Fix | Delete
# method call, as there is initially no remote object reference it can
[88] Fix | Delete
# invoke a method upon. This is done by attaching to the server by
[89] Fix | Delete
# URI. Each DRbServer binds itself to a URI such as
[90] Fix | Delete
# 'druby://example.com:8787'. A DRbServer can have an object attached
[91] Fix | Delete
# to it that acts as the server's *front* *object*. A DRbObject can
[92] Fix | Delete
# be explicitly created from the server's URI. This DRbObject's
[93] Fix | Delete
# remote object will be the server's front object. This front object
[94] Fix | Delete
# can then return references to other Ruby objects in the DRbServer's
[95] Fix | Delete
# process.
[96] Fix | Delete
#
[97] Fix | Delete
# Method calls made over dRuby behave largely the same as normal Ruby
[98] Fix | Delete
# method calls made within a process. Method calls with blocks are
[99] Fix | Delete
# supported, as are raising exceptions. In addition to a method's
[100] Fix | Delete
# standard errors, a dRuby call may also raise one of the
[101] Fix | Delete
# dRuby-specific errors, all of which are subclasses of DRb::DRbError.
[102] Fix | Delete
#
[103] Fix | Delete
# Any type of object can be passed as an argument to a dRuby call or
[104] Fix | Delete
# returned as its return value. By default, such objects are dumped
[105] Fix | Delete
# or marshalled at the local end, then loaded or unmarshalled at the
[106] Fix | Delete
# remote end. The remote end therefore receives a copy of the local
[107] Fix | Delete
# object, not a distributed reference to it; methods invoked upon this
[108] Fix | Delete
# copy are executed entirely in the remote process, not passed on to
[109] Fix | Delete
# the local original. This has semantics similar to pass-by-value.
[110] Fix | Delete
#
[111] Fix | Delete
# However, if an object cannot be marshalled, a dRuby reference to it
[112] Fix | Delete
# is passed or returned instead. This will turn up at the remote end
[113] Fix | Delete
# as a DRbObject instance. All methods invoked upon this remote proxy
[114] Fix | Delete
# are forwarded to the local object, as described in the discussion of
[115] Fix | Delete
# DRbObjects. This has semantics similar to the normal Ruby
[116] Fix | Delete
# pass-by-reference.
[117] Fix | Delete
#
[118] Fix | Delete
# The easiest way to signal that we want an otherwise marshallable
[119] Fix | Delete
# object to be passed or returned as a DRbObject reference, rather
[120] Fix | Delete
# than marshalled and sent as a copy, is to include the
[121] Fix | Delete
# DRb::DRbUndumped mixin module.
[122] Fix | Delete
#
[123] Fix | Delete
# dRuby supports calling remote methods with blocks. As blocks (or
[124] Fix | Delete
# rather the Proc objects that represent them) are not marshallable,
[125] Fix | Delete
# the block executes in the local, not the remote, context. Each
[126] Fix | Delete
# value yielded to the block is passed from the remote object to the
[127] Fix | Delete
# local block, then the value returned by each block invocation is
[128] Fix | Delete
# passed back to the remote execution context to be collected, before
[129] Fix | Delete
# the collected values are finally returned to the local context as
[130] Fix | Delete
# the return value of the method invocation.
[131] Fix | Delete
#
[132] Fix | Delete
# == Examples of usage
[133] Fix | Delete
#
[134] Fix | Delete
# For more dRuby samples, see the +samples+ directory in the full
[135] Fix | Delete
# dRuby distribution.
[136] Fix | Delete
#
[137] Fix | Delete
# === dRuby in client/server mode
[138] Fix | Delete
#
[139] Fix | Delete
# This illustrates setting up a simple client-server drb
[140] Fix | Delete
# system. Run the server and client code in different terminals,
[141] Fix | Delete
# starting the server code first.
[142] Fix | Delete
#
[143] Fix | Delete
# ==== Server code
[144] Fix | Delete
#
[145] Fix | Delete
# require 'drb/drb'
[146] Fix | Delete
#
[147] Fix | Delete
# # The URI for the server to connect to
[148] Fix | Delete
# URI="druby://localhost:8787"
[149] Fix | Delete
#
[150] Fix | Delete
# class TimeServer
[151] Fix | Delete
#
[152] Fix | Delete
# def get_current_time
[153] Fix | Delete
# return Time.now
[154] Fix | Delete
# end
[155] Fix | Delete
#
[156] Fix | Delete
# end
[157] Fix | Delete
#
[158] Fix | Delete
# # The object that handles requests on the server
[159] Fix | Delete
# FRONT_OBJECT=TimeServer.new
[160] Fix | Delete
#
[161] Fix | Delete
# DRb.start_service(URI, FRONT_OBJECT)
[162] Fix | Delete
# # Wait for the drb server thread to finish before exiting.
[163] Fix | Delete
# DRb.thread.join
[164] Fix | Delete
#
[165] Fix | Delete
# ==== Client code
[166] Fix | Delete
#
[167] Fix | Delete
# require 'drb/drb'
[168] Fix | Delete
#
[169] Fix | Delete
# # The URI to connect to
[170] Fix | Delete
# SERVER_URI="druby://localhost:8787"
[171] Fix | Delete
#
[172] Fix | Delete
# # Start a local DRbServer to handle callbacks.
[173] Fix | Delete
# #
[174] Fix | Delete
# # Not necessary for this small example, but will be required
[175] Fix | Delete
# # as soon as we pass a non-marshallable object as an argument
[176] Fix | Delete
# # to a dRuby call.
[177] Fix | Delete
# #
[178] Fix | Delete
# # Note: this must be called at least once per process to take any effect.
[179] Fix | Delete
# # This is particularly important if your application forks.
[180] Fix | Delete
# DRb.start_service
[181] Fix | Delete
#
[182] Fix | Delete
# timeserver = DRbObject.new_with_uri(SERVER_URI)
[183] Fix | Delete
# puts timeserver.get_current_time
[184] Fix | Delete
#
[185] Fix | Delete
# === Remote objects under dRuby
[186] Fix | Delete
#
[187] Fix | Delete
# This example illustrates returning a reference to an object
[188] Fix | Delete
# from a dRuby call. The Logger instances live in the server
[189] Fix | Delete
# process. References to them are returned to the client process,
[190] Fix | Delete
# where methods can be invoked upon them. These methods are
[191] Fix | Delete
# executed in the server process.
[192] Fix | Delete
#
[193] Fix | Delete
# ==== Server code
[194] Fix | Delete
#
[195] Fix | Delete
# require 'drb/drb'
[196] Fix | Delete
#
[197] Fix | Delete
# URI="druby://localhost:8787"
[198] Fix | Delete
#
[199] Fix | Delete
# class Logger
[200] Fix | Delete
#
[201] Fix | Delete
# # Make dRuby send Logger instances as dRuby references,
[202] Fix | Delete
# # not copies.
[203] Fix | Delete
# include DRb::DRbUndumped
[204] Fix | Delete
#
[205] Fix | Delete
# def initialize(n, fname)
[206] Fix | Delete
# @name = n
[207] Fix | Delete
# @filename = fname
[208] Fix | Delete
# end
[209] Fix | Delete
#
[210] Fix | Delete
# def log(message)
[211] Fix | Delete
# File.open(@filename, "a") do |f|
[212] Fix | Delete
# f.puts("#{Time.now}: #{@name}: #{message}")
[213] Fix | Delete
# end
[214] Fix | Delete
# end
[215] Fix | Delete
#
[216] Fix | Delete
# end
[217] Fix | Delete
#
[218] Fix | Delete
# # We have a central object for creating and retrieving loggers.
[219] Fix | Delete
# # This retains a local reference to all loggers created. This
[220] Fix | Delete
# # is so an existing logger can be looked up by name, but also
[221] Fix | Delete
# # to prevent loggers from being garbage collected. A dRuby
[222] Fix | Delete
# # reference to an object is not sufficient to prevent it being
[223] Fix | Delete
# # garbage collected!
[224] Fix | Delete
# class LoggerFactory
[225] Fix | Delete
#
[226] Fix | Delete
# def initialize(bdir)
[227] Fix | Delete
# @basedir = bdir
[228] Fix | Delete
# @loggers = {}
[229] Fix | Delete
# end
[230] Fix | Delete
#
[231] Fix | Delete
# def get_logger(name)
[232] Fix | Delete
# if !@loggers.has_key? name
[233] Fix | Delete
# # make the filename safe, then declare it to be so
[234] Fix | Delete
# fname = name.gsub(/[.\/\\\:]/, "_")
[235] Fix | Delete
# @loggers[name] = Logger.new(name, @basedir + "/" + fname)
[236] Fix | Delete
# end
[237] Fix | Delete
# return @loggers[name]
[238] Fix | Delete
# end
[239] Fix | Delete
#
[240] Fix | Delete
# end
[241] Fix | Delete
#
[242] Fix | Delete
# FRONT_OBJECT=LoggerFactory.new("/tmp/dlog")
[243] Fix | Delete
#
[244] Fix | Delete
# DRb.start_service(URI, FRONT_OBJECT)
[245] Fix | Delete
# DRb.thread.join
[246] Fix | Delete
#
[247] Fix | Delete
# ==== Client code
[248] Fix | Delete
#
[249] Fix | Delete
# require 'drb/drb'
[250] Fix | Delete
#
[251] Fix | Delete
# SERVER_URI="druby://localhost:8787"
[252] Fix | Delete
#
[253] Fix | Delete
# DRb.start_service
[254] Fix | Delete
#
[255] Fix | Delete
# log_service=DRbObject.new_with_uri(SERVER_URI)
[256] Fix | Delete
#
[257] Fix | Delete
# ["loga", "logb", "logc"].each do |logname|
[258] Fix | Delete
#
[259] Fix | Delete
# logger=log_service.get_logger(logname)
[260] Fix | Delete
#
[261] Fix | Delete
# logger.log("Hello, world!")
[262] Fix | Delete
# logger.log("Goodbye, world!")
[263] Fix | Delete
# logger.log("=== EOT ===")
[264] Fix | Delete
#
[265] Fix | Delete
# end
[266] Fix | Delete
#
[267] Fix | Delete
# == Security
[268] Fix | Delete
#
[269] Fix | Delete
# As with all network services, security needs to be considered when
[270] Fix | Delete
# using dRuby. By allowing external access to a Ruby object, you are
[271] Fix | Delete
# not only allowing outside clients to call the methods you have
[272] Fix | Delete
# defined for that object, but by default to execute arbitrary Ruby
[273] Fix | Delete
# code on your server. Consider the following:
[274] Fix | Delete
#
[275] Fix | Delete
# # !!! UNSAFE CODE !!!
[276] Fix | Delete
# ro = DRbObject::new_with_uri("druby://your.server.com:8989")
[277] Fix | Delete
# class << ro
[278] Fix | Delete
# undef :instance_eval # force call to be passed to remote object
[279] Fix | Delete
# end
[280] Fix | Delete
# ro.instance_eval("`rm -rf *`")
[281] Fix | Delete
#
[282] Fix | Delete
# The dangers posed by instance_eval and friends are such that a
[283] Fix | Delete
# DRbServer should only be used when clients are trusted.
[284] Fix | Delete
#
[285] Fix | Delete
# A DRbServer can be configured with an access control list to
[286] Fix | Delete
# selectively allow or deny access from specified IP addresses. The
[287] Fix | Delete
# main druby distribution provides the ACL class for this purpose. In
[288] Fix | Delete
# general, this mechanism should only be used alongside, rather than
[289] Fix | Delete
# as a replacement for, a good firewall.
[290] Fix | Delete
#
[291] Fix | Delete
# == dRuby internals
[292] Fix | Delete
#
[293] Fix | Delete
# dRuby is implemented using three main components: a remote method
[294] Fix | Delete
# call marshaller/unmarshaller; a transport protocol; and an
[295] Fix | Delete
# ID-to-object mapper. The latter two can be directly, and the first
[296] Fix | Delete
# indirectly, replaced, in order to provide different behaviour and
[297] Fix | Delete
# capabilities.
[298] Fix | Delete
#
[299] Fix | Delete
# Marshalling and unmarshalling of remote method calls is performed by
[300] Fix | Delete
# a DRb::DRbMessage instance. This uses the Marshal module to dump
[301] Fix | Delete
# the method call before sending it over the transport layer, then
[302] Fix | Delete
# reconstitute it at the other end. There is normally no need to
[303] Fix | Delete
# replace this component, and no direct way is provided to do so.
[304] Fix | Delete
# However, it is possible to implement an alternative marshalling
[305] Fix | Delete
# scheme as part of an implementation of the transport layer.
[306] Fix | Delete
#
[307] Fix | Delete
# The transport layer is responsible for opening client and server
[308] Fix | Delete
# network connections and forwarding dRuby request across them.
[309] Fix | Delete
# Normally, it uses DRb::DRbMessage internally to manage marshalling
[310] Fix | Delete
# and unmarshalling. The transport layer is managed by
[311] Fix | Delete
# DRb::DRbProtocol. Multiple protocols can be installed in
[312] Fix | Delete
# DRbProtocol at the one time; selection between them is determined by
[313] Fix | Delete
# the scheme of a dRuby URI. The default transport protocol is
[314] Fix | Delete
# selected by the scheme 'druby:', and implemented by
[315] Fix | Delete
# DRb::DRbTCPSocket. This uses plain TCP/IP sockets for
[316] Fix | Delete
# communication. An alternative protocol, using UNIX domain sockets,
[317] Fix | Delete
# is implemented by DRb::DRbUNIXSocket in the file drb/unix.rb, and
[318] Fix | Delete
# selected by the scheme 'drbunix:'. A sample implementation over
[319] Fix | Delete
# HTTP can be found in the samples accompanying the main dRuby
[320] Fix | Delete
# distribution.
[321] Fix | Delete
#
[322] Fix | Delete
# The ID-to-object mapping component maps dRuby object ids to the
[323] Fix | Delete
# objects they refer to, and vice versa. The implementation to use
[324] Fix | Delete
# can be specified as part of a DRb::DRbServer's configuration. The
[325] Fix | Delete
# default implementation is provided by DRb::DRbIdConv. It uses an
[326] Fix | Delete
# object's ObjectSpace id as its dRuby id. This means that the dRuby
[327] Fix | Delete
# reference to that object only remains meaningful for the lifetime of
[328] Fix | Delete
# the object's process and the lifetime of the object within that
[329] Fix | Delete
# process. A modified implementation is provided by DRb::TimerIdConv
[330] Fix | Delete
# in the file drb/timeridconv.rb. This implementation retains a local
[331] Fix | Delete
# reference to all objects exported over dRuby for a configurable
[332] Fix | Delete
# period of time (defaulting to ten minutes), to prevent them being
[333] Fix | Delete
# garbage-collected within this time. Another sample implementation
[334] Fix | Delete
# is provided in sample/name.rb in the main dRuby distribution. This
[335] Fix | Delete
# allows objects to specify their own id or "name". A dRuby reference
[336] Fix | Delete
# can be made persistent across processes by having each process
[337] Fix | Delete
# register an object using the same dRuby name.
[338] Fix | Delete
#
[339] Fix | Delete
module DRb
[340] Fix | Delete
[341] Fix | Delete
# Superclass of all errors raised in the DRb module.
[342] Fix | Delete
class DRbError < RuntimeError; end
[343] Fix | Delete
[344] Fix | Delete
# Error raised when an error occurs on the underlying communication
[345] Fix | Delete
# protocol.
[346] Fix | Delete
class DRbConnError < DRbError; end
[347] Fix | Delete
[348] Fix | Delete
# Class responsible for converting between an object and its id.
[349] Fix | Delete
#
[350] Fix | Delete
# This, the default implementation, uses an object's local ObjectSpace
[351] Fix | Delete
# __id__ as its id. This means that an object's identification over
[352] Fix | Delete
# drb remains valid only while that object instance remains alive
[353] Fix | Delete
# within the server runtime.
[354] Fix | Delete
#
[355] Fix | Delete
# For alternative mechanisms, see DRb::TimerIdConv in drb/timeridconv.rb
[356] Fix | Delete
# and DRbNameIdConv in sample/name.rb in the full drb distribution.
[357] Fix | Delete
class DRbIdConv
[358] Fix | Delete
[359] Fix | Delete
# Convert an object reference id to an object.
[360] Fix | Delete
#
[361] Fix | Delete
# This implementation looks up the reference id in the local object
[362] Fix | Delete
# space and returns the object it refers to.
[363] Fix | Delete
def to_obj(ref)
[364] Fix | Delete
ObjectSpace._id2ref(ref)
[365] Fix | Delete
end
[366] Fix | Delete
[367] Fix | Delete
# Convert an object into a reference id.
[368] Fix | Delete
#
[369] Fix | Delete
# This implementation returns the object's __id__ in the local
[370] Fix | Delete
# object space.
[371] Fix | Delete
def to_id(obj)
[372] Fix | Delete
case obj
[373] Fix | Delete
when Object
[374] Fix | Delete
obj.nil? ? nil : obj.__id__
[375] Fix | Delete
when BasicObject
[376] Fix | Delete
obj.__id__
[377] Fix | Delete
end
[378] Fix | Delete
end
[379] Fix | Delete
end
[380] Fix | Delete
[381] Fix | Delete
# Mixin module making an object undumpable or unmarshallable.
[382] Fix | Delete
#
[383] Fix | Delete
# If an object which includes this module is returned by method
[384] Fix | Delete
# called over drb, then the object remains in the server space
[385] Fix | Delete
# and a reference to the object is returned, rather than the
[386] Fix | Delete
# object being marshalled and moved into the client space.
[387] Fix | Delete
module DRbUndumped
[388] Fix | Delete
def _dump(dummy) # :nodoc:
[389] Fix | Delete
raise TypeError, 'can\'t dump'
[390] Fix | Delete
end
[391] Fix | Delete
end
[392] Fix | Delete
[393] Fix | Delete
# Error raised by the DRb module when an attempt is made to refer to
[394] Fix | Delete
# the context's current drb server but the context does not have one.
[395] Fix | Delete
# See #current_server.
[396] Fix | Delete
class DRbServerNotFound < DRbError; end
[397] Fix | Delete
[398] Fix | Delete
# Error raised by the DRbProtocol module when it cannot find any
[399] Fix | Delete
# protocol implementation support the scheme specified in a URI.
[400] Fix | Delete
class DRbBadURI < DRbError; end
[401] Fix | Delete
[402] Fix | Delete
# Error raised by a dRuby protocol when it doesn't support the
[403] Fix | Delete
# scheme specified in a URI. See DRb::DRbProtocol.
[404] Fix | Delete
class DRbBadScheme < DRbError; end
[405] Fix | Delete
[406] Fix | Delete
# An exception wrapping a DRb::DRbUnknown object
[407] Fix | Delete
class DRbUnknownError < DRbError
[408] Fix | Delete
[409] Fix | Delete
# Create a new DRbUnknownError for the DRb::DRbUnknown object +unknown+
[410] Fix | Delete
def initialize(unknown)
[411] Fix | Delete
@unknown = unknown
[412] Fix | Delete
super(unknown.name)
[413] Fix | Delete
end
[414] Fix | Delete
[415] Fix | Delete
# Get the wrapped DRb::DRbUnknown object.
[416] Fix | Delete
attr_reader :unknown
[417] Fix | Delete
[418] Fix | Delete
def self._load(s) # :nodoc:
[419] Fix | Delete
Marshal::load(s)
[420] Fix | Delete
end
[421] Fix | Delete
[422] Fix | Delete
def _dump(lv) # :nodoc:
[423] Fix | Delete
Marshal::dump(@unknown)
[424] Fix | Delete
end
[425] Fix | Delete
end
[426] Fix | Delete
[427] Fix | Delete
# An exception wrapping an error object
[428] Fix | Delete
class DRbRemoteError < DRbError
[429] Fix | Delete
[430] Fix | Delete
# Creates a new remote error that wraps the Exception +error+
[431] Fix | Delete
def initialize(error)
[432] Fix | Delete
@reason = error.class.to_s
[433] Fix | Delete
super("#{error.message} (#{error.class})")
[434] Fix | Delete
set_backtrace(error.backtrace)
[435] Fix | Delete
end
[436] Fix | Delete
[437] Fix | Delete
# the class of the error, as a string.
[438] Fix | Delete
attr_reader :reason
[439] Fix | Delete
end
[440] Fix | Delete
[441] Fix | Delete
# Class wrapping a marshalled object whose type is unknown locally.
[442] Fix | Delete
#
[443] Fix | Delete
# If an object is returned by a method invoked over drb, but the
[444] Fix | Delete
# class of the object is unknown in the client namespace, or
[445] Fix | Delete
# the object is a constant unknown in the client namespace, then
[446] Fix | Delete
# the still-marshalled object is returned wrapped in a DRbUnknown instance.
[447] Fix | Delete
#
[448] Fix | Delete
# If this object is passed as an argument to a method invoked over
[449] Fix | Delete
# drb, then the wrapped object is passed instead.
[450] Fix | Delete
#
[451] Fix | Delete
# The class or constant name of the object can be read from the
[452] Fix | Delete
# +name+ attribute. The marshalled object is held in the +buf+
[453] Fix | Delete
# attribute.
[454] Fix | Delete
class DRbUnknown
[455] Fix | Delete
[456] Fix | Delete
# Create a new DRbUnknown object.
[457] Fix | Delete
#
[458] Fix | Delete
# +buf+ is a string containing a marshalled object that could not
[459] Fix | Delete
# be unmarshalled. +err+ is the error message that was raised
[460] Fix | Delete
# when the unmarshalling failed. It is used to determine the
[461] Fix | Delete
# name of the unmarshalled object.
[462] Fix | Delete
def initialize(err, buf)
[463] Fix | Delete
case err.to_s
[464] Fix | Delete
when /uninitialized constant (\S+)/
[465] Fix | Delete
@name = $1
[466] Fix | Delete
when /undefined class\/module (\S+)/
[467] Fix | Delete
@name = $1
[468] Fix | Delete
else
[469] Fix | Delete
@name = nil
[470] Fix | Delete
end
[471] Fix | Delete
@buf = buf
[472] Fix | Delete
end
[473] Fix | Delete
[474] Fix | Delete
# The name of the unknown thing.
[475] Fix | Delete
#
[476] Fix | Delete
# Class name for unknown objects; variable name for unknown
[477] Fix | Delete
# constants.
[478] Fix | Delete
attr_reader :name
[479] Fix | Delete
[480] Fix | Delete
# Buffer contained the marshalled, unknown object.
[481] Fix | Delete
attr_reader :buf
[482] Fix | Delete
[483] Fix | Delete
def self._load(s) # :nodoc:
[484] Fix | Delete
begin
[485] Fix | Delete
Marshal::load(s)
[486] Fix | Delete
rescue NameError, ArgumentError
[487] Fix | Delete
DRbUnknown.new($!, s)
[488] Fix | Delete
end
[489] Fix | Delete
end
[490] Fix | Delete
[491] Fix | Delete
def _dump(lv) # :nodoc:
[492] Fix | Delete
@buf
[493] Fix | Delete
end
[494] Fix | Delete
[495] Fix | Delete
# Attempt to load the wrapped marshalled object again.
[496] Fix | Delete
#
[497] Fix | Delete
# If the class of the object is now known locally, the object
[498] Fix | Delete
# will be unmarshalled and returned. Otherwise, a new
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function