Class: DRb::DRbObject
- Inherits:
-
Object
show all
- Defined in:
- lib/drb/drb_object.rb
Defined Under Namespace
Classes: DRbPromise
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(obj, uri = nil) ⇒ DRbObject
Returns a new instance of DRbObject.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg_id, *a, &b) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/drb/drb_object.rb', line 118
def method_missing(msg_id, *a, &b)
DRbPromise.new do |resolve|
DRbConn.open(@uri) do |conn|
conn.send_message(self, msg_id, a, b) do |succ, result|
if succ
resolve.apply result
elsif DRbUnknown === result
resolve.apply result
else
bt = self.class.prepare_backtrace(@uri, result)
result.set_backtrace(bt + caller)
resolve.apply result
conn.close
end
end
end
end
end
|
Class Method Details
._load(s) ⇒ Object
3
4
5
6
7
8
|
# File 'lib/drb/drb_object.rb', line 3
def self._load(s)
uri, ref = Marshal.load(s)
self.new_with(uri, ref)
rescue Exception => e
puts e.message
end
|
.id2ref ⇒ Object
47
48
49
|
# File 'lib/drb/drb_object.rb', line 47
def self.id2ref
@id2ref ||= {}
end
|
.new_with(uri, ref) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/drb/drb_object.rb', line 10
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
17
18
19
|
# File 'lib/drb/drb_object.rb', line 17
def self.new_with_uri(uri)
self.new(nil, uri)
end
|
.prepare_backtrace(uri, result) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/drb/drb_object.rb', line 137
def self.prepare_backtrace(uri, result)
prefix = "(#{uri}) "
bt = []
result.backtrace.each do |x|
break if /`__send__'$/ =~ x
if /^\(druby:\/\// =~ x
bt.push(x)
else
bt.push(prefix + x)
end
end
bt
end
|
Instance Method Details
#__drbref ⇒ Object
43
44
45
|
# File 'lib/drb/drb_object.rb', line 43
def __drbref
@ref
end
|
#__drburi ⇒ Object
39
40
41
|
# File 'lib/drb/drb_object.rb', line 39
def __drburi
@uri
end
|
#_dump(lv) ⇒ Object
21
22
23
|
# File 'lib/drb/drb_object.rb', line 21
def _dump(lv)
Marshal.dump([@uri, @ref])
end
|
#inspect ⇒ Object
51
52
53
|
# File 'lib/drb/drb_object.rb', line 51
def inspect
@ref && @ref.inspect
end
|
#pretty_print(q) ⇒ Object
151
152
153
|
# File 'lib/drb/drb_object.rb', line 151
def pretty_print(q)
q.pp_object(self)
end
|
#pretty_print_cycle(q) ⇒ Object
155
156
157
158
159
160
|
# File 'lib/drb/drb_object.rb', line 155
def pretty_print_cycle(q)
q.object_address_group(self) {
q.breakable
q.text '...'
}
end
|
#respond_to?(msg_id, priv = false) ⇒ Boolean
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/drb/drb_object.rb', line 55
def respond_to?(msg_id, priv=false)
case msg_id
when :_dump
true
when :marshal_dump
false
else
false
end
end
|