/
run_send_data
executable file
·71 lines (60 loc) · 1.4 KB
/
run_send_data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
require 'rubygems'
require File.dirname(__FILE__) + '/lib/pelvis'
require File.dirname(__FILE__) + '/examples/actors/herault'
require File.dirname(__FILE__) + '/examples/actors/echo'
def connect_herault
Pelvis.connect(:local, :identity => "herault", :advertise => false) do |agent|
agent.add_actor Herault
agent.on_advertised do
puts "herault is ready"
connect_foo
end
end
end
def connect_foo
Pelvis.connect(:local, :identity => "foo") do |agent|
agent.add_actor Echo
agent.on_advertised do
puts "foo is ready"
connect_bar
end
end
end
def connect_bar
Pelvis.connect(:local, {:identity => "bar"}) do |agent|
agent.on_advertised do
puts "bar is ready"
r = agent.request(:all, "/do/echo", {}, :identities => ["foo"])
r.on_received do |data|
puts data[:output]
end
r.on_completed do |event|
puts event
EM::stop_event_loop
end
prompt_for_data do |data|
puts "SENDING: #{data}"
r.put :input => data
end
end
end
end
def prompt_for_data(&block)
op = proc { $stdin.gets }
cb = proc {|data|
if "LQUIT" === data.chomp.upcase
EM::stop_event_loop
else
block.call(data) unless block.nil?
EM::defer(op, cb)
end
}
EM::defer(op, cb)
end
if ENV["DEBUGGER"]
Pelvis.logger.level = Logger::DEBUG
end
EM.run do
connect_herault
end