Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
Object wrapping a reference to a remote drb object.
Method calls on this object are relayed to the remote object that this object is a stub for.
Unmarshall a marshalled DRbObject.
If the referenced object is located within the local server, then the object itself is returned. Otherwise, a new DRbObject is created to act as a stub for the remote referenced object.
# File drb/drb.rb, line 1003 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
Create a new remote object stub.
obj
is the (local) object we want to create a stub for.
Normally this is nil
. uri
is the URI of the
remote object that this will be a stub for.
# File drb/drb.rb, line 1041 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
# File drb/drb.rb, line 1017 def self.new_with(uri, ref) it = self.allocate it.instance_variable_set('@uri', uri) it.instance_variable_set('@ref', ref) it end
Create a new DRbObject from a URI alone.
# File drb/drb.rb, line 1025 def self.new_with_uri(uri) self.new(nil, uri) end
# File drb/eq.rb, line 3 def ==(other) return false unless DRbObject === other (@ref == other.__drbref) && (@uri == other.__drburi) end
Get the reference of the object, if local.
# File drb/drb.rb, line 1060 def __drbref @ref end
Get the URI of the remote object.
# File drb/drb.rb, line 1055 def __drburi @uri end
Marshall this object.
The URI and ref of the object are marshalled.
# File drb/drb.rb, line 1032 def _dump(lv) Marshal.dump([@uri, @ref]) end
Routes method calls to the referenced object.
# File drb/drb.rb, line 1079 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
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.