Class: Dcmgr::MessagingClient
- Inherits:
-
Isono::Node
- Object
- Isono::Node
- Dcmgr::MessagingClient
show all
- Includes:
- Logger, Isono
- Defined in:
- lib/dcmgr/messaging_client.rb
Overview
mc = MessagingClient.start puts mc.request(‘endpoint’, ‘func1’, xxxx, xxxx) puts mc.request(‘endpoint’, ‘func2’, xxx, xxx)
mc = MessagingClient.start endpoint = mc.sync_rpc(‘endpoint’) endpoint.func1(xxxx, xxxx) endpoint.func2(xxx, xxx)
Defined Under Namespace
Classes: RpcSyncDelegator
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logger
create, default_logdev, included
Constructor Details
Returns a new instance of MessagingClient.
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/dcmgr/messaging_client.rb', line 56
def initialize(m=nil, &blk)
m ||= Manifest.new(Dir.pwd) {
node_name 'dcmgr'
node_instance_id Util.gen_id
load_module NodeModules::EventChannel
load_module NodeModules::RpcChannel
load_module NodeModules::JobChannel
}
m.instance_eval(&blk) if blk
super(m)
end
|
Class Method Details
.start(amqp_uri, manifest = nil, &blk) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/dcmgr/messaging_client.rb', line 22
def self.start(amqp_uri, manifest=nil, &blk)
node = self.new(manifest, &blk)
if EventMachine.reactor_thread?
EventMachine.schedule {
node.connect(amqp_uri)
}
else
q = ::Queue.new
EventMachine.schedule {
node.connect(amqp_uri) { |type|
q << type
}
}
case q.deq
when :success
when :error
raise "Connection failed: #{amqp_uri}"
end
end
node
end
|
Instance Method Details
#event_publish(evname, opts = {}) ⇒ Object
112
113
114
|
# File 'lib/dcmgr/messaging_client.rb', line 112
def event_publish(evname, opts={})
NodeModules::EventChannel.new(self).publish(evname, opts)
end
|
#request(endpoint, key, *args, &blk) ⇒ Object
103
104
105
106
|
# File 'lib/dcmgr/messaging_client.rb', line 103
def request(endpoint, key, *args, &blk)
rpc = NodeModules::RpcChannel.new(self)
rpc.request(endpoint, key, *args, &blk)
end
|
#stop ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/dcmgr/messaging_client.rb', line 46
def stop
if connected?
close {
EventMachine.schedule {
EventMachine.stop
}
}
end
end
|
#submit(job_endpoint, key, *args) ⇒ Object
108
109
110
|
# File 'lib/dcmgr/messaging_client.rb', line 108
def submit(job_endpoint, key, *args)
NodeModules::JobChannel.new(self).submit(job_endpoint, key, *args)
end
|
#sync_rpc(endpoint, opts = {}) ⇒ Object
98
99
100
101
|
# File 'lib/dcmgr/messaging_client.rb', line 98
def sync_rpc(endpoint, opts={})
rpc = NodeModules::RpcChannel.new(self)
RpcSyncDelegator.new(rpc, endpoint, opts)
end
|