| Class | DRb::DRbObject |
| In: |
lib/drb/eq.rb
lib/drb/gw.rb lib/drb/drb.rb |
| Parent: | Object |
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 lib/drb/drb.rb, line 1001
1001: def self._load(s)
1002: uri, ref = Marshal.load(s)
1003:
1004: if DRb.here?(uri)
1005: obj = DRb.to_obj(ref)
1006: if ((! obj.tainted?) && Thread.current[:drb_untaint])
1007: Thread.current[:drb_untaint].push(obj)
1008: end
1009: return obj
1010: end
1011:
1012: self.new_with(uri, ref)
1013: end
# File lib/drb/gw.rb, line 35
35: def self._load(s)
36: uri, ref = Marshal.load(s)
37: if DRb.uri == uri
38: return ref ? DRb.to_obj(ref) : DRb.front
39: end
40:
41: self.new_with(DRb.uri, [:DRbObject, uri, ref])
42: 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 lib/drb/drb.rb, line 1039
1039: def initialize(obj, uri=nil)
1040: @uri = nil
1041: @ref = nil
1042: if obj.nil?
1043: return if uri.nil?
1044: @uri, option = DRbProtocol.uri_option(uri, DRb.config)
1045: @ref = DRbURIOption.new(option) unless option.nil?
1046: else
1047: @uri = uri ? uri : (DRb.uri rescue nil)
1048: @ref = obj ? DRb.to_id(obj) : nil
1049: end
1050: end
# File lib/drb/drb.rb, line 1015
1015: def self.new_with(uri, ref)
1016: it = self.allocate
1017: it.instance_variable_set('@uri', uri)
1018: it.instance_variable_set('@ref', ref)
1019: it
1020: end
# File lib/drb/drb.rb, line 1112
1112: def self.prepare_backtrace(uri, result)
1113: prefix = "(#{uri}) "
1114: bt = []
1115: result.backtrace.each do |x|
1116: break if /`__send__'$/ =~ x
1117: if /^\(druby:\/\// =~ x
1118: bt.push(x)
1119: else
1120: bt.push(prefix + x)
1121: end
1122: end
1123: bt
1124: end
# File lib/drb/drb.rb, line 1101
1101: def self.with_friend(uri)
1102: friend = DRb.fetch_server(uri)
1103: return yield() unless friend
1104:
1105: save = Thread.current['DRb']
1106: Thread.current['DRb'] = { 'server' => friend }
1107: return yield
1108: ensure
1109: Thread.current['DRb'] = save if friend
1110: end
# File lib/drb/eq.rb, line 5 5: def ==(other) 6: return false unless DRbObject === other 7: (@ref == other.__drbref) && (@uri == other.__drburi) 8: end
Get the reference of the object, if local.
# File lib/drb/drb.rb, line 1058
1058: def __drbref
1059: @ref
1060: end
# File lib/drb/gw.rb, line 44
44: def _dump(lv)
45: if DRb.uri == @uri
46: if Array === @ref && @ref[0] == :DRbObject
47: Marshal.dump([@ref[1], @ref[2]])
48: else
49: Marshal.dump([@uri, @ref]) # ??
50: end
51: else
52: Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]])
53: end
54: end
Routes method calls to the referenced object.
# File lib/drb/drb.rb, line 1077
1077: def method_missing(msg_id, *a, &b)
1078: if DRb.here?(@uri)
1079: obj = DRb.to_obj(@ref)
1080: DRb.current_server.check_insecure_method(obj, msg_id)
1081: return obj.__send__(msg_id, *a, &b)
1082: end
1083:
1084: succ, result = self.class.with_friend(@uri) do
1085: DRbConn.open(@uri) do |conn|
1086: conn.send_message(self, msg_id, a, b)
1087: end
1088: end
1089:
1090: if succ
1091: return result
1092: elsif DRbUnknown === result
1093: raise result
1094: else
1095: bt = self.class.prepare_backtrace(@uri, result)
1096: result.set_backtrace(bt + caller)
1097: raise result
1098: end
1099: end