zactor 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +5 -6
- data/README.md +2 -2
- data/examples/chat/client.rb +2 -4
- data/examples/chat/server.rb +16 -2
- data/images/zactor1.png +0 -0
- data/images/zactor2.png +0 -0
- data/lib/zactor.rb +9 -5
- data/lib/zactor/version.rb +1 -1
- metadata +5 -4
- data/.rake_tasks~ +0 -19
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
zactor (0.0.
|
11
|
+
zactor (0.0.7)
|
12
12
|
activesupport (> 0.1)
|
13
13
|
bson (> 0.1)
|
14
14
|
bson_ext (> 0.1)
|
@@ -23,8 +23,8 @@ GEM
|
|
23
23
|
activesupport (3.0.7)
|
24
24
|
archive-tar-minitar (0.5.2)
|
25
25
|
bluecloth (2.1.0)
|
26
|
-
bson (1.
|
27
|
-
bson_ext (1.
|
26
|
+
bson (1.3.0)
|
27
|
+
bson_ext (1.3.0)
|
28
28
|
columnize (0.3.2)
|
29
29
|
configuration (1.2.0)
|
30
30
|
diff-lcs (1.1.2)
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
eventmachine (1.0.0.beta.3)
|
35
35
|
ffi (1.0.7)
|
36
36
|
rake (>= 0.8.7)
|
37
|
-
ffi-rzmq (0.
|
37
|
+
ffi-rzmq (0.8.0)
|
38
38
|
growl (1.0.3)
|
39
39
|
guard (0.3.0)
|
40
40
|
open_gem (~> 1.4.2)
|
@@ -68,10 +68,9 @@ GEM
|
|
68
68
|
columnize (>= 0.3.1)
|
69
69
|
linecache19 (>= 0.5.11)
|
70
70
|
ruby-debug-base19 (>= 0.11.19)
|
71
|
-
ruby-interface (0.0.
|
71
|
+
ruby-interface (0.0.6)
|
72
72
|
activesupport (> 0.1)
|
73
73
|
i18n (> 0.1)
|
74
|
-
ruby-interface
|
75
74
|
ruby_core_source (0.1.4)
|
76
75
|
archive-tar-minitar (>= 0.5.2)
|
77
76
|
thor (0.14.6)
|
data/README.md
CHANGED
@@ -110,7 +110,7 @@ ZMQ
|
|
110
110
|
|
111
111
|
При Zactor.start стартует брокер, по одному на каждый процесс, через него проходят все сообщения данного процесса, принимает сообщения через SUB-сокет, отправляет через PUB. SUB подписан на все сообщения. Каждый zactor-объект создает по паре сокетов, PUB подключается к SUB-брокера, а SUB к PUB-брокера. SUB подписывается на сообщения содержащие его identity.
|
112
112
|
|
113
|
-
![ZMQ](images/
|
113
|
+
![ZMQ](https://github.com/Undev/zactor/raw/master/images/zactor1.png)
|
114
114
|
|
115
115
|
Рассмотрим жизнь сообщения на примере с ping-ping. В случае с b в том же процессе:
|
116
116
|
|
@@ -143,7 +143,7 @@ App1 Broker[PUB]->A[SUB]: Отправитель получает ответ
|
|
143
143
|
|
144
144
|
У нас получится примерно следующая схема:
|
145
145
|
|
146
|
-
![ZMQ](images/
|
146
|
+
![ZMQ](https://github.com/Undev/zactor/raw/master/images/zactor2.png)
|
147
147
|
|
148
148
|
Теперь наш ping можно отправлять в балансер, а отвечать будет один из подключенных воркеров.
|
149
149
|
|
data/examples/chat/client.rb
CHANGED
@@ -29,11 +29,9 @@ class Client
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def connect
|
32
|
-
puts "Подключаемся"
|
33
32
|
zactor.send_request(@server, :new_client, @login) do
|
34
|
-
|
35
|
-
|
36
|
-
end.timeout(5) { puts "Проблемы с подключением..." }
|
33
|
+
zactor.link(@server) { EM.add_timer(1) { connect } }
|
34
|
+
end
|
37
35
|
end
|
38
36
|
|
39
37
|
def send_message(text)
|
data/examples/chat/server.rb
CHANGED
@@ -15,6 +15,7 @@ class Server
|
|
15
15
|
identity "server"
|
16
16
|
|
17
17
|
event(:new_client) do |o, msg, login|
|
18
|
+
puts "NEW CLIENT!"
|
18
19
|
o.new_client msg.sender, login
|
19
20
|
msg.reply :ok
|
20
21
|
end
|
@@ -34,10 +35,13 @@ class Server
|
|
34
35
|
|
35
36
|
attr_accessor :clients
|
36
37
|
def initialize
|
37
|
-
zactor.init
|
38
38
|
@clients = {}
|
39
39
|
end
|
40
40
|
|
41
|
+
def start
|
42
|
+
zactor.init
|
43
|
+
end
|
44
|
+
|
41
45
|
def new_client(client, login)
|
42
46
|
@clients[client] = login
|
43
47
|
send_message client, "присоединился"
|
@@ -47,13 +51,23 @@ class Server
|
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
54
|
+
def stop
|
55
|
+
zactor.finish
|
56
|
+
EM.stop
|
57
|
+
end
|
58
|
+
|
50
59
|
def send_message(from, message)
|
51
60
|
(clients.keys - [from]).each { |c| zactor.send_request c, :message, "#{clients[from]}: #{message}"}
|
52
61
|
end
|
53
62
|
end
|
54
63
|
|
64
|
+
server = Server.new
|
65
|
+
|
66
|
+
Signal.trap('INT') { server.stop }
|
67
|
+
Signal.trap('TERM') { server.stop }
|
68
|
+
|
55
69
|
EM.run do
|
56
70
|
Zactor.start ARGV[0]#, :debug => true
|
57
|
-
|
71
|
+
server.start
|
58
72
|
puts "Server started"
|
59
73
|
end
|
data/images/zactor1.png
ADDED
Binary file
|
data/images/zactor2.png
ADDED
Binary file
|
data/lib/zactor.rb
CHANGED
@@ -181,7 +181,8 @@ module Zactor
|
|
181
181
|
|
182
182
|
def timeout(secs, &clb)
|
183
183
|
raise "Only for requests" unless @last_callback
|
184
|
-
|
184
|
+
last_clb = @last_callback
|
185
|
+
@timeouts[last_clb] = EM.add_timer(secs) { @timeouts.delete(last_clb); clb.call }
|
185
186
|
end
|
186
187
|
|
187
188
|
def send_reply(actor, callback_id, *args)
|
@@ -203,19 +204,22 @@ module Zactor
|
|
203
204
|
end
|
204
205
|
|
205
206
|
def link(actor, &clb)
|
207
|
+
return if @finished || Zactor.stub
|
206
208
|
Zactor.logger.debug { "Zactor: link #{actor} with #{self.actor}"}
|
209
|
+
link_timer = {}
|
207
210
|
send_request actor, :link do
|
208
211
|
clb.call
|
212
|
+
EM.cancel_timer link_timer[:timer]
|
209
213
|
end
|
210
|
-
link_ping actor, &clb
|
214
|
+
link_ping link_timer, actor, &clb
|
211
215
|
self
|
212
216
|
end
|
213
217
|
|
214
|
-
def link_ping(actor, &clb)
|
215
|
-
|
218
|
+
def link_ping(link_timer, actor, &clb)
|
219
|
+
link_timer[:timer] = EM.add_timer(5) do
|
216
220
|
unless @finished
|
217
221
|
send_request(actor, :link_ping) do
|
218
|
-
link_ping actor, &clb
|
222
|
+
link_ping link_timer, actor, &clb
|
219
223
|
end.timeout(5) do
|
220
224
|
clb.call
|
221
225
|
end
|
data/lib/zactor/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrew Rudenko
|
@@ -125,7 +125,6 @@ extra_rdoc_files: []
|
|
125
125
|
files:
|
126
126
|
- .document
|
127
127
|
- .gitignore
|
128
|
-
- .rake_tasks~
|
129
128
|
- .rspec
|
130
129
|
- .yardopts
|
131
130
|
- Gemfile
|
@@ -138,6 +137,8 @@ files:
|
|
138
137
|
- examples/chat/client.rb
|
139
138
|
- examples/chat/server.rb
|
140
139
|
- examples/ping/inproc.rb
|
140
|
+
- images/zactor1.png
|
141
|
+
- images/zactor2.png
|
141
142
|
- lib/zactor.rb
|
142
143
|
- lib/zactor/actor_pub.rb
|
143
144
|
- lib/zactor/actor_sub.rb
|
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
166
|
requirements:
|
166
167
|
- - ">="
|
167
168
|
- !ruby/object:Gem::Version
|
168
|
-
hash:
|
169
|
+
hash: 1512131416648626830
|
169
170
|
segments:
|
170
171
|
- 0
|
171
172
|
version: "0"
|
data/.rake_tasks~
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
build
|
2
|
-
console[script]
|
3
|
-
gemcutter:release
|
4
|
-
gemspec
|
5
|
-
gemspec:debug
|
6
|
-
gemspec:generate
|
7
|
-
gemspec:release
|
8
|
-
gemspec:validate
|
9
|
-
git:release
|
10
|
-
install
|
11
|
-
rcov
|
12
|
-
release
|
13
|
-
spec
|
14
|
-
version
|
15
|
-
version:bump:major
|
16
|
-
version:bump:minor
|
17
|
-
version:bump:patch
|
18
|
-
version:write
|
19
|
-
yard
|