Class: Cuboid::RPC::Client::Instance
- Inherits:
-
Object
- Object
- Cuboid::RPC::Client::Instance
show all
- Defined in:
- lib/cuboid/rpc/client/instance.rb,
lib/cuboid/rpc/client/instance/service.rb more...
Overview
RPC client for remote instances spawned by a remote agent
Defined Under Namespace
Classes: Proxy
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url, token = nil, options = nil) ⇒ Instance
Returns a new instance of Instance.
[View source]
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/cuboid/rpc/client/instance.rb', line 43
def initialize( url, token = nil, options = nil )
@token = token
@client = Base.new( url, token, options )
@instance = Proxy.new( @client )
@options = Toq::Proxy.new( @client, 'options' )
Cuboid::Application.application.instance_services.keys.each do |name|
self.class.send( :attr_reader, name.to_sym )
instance_variable_set(
"@#{name}".to_sym,
Toq::Proxy.new( @client, name )
)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Used to provide the illusion of locality for remote methods
[View source]
92
93
94
|
# File 'lib/cuboid/rpc/client/instance.rb', line 92
def method_missing( sym, *args, &block )
@instance.send( sym, *args, &block )
end
|
Instance Attribute Details
Returns the value of attribute options.
14
15
16
|
# File 'lib/cuboid/rpc/client/instance.rb', line 14
def options
@options
end
|
Not always available, set by the parent.
13
14
15
|
# File 'lib/cuboid/rpc/client/instance.rb', line 13
def pid
@pid
end
|
Class Method Details
.when_ready(url, token, &block) ⇒ Object
[View source]
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cuboid/rpc/client/instance.rb', line 20
def when_ready( url, token, &block )
options = Cuboid::Options.rpc.to_client_options.merge(
client_max_retries: 0,
connection_pool_size: 1
)
client = new( url, token, options )
Raktr.global.delay( 0.1 ) do |task|
client.alive? do |r|
if r.rpc_exception?
Raktr.global.delay( 0.1, &task )
next
end
client.close
block.call
end
end
end
|
Instance Method Details
[View source]
81
82
83
|
# File 'lib/cuboid/rpc/client/instance.rb', line 81
def address
@client.address
end
|
[View source]
69
70
71
|
# File 'lib/cuboid/rpc/client/instance.rb', line 69
def client
@client
end
|
[View source]
73
74
75
|
# File 'lib/cuboid/rpc/client/instance.rb', line 73
def close
@client.close
end
|
[View source]
85
86
87
|
# File 'lib/cuboid/rpc/client/instance.rb', line 85
def port
@client.port
end
|
[View source]
65
66
67
|
# File 'lib/cuboid/rpc/client/instance.rb', line 65
def token
@token
end
|
[View source]
77
78
79
|
# File 'lib/cuboid/rpc/client/instance.rb', line 77
def url
@client.url
end
|
#when_ready(&block) ⇒ Object
[View source]
61
62
63
|
# File 'lib/cuboid/rpc/client/instance.rb', line 61
def when_ready( &block )
self.class.when_ready( url, token, &block )
end
|