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

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 drb/drb.rb, line 998
 998:     def self._load(s)
 999:       uri, ref = Marshal.load(s)
1000:       
1001:       if DRb.here?(uri)
1002:         obj = DRb.to_obj(ref)
1003:         if ((! obj.tainted?) && Thread.current[:drb_untaint])
1004:           Thread.current[:drb_untaint].push(obj)
1005:         end
1006:         return obj
1007:       end
1008: 
1009:       self.new_with(uri, ref)
1010:     end

[Source]

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

[Source]

      # File drb/drb.rb, line 1036
1036:     def initialize(obj, uri=nil)
1037:       @uri = nil
1038:       @ref = nil
1039:       if obj.nil?
1040:         return if uri.nil?
1041:         @uri, option = DRbProtocol.uri_option(uri, DRb.config)
1042:         @ref = DRbURIOption.new(option) unless option.nil?
1043:       else
1044:         @uri = uri ? uri : (DRb.uri rescue nil)
1045:         @ref = obj ? DRb.to_id(obj) : nil
1046:       end
1047:     end

[Source]

      # File drb/drb.rb, line 1012
1012:     def self.new_with(uri, ref)
1013:       it = self.allocate
1014:       it.instance_variable_set('@uri', uri)
1015:       it.instance_variable_set('@ref', ref)
1016:       it
1017:     end

Create a new DRbObject from a URI alone.

[Source]

      # File drb/drb.rb, line 1020
1020:     def self.new_with_uri(uri)
1021:       self.new(nil, uri)
1022:     end

[Source]

      # File drb/drb.rb, line 1109
1109:     def self.prepare_backtrace(uri, result)
1110:       prefix = "(#{uri}) "
1111:       bt = []
1112:       result.backtrace.each do |x|
1113:         break if /`__send__'$/ =~ x 
1114:         if /^\(druby:\/\// =~ x
1115:           bt.push(x)
1116:         else
1117:           bt.push(prefix + x)
1118:         end
1119:       end
1120:       bt
1121:     end

[Source]

      # File drb/drb.rb, line 1098
1098:     def self.with_friend(uri)
1099:       friend = DRb.fetch_server(uri)
1100:       return yield() unless friend
1101:       
1102:       save = Thread.current['DRb']
1103:       Thread.current['DRb'] = { 'server' => friend }
1104:       return yield
1105:     ensure
1106:       Thread.current['DRb'] = save if friend
1107:     end

Public Instance methods

[Source]

   # File 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 drb/drb.rb, line 1055
1055:     def __drbref
1056:       @ref
1057:     end

Get the URI of the remote object.

[Source]

      # File drb/drb.rb, line 1050
1050:     def __drburi 
1051:       @uri
1052:     end

[Source]

    # File 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 drb/drb.rb, line 1027
1027:     def _dump(lv)
1028:       Marshal.dump([@uri, @ref])
1029:     end
eql?(other)

Alias for #==

[Source]

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

Routes method calls to the referenced object.

[Source]

      # File drb/drb.rb, line 1074
1074:     def method_missing(msg_id, *a, &b)
1075:       if DRb.here?(@uri)
1076:         obj = DRb.to_obj(@ref)
1077:         DRb.current_server.check_insecure_method(obj, msg_id)
1078:         return obj.__send__(msg_id, *a, &b) 
1079:       end
1080: 
1081:       succ, result = self.class.with_friend(@uri) do
1082:         DRbConn.open(@uri) do |conn|
1083:           conn.send_message(self, msg_id, a, b)
1084:         end
1085:       end
1086: 
1087:       if succ
1088:         return result
1089:       elsif DRbUnknown === result
1090:         raise result
1091:       else
1092:         bt = self.class.prepare_backtrace(@uri, result)
1093:         result.set_backtrace(bt + caller)
1094:         raise result
1095:       end
1096:     end

[Source]

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

Search

Google

Ruby API Docs

Links