Class: DRbFire::Protocol
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- DRbFire::Protocol
show all
- Defined in:
- lib/deep_test/drbfire.rb
Overview
Defined Under Namespace
Classes: ClientServer, ClientServerProxy
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(uri, delegate) ⇒ Protocol
Returns a new instance of Protocol.
245
246
247
248
249
250
|
# File 'lib/deep_test/drbfire.rb', line 245
def initialize(uri, delegate)
super(delegate)
@uri = uri
@id = 0
@id_mutex = Mutex.new
end
|
Instance Attribute Details
#signal_id ⇒ Object
Returns the value of attribute signal_id.
243
244
245
|
# File 'lib/deep_test/drbfire.rb', line 243
def signal_id
@signal_id
end
|
#uri ⇒ Object
Returns the value of attribute uri.
243
244
245
|
# File 'lib/deep_test/drbfire.rb', line 243
def uri
@uri
end
|
Class Method Details
.add_client_connection(id, connection) ⇒ Object
190
191
192
193
194
195
|
# File 'lib/deep_test/drbfire.rb', line 190
def add_client_connection(id, connection)
if((c = @client_servers[id]))
c.push(connection)
else
end
end
|
.add_client_server(id, server) ⇒ Object
197
198
199
|
# File 'lib/deep_test/drbfire.rb', line 197
def add_client_server(id, server)
@client_servers[id] = server
end
|
.open(uri, config, type = INCOMING_CONN) ⇒ Object
180
181
182
183
184
185
186
187
188
|
# File 'lib/deep_test/drbfire.rb', line 180
def open(uri, config, type=INCOMING_CONN)
unless(server?(config))
connection = new(uri, delegate(config).open(uri, config))
connection.stream.write(type)
connection
else
@client_servers[parse_uri(uri).last.to_i].open
end
end
|
.open_server(uri, config) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/deep_test/drbfire.rb', line 162
def open_server(uri, config)
if(server?(config))
@client_servers ||= {}
puts "OPEN SERVER1 #{uri}"
sock = delegate(config).open_server(uri, config)
scheme = sock.uri.match(/^(.*):\/\//)[1]
drbfire_uri = sock.uri.sub(scheme, SCHEME)
puts "OPEN SERVER2 #{drbfire_uri}\n#{caller.join("\n")}"
new(drbfire_uri, sock)
else
ClientServer.new(uri, config)
end
end
|
.parse_uri(uri) ⇒ Object
201
202
203
204
205
206
207
208
|
# File 'lib/deep_test/drbfire.rb', line 201
def parse_uri(uri)
if(%r{^#{SCHEME}://([^:]+):(\d+)(?:\?(.+))?$} =~ uri)
[$1, $2.to_i, $3]
else
raise DRb::DRbBadScheme, uri unless(/^#{SCHEME}/ =~ uri)
raise DRb::DRbBadURI, "Can't parse uri: #{uri}"
end
end
|
.uri_option(uri, config) ⇒ Object
210
211
212
213
|
# File 'lib/deep_test/drbfire.rb', line 210
def uri_option(uri, config)
host, port, option = parse_uri(uri)
return "#{SCHEME}://#{host}:#{port}", option
end
|
Instance Method Details
#accept ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/deep_test/drbfire.rb', line 252
def accept
while(__getobj__.instance_eval{@socket})
begin
connection = self.class.new(nil, __getobj__.accept)
rescue IOError
return nil
end
begin
type = connection.stream.read(1)
rescue
next
end
case type
when INCOMING_CONN
return connection
when OUTGOING_CONN
self.class.add_client_connection(connection.read_signal_id, connection)
next
when SIGNAL_CONN
new_id = nil
@id_mutex.synchronize do
new_id = (@id += 1)
end
client_server = ClientServerProxy.new(connection, new_id)
self.class.add_client_server(new_id, client_server)
client_server.write_signal_id
next
else
raise "Invalid type #{type}"
end
end
end
|
#read_signal_id ⇒ Object
285
286
287
|
# File 'lib/deep_test/drbfire.rb', line 285
def read_signal_id
stream.read(4).unpack(ID_FORMAT).first
end
|