Class DRb::DRbObject
In: lib/drb/drb.rb
lib/drb/eq.rb
lib/drb/gw.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 1008
1008:     def self._load(s)
1009:       uri, ref = Marshal.load(s)
1010:       
1011:       if DRb.here?(uri)
1012:         obj = DRb.to_obj(ref)
1013:         if ((! obj.tainted?) && Thread.current[:drb_untaint])
1014:           Thread.current[:drb_untaint].push(obj)
1015:         end
1016:         return obj
1017:       end
1018: 
1019:       self.new_with(uri, ref)
1020:     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 1046
1046:     def initialize(obj, uri=nil)
1047:       @uri = nil
1048:       @ref = nil
1049:       if obj.nil?
1050:         return if uri.nil?
1051:         @uri, option = DRbProtocol.uri_option(uri, DRb.config)
1052:         @ref = DRbURIOption.new(option) unless option.nil?
1053:       else
1054:         @uri = uri ? uri : (DRb.uri rescue nil)
1055:         @ref = obj ? DRb.to_id(obj) : nil
1056:       end
1057:     end

[Source]

      # File lib/drb/drb.rb, line 1022
1022:     def self.new_with(uri, ref)
1023:       it = self.allocate
1024:       it.instance_variable_set('@uri', uri)
1025:       it.instance_variable_set('@ref', ref)
1026:       it
1027:     end

Create a new DRbObject from a URI alone.

[Source]

      # File lib/drb/drb.rb, line 1030
1030:     def self.new_with_uri(uri)
1031:       self.new(nil, uri)
1032:     end

[Source]

      # File lib/drb/drb.rb, line 1119
1119:     def self.prepare_backtrace(uri, result)
1120:       prefix = "(#{uri}) "
1121:       bt = []
1122:       result.backtrace.each do |x|
1123:         break if /`__send__'$/ =~ x 
1124:         if /^\(druby:\/\// =~ x
1125:           bt.push(x)
1126:         else
1127:           bt.push(prefix + x)
1128:         end
1129:       end
1130:       bt
1131:     end

[Source]

      # File lib/drb/drb.rb, line 1108
1108:     def self.with_friend(uri)
1109:       friend = DRb.fetch_server(uri)
1110:       return yield() unless friend
1111:       
1112:       save = Thread.current['DRb']
1113:       Thread.current['DRb'] = { 'server' => friend }
1114:       return yield
1115:     ensure
1116:       Thread.current['DRb'] = save if friend
1117:     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 1065
1065:     def __drbref
1066:       @ref
1067:     end

Get the URI of the remote object.

[Source]

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

Marshall this object.

The URI and ref of the object are marshalled.

[Source]

      # File lib/drb/drb.rb, line 1037
1037:     def _dump(lv)
1038:       Marshal.dump([@uri, @ref])
1039:     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
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 1084
1084:     def method_missing(msg_id, *a, &b)
1085:       if DRb.here?(@uri)
1086:         obj = DRb.to_obj(@ref)
1087:         DRb.current_server.check_insecure_method(obj, msg_id)
1088:         return obj.__send__(msg_id, *a, &b) 
1089:       end
1090: 
1091:       succ, result = self.class.with_friend(@uri) do
1092:         DRbConn.open(@uri) do |conn|
1093:           conn.send_message(self, msg_id, a, b)
1094:         end
1095:       end
1096: 
1097:       if succ
1098:         return result
1099:       elsif DRbUnknown === result
1100:         raise result
1101:       else
1102:         bt = self.class.prepare_backtrace(@uri, result)
1103:         result.set_backtrace(bt + caller)
1104:         raise result
1105:       end
1106:     end

[Source]

      # File lib/drb/drb.rb, line 1072
1072:     def respond_to?(msg_id, priv=false)
1073:       case msg_id
1074:       when :_dump
1075:         true
1076:       when :marshal_dump
1077:         false
1078:       else
1079:         method_missing(:respond_to?, msg_id, priv)
1080:       end
1081:     end

[Validate]