-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalice_tuplespace.rb
executable file
·52 lines (42 loc) · 1.04 KB
/
alice_tuplespace.rb
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
#!/usr/bin/env ruby
require 'json'
require 'socket'
require 'rinda/tuplespace'
require './config_alice'
require './multicast'
require './multiplenotify'
def start_tuplespace(name, uri)
ts = Rinda::TupleSpace.new
DRb.start_service(uri, ts)
puts "Tuplespace #{name} started at #{DRb.uri}"
ts
end
def map_symbols_out(tuple)
tuple.map do |item|
(item.is_a? Symbol)? { :symbol => item } : item
end
end
config = read_config
ts_name = config['name']
ts_uri = config['uri']
notify_addrs = config['notify']
ts = start_tuplespace ts_name, ts_uri
begin
sock = open_multicast_socket
notify_addrs.each do |dest|
puts "Sending notifications to udp://#{dest['address']}:#{dest['port']}"
end
notify_all notify_addrs, sock, "#{ts_name} start #{ts_uri}"
mn = MultipleNotify.new ts, nil, config['filters']
loop do
event, tuple = mn.pop
json = JSON.generate(map_symbols_out(tuple))
notify_all notify_addrs, sock, "#{ts_name} #{event} #{json}"
end
DRb.thread.join
rescue Interrupt
puts
ensure
sock.close
DRb.stop_service
end