Class | DRb::DRbObject |
In: |
lib/drb/gw.rb
lib/drb/eq.rb lib/drb/drb.rb |
Parent: | Object |
# 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
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 1003 1003: def self._load(s) 1004: uri, ref = Marshal.load(s) 1005: 1006: if DRb.here?(uri) 1007: obj = DRb.to_obj(ref) 1008: if ((! obj.tainted?) && Thread.current[:drb_untaint]) 1009: Thread.current[:drb_untaint].push(obj) 1010: end 1011: return obj 1012: end 1013: 1014: self.new_with(uri, ref) 1015: 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 1041 1041: def initialize(obj, uri=nil) 1042: @uri = nil 1043: @ref = nil 1044: if obj.nil? 1045: return if uri.nil? 1046: @uri, option = DRbProtocol.uri_option(uri, DRb.config) 1047: @ref = DRbURIOption.new(option) unless option.nil? 1048: else 1049: @uri = uri ? uri : (DRb.uri rescue nil) 1050: @ref = obj ? DRb.to_id(obj) : nil 1051: end 1052: end
# File lib/drb/drb.rb, line 1017 1017: def self.new_with(uri, ref) 1018: it = self.allocate 1019: it.instance_variable_set('@uri', uri) 1020: it.instance_variable_set('@ref', ref) 1021: it 1022: end
# File lib/drb/drb.rb, line 1114 1114: def self.prepare_backtrace(uri, result) 1115: prefix = "(#{uri}) " 1116: bt = [] 1117: result.backtrace.each do |x| 1118: break if /`__send__'$/ =~ x 1119: if /^\(druby:\/\// =~ x 1120: bt.push(x) 1121: else 1122: bt.push(prefix + x) 1123: end 1124: end 1125: bt 1126: end
# File lib/drb/drb.rb, line 1103 1103: def self.with_friend(uri) 1104: friend = DRb.fetch_server(uri) 1105: return yield() unless friend 1106: 1107: save = Thread.current['DRb'] 1108: Thread.current['DRb'] = { 'server' => friend } 1109: return yield 1110: ensure 1111: Thread.current['DRb'] = save if friend 1112: 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 1060 1060: def __drbref 1061: @ref 1062: 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 1079 1079: def method_missing(msg_id, *a, &b) 1080: if DRb.here?(@uri) 1081: obj = DRb.to_obj(@ref) 1082: DRb.current_server.check_insecure_method(obj, msg_id) 1083: return obj.__send__(msg_id, *a, &b) 1084: end 1085: 1086: succ, result = self.class.with_friend(@uri) do 1087: DRbConn.open(@uri) do |conn| 1088: conn.send_message(self, msg_id, a, b) 1089: end 1090: end 1091: 1092: if succ 1093: return result 1094: elsif DRbUnknown === result 1095: raise result 1096: else 1097: bt = self.class.prepare_backtrace(@uri, result) 1098: result.set_backtrace(bt + caller) 1099: raise result 1100: end 1101: end