metacosm 0.2.12 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/metacosm/remote_simulation.rb +48 -0
- data/lib/metacosm/simulation.rb +0 -5
- data/lib/metacosm/version.rb +1 -1
- metadata +3 -3
- data/lib/metacosm/redis_simulation.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f78fea361e727ab756d606811ca59e1f52a5b1e5
|
4
|
+
data.tar.gz: b6539a027a2cf2bac9270b3c60b8a3246b35c228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c34e16473d596582f095fa4785cb01e0de4f7a3436eae237b582ed504a1c9555950892afe4a643fbc85716cbb473d40b5d149778d0acbc4e2d7cc1f22f1a6ee4
|
7
|
+
data.tar.gz: 15c5c5734f37cd1a1c088822027127dedc861381a25d3934fc6d622905fdec38666c12c299eb3acdbf9e3cc23f7be77430ab6867502bf4cc1bf4c2e2269ec107
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Metacosm
|
2
|
+
class RemoteSimulation < Simulation
|
3
|
+
def initialize
|
4
|
+
setup_connection
|
5
|
+
end
|
6
|
+
|
7
|
+
def redis_connection
|
8
|
+
Redis.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def fire(command)
|
12
|
+
command_dto = command.attrs.merge(handler_module: command.handler_module_name, handler_class_name: command.handler_class_name)
|
13
|
+
redis = redis_connection
|
14
|
+
redis.publish(:socius_command_queue, Marshal.dump(command_dto))
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_connection
|
18
|
+
@remote_listener_thread = Thread.new do
|
19
|
+
begin
|
20
|
+
redis = redis_connection
|
21
|
+
redis.subscribe(:socius_event_stream) do |on|
|
22
|
+
on.subscribe do |channel, subscriptions|
|
23
|
+
puts "Subscribed to remote simulation event stream ##{channel} (#{subscriptions} subscriptions)"
|
24
|
+
end
|
25
|
+
|
26
|
+
on.message do |channel, message|
|
27
|
+
event = Marshal.load(message)
|
28
|
+
listener_module_name = event.delete(:listener_module)
|
29
|
+
listener_class_name = event.delete(:listener_class_name)
|
30
|
+
module_name = listener_module_name
|
31
|
+
module_name = "Object" if module_name.empty?
|
32
|
+
listener = (module_name.constantize).const_get(listener_class_name).new(self)
|
33
|
+
listener.receive(event)
|
34
|
+
end
|
35
|
+
|
36
|
+
on.unsubscribe do |channel, subscriptions|
|
37
|
+
puts "Unsubscribed from remote simulation event stream ##{channel} (#{subscriptions} subscriptions)"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
rescue Redis::BaseConnectionError => error
|
41
|
+
puts "#{error}, retrying in 1s"
|
42
|
+
sleep 1
|
43
|
+
retry
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/metacosm/simulation.rb
CHANGED
@@ -82,11 +82,6 @@ module Metacosm
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
# TODO lift this stuff from socius
|
86
|
-
# def push_commands_to(channel:)
|
87
|
-
# @command_push_channel = channel
|
88
|
-
# end
|
89
|
-
|
90
85
|
def subscribe_for_commands(channel:)
|
91
86
|
p [ :subscribe_to_command_channel, channel: channel ]
|
92
87
|
redis = Redis.new
|
data/lib/metacosm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metacosm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Weissman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: passive_record
|
@@ -163,7 +163,7 @@ files:
|
|
163
163
|
- gemspec.yml
|
164
164
|
- lib/metacosm.rb
|
165
165
|
- lib/metacosm/model.rb
|
166
|
-
- lib/metacosm/
|
166
|
+
- lib/metacosm/remote_simulation.rb
|
167
167
|
- lib/metacosm/simulation.rb
|
168
168
|
- lib/metacosm/support/spec_harness.rb
|
169
169
|
- lib/metacosm/support/test_harness.rb
|