Class: DRb::DRbObject
- Inherits:
-
Object
- Object
- DRb::DRbObject
- Defined in:
- lib/drb/eq.rb,
lib/drb/gw.rb,
lib/drb/drb.rb
Overview
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.
Class Method Summary collapse
-
._load(s) ⇒ Object
Unmarshall a marshalled DRbObject.
-
.new_with(uri, ref) ⇒ Object
Creates a DRb::DRbObject given the reference information to the remote host
uri
and objectref
. -
.new_with_uri(uri) ⇒ Object
Create a new DRbObject from a URI alone.
-
.prepare_backtrace(uri, result) ⇒ Object
Returns a modified backtrace from
result
with theuri
where each call in the backtrace came from. -
.with_friend(uri) ⇒ Object
Given the
uri
of another host executes the block provided.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#__drbref ⇒ Object
Get the reference of the object, if local.
-
#__drburi ⇒ Object
Get the URI of the remote object.
-
#_dump(lv) ⇒ Object
Marshall this object.
- #hash ⇒ Object
-
#initialize(obj, uri = nil) ⇒ DRbObject
constructor
Create a new remote object stub.
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#pretty_print_cycle(q) ⇒ Object
:nodoc:.
-
#respond_to?(msg_id, priv = false) ⇒ Boolean
Routes respond_to? to the referenced remote object.
Constructor Details
#initialize(obj, uri = nil) ⇒ DRbObject
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.
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
# File 'lib/drb/drb.rb', line 1117 def initialize(obj, uri=nil) @uri = nil @ref = nil case obj when Object is_nil = obj.nil? when BasicObject is_nil = false end if is_nil return if uri.nil? @uri, option = DRbProtocol.uri_option(uri, DRb.config) @ref = DRbURIOption.new(option) unless option.nil? else @uri = uri ? uri : (DRb.uri rescue nil) @ref = obj ? DRb.to_id(obj) : nil end end |
Class Method Details
._load(s) ⇒ Object
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.
1079 1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/drb/drb.rb', line 1079 def self._load(s) uri, ref = Marshal.load(s) if DRb.uri == uri return ref ? DRb.to_obj(ref) : DRb.front end self.new_with(DRb.uri, [:DRbObject, uri, ref]) end |
.new_with(uri, ref) ⇒ Object
Creates a DRb::DRbObject given the reference information to the remote host uri
and object ref
.
1093 1094 1095 1096 1097 1098 |
# File 'lib/drb/drb.rb', line 1093 def self.new_with(uri, ref) it = self.allocate it.instance_variable_set(:@uri, uri) it.instance_variable_set(:@ref, ref) it end |
.new_with_uri(uri) ⇒ Object
Create a new DRbObject from a URI alone.
1101 1102 1103 |
# File 'lib/drb/drb.rb', line 1101 def self.new_with_uri(uri) self.new(nil, uri) end |
.prepare_backtrace(uri, result) ⇒ Object
Returns a modified backtrace from result
with the uri
where each call in the backtrace came from.
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 |
# File 'lib/drb/drb.rb', line 1201 def self.prepare_backtrace(uri, result) # :nodoc: prefix = "(#{uri}) " bt = [] result.backtrace.each do |x| break if /[`']__send__'$/ =~ x if /\A\(druby:\/\// =~ x bt.push(x) else bt.push(prefix + x) end end bt end |
.with_friend(uri) ⇒ Object
Given the uri
of another host executes the block provided.
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File 'lib/drb/drb.rb', line 1188 def self.with_friend(uri) # :nodoc: friend = DRb.fetch_server(uri) return yield() unless friend save = Thread.current['DRb'] Thread.current['DRb'] = { 'server' => friend } return yield ensure Thread.current['DRb'] = save if friend end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
4 5 6 7 |
# File 'lib/drb/eq.rb', line 4 def ==(other) return false unless DRbObject === other (@ref == other.__drbref) && (@uri == other.__drburi) end |
#__drbref ⇒ Object
Get the reference of the object, if local.
1143 1144 1145 |
# File 'lib/drb/drb.rb', line 1143 def __drbref @ref end |
#__drburi ⇒ Object
Get the URI of the remote object.
1138 1139 1140 |
# File 'lib/drb/drb.rb', line 1138 def __drburi @uri end |
#_dump(lv) ⇒ Object
Marshall this object.
The URI and ref of the object are marshalled.
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 |
# File 'lib/drb/drb.rb', line 1108 def _dump(lv) if DRb.uri == @uri if Array === @ref && @ref[0] == :DRbObject Marshal.dump([@ref[1], @ref[2]]) else Marshal.dump([@uri, @ref]) # ?? end else Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]]) end end |
#hash ⇒ Object
9 10 11 |
# File 'lib/drb/eq.rb', line 9 def hash [@uri, @ref].hash end |
#pretty_print(q) ⇒ Object
:nodoc:
1215 1216 1217 |
# File 'lib/drb/drb.rb', line 1215 def pretty_print(q) # :nodoc: q.pp_object(self) end |
#pretty_print_cycle(q) ⇒ Object
:nodoc:
1219 1220 1221 1222 1223 1224 |
# File 'lib/drb/drb.rb', line 1219 def pretty_print_cycle(q) # :nodoc: q.object_address_group(self) { q.breakable q.text '...' } end |
#respond_to?(msg_id, priv = false) ⇒ Boolean
Routes respond_to? to the referenced remote object.
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
# File 'lib/drb/drb.rb', line 1151 def respond_to?(msg_id, priv=false) case msg_id when :_dump true when :marshal_dump false else method_missing(:respond_to?, msg_id, priv) end end |