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

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

[Source]

      # 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

Create a new DRbObject from a URI alone.

[Source]

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

[Source]

      # 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

[Source]

      # 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

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 1058
1058:     def __drbref
1059:       @ref
1060:     end

Get the URI of the remote object.

[Source]

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

Marshall this object.

The URI and ref of the object are marshalled.

[Source]

      # File lib/drb/drb.rb, line 1030
1030:     def _dump(lv)
1031:       Marshal.dump([@uri, @ref])
1032:     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 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

[Source]

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

[Validate]