Class DRb::DRbObject
In: lib/drb/gw.rb
lib/drb/eq.rb
lib/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.

Methods

Public Class methods

[Source]

    # 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.

[Source]

      # 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.

[Source]

      # 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

[Source]

      # 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

Create a new DRbObject from a URI alone.

[Source]

      # File lib/drb/drb.rb, line 1025
1025:     def self.new_with_uri(uri)
1026:       self.new(nil, uri)
1027:     end

[Source]

      # 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

[Source]

      # 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

Public Instance methods

[Source]

   # 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.

[Source]

      # File lib/drb/drb.rb, line 1060
1060:     def __drbref
1061:       @ref
1062:     end

Get the URI of the remote object.

[Source]

      # File lib/drb/drb.rb, line 1055
1055:     def __drburi 
1056:       @uri
1057:     end

[Source]

    # 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

Marshall this object.

The URI and ref of the object are marshalled.

[Source]

      # File lib/drb/drb.rb, line 1032
1032:     def _dump(lv)
1033:       Marshal.dump([@uri, @ref])
1034:     end
eql?(other)

Alias for #==

[Source]

    # File lib/drb/eq.rb, line 10
10:     def hash
11:       [@uri, @ref].hash
12:     end

Routes method calls to the referenced object.

[Source]

      # 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

[Source]

      # File lib/drb/drb.rb, line 1067
1067:     def respond_to?(msg_id, priv=false)
1068:       case msg_id
1069:       when :_dump
1070:         true
1071:       when :marshal_dump
1072:         false
1073:       else
1074:         method_missing(:respond_to?, msg_id, priv)
1075:       end
1076:     end

[Validate]