In: |
drb/gw.rb
drb/eq.rb drb/drb.rb |
Parent: | Object |
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 945 def self._load(s) uri, ref = Marshal.load(s) if DRb.here?(uri) return DRb.to_obj(ref) end it = self.new(nil) it.reinit(uri, ref) it end
# File drb/gw.rb, line 37 def self._load(s) uri, ref = Marshal.load(s) if DRb.uri == uri return ref ? DRb.to_obj(ref) : DRb.front end it = self.new(nil) it.reinit(DRb.uri, [:DRbObject, uri, ref]) it 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 973 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/eq.rb, line 5 def ==(other) return false unless DRbObject === other (@ref == other.__drbref) && (@uri == other.__drburi) end
# File drb/gw.rb, line 48 def _dump(lv) if DRb.uri == @uri if Array === @ref && @ref[0] == :DRbObject Marshal.dump([@ref[1], @ref[2]]) else Marshal.dump([@uri, @ref]) # ?? end else Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]]) end end
Marshall this object.
The URI and ref of the object are marshalled.
# File drb/drb.rb, line 964 def _dump(lv) Marshal.dump([@uri, @ref]) end
Routes method calls to the referenced object.
# File drb/drb.rb, line 1007 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 = DRbConn.open(@uri) do |conn| conn.send_message(self, msg_id, a, b) end return result if succ unless DRbUnknown === 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 raise result, result.message, bt + caller else raise result end end