celluloid_pubsub 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/celluloid_pubsub/base_actor.rb +1 -1
- data/lib/celluloid_pubsub/helper.rb +1 -1
- data/lib/celluloid_pubsub/reactor.rb +30 -21
- data/lib/celluloid_pubsub/version.rb +2 -2
- data/lib/celluloid_pubsub/web_server.rb +2 -1
- data/spec/lib/celluloid_pubsub/client_pubsub_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9a9695736f77a9058642129bc301b000da27ed4
|
4
|
+
data.tar.gz: 5d626707aec391b2e7e409a402a8da9cc2dbfb98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b583c4c34ff483903aaf081d8a204e67514112210c76976b17ab4809dfade9f7a90dd763d04955da135361b497d4291a312ed1a4a8c6ba88f5f199bc3c49172f
|
7
|
+
data.tar.gz: 7424cf9bf1ebc91c08e334f3da91736ef7c2f531310823283e531d0eab7b46bf89be1f791e1df1e5ca741d3b96110d562ab37c14a9673661d8c66c51c85a6500
|
@@ -71,7 +71,7 @@ module CelluloidPubsub
|
|
71
71
|
#
|
72
72
|
# @api private
|
73
73
|
def setup_celluloid_exception_handler
|
74
|
-
Celluloid.task_class = Celluloid::TaskThread
|
74
|
+
Celluloid.task_class = defined?(Celluloid::TaskThread) ? Celluloid::TaskThread : Celluloid::Task::Threaded
|
75
75
|
Celluloid.exception_handler do |ex|
|
76
76
|
puts ex unless filtered_error?(ex)
|
77
77
|
end
|
@@ -165,18 +165,18 @@ module CelluloidPubsub
|
|
165
165
|
def delegate_action(json_data)
|
166
166
|
channel = json_data.fetch('channel', nil)
|
167
167
|
case json_data['client_action']
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
168
|
+
when 'unsubscribe_all'
|
169
|
+
unsubscribe_all
|
170
|
+
when 'unsubscribe_clients'
|
171
|
+
async.unsubscribe_clients(channel)
|
172
|
+
when 'unsubscribe'
|
173
|
+
async.unsubscribe(channel)
|
174
|
+
when 'subscribe'
|
175
|
+
async.start_subscriber(channel, json_data)
|
176
|
+
when 'publish'
|
177
|
+
async.publish_event(channel, json_data['data'].to_json)
|
178
|
+
else
|
179
|
+
handle_unknown_action(json_data)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
@@ -221,8 +221,10 @@ module CelluloidPubsub
|
|
221
221
|
log_debug "#{self.class} runs 'unsubscribe' method with #{channel}"
|
222
222
|
return unless channel.present?
|
223
223
|
forget_channel(channel)
|
224
|
-
|
225
|
-
|
224
|
+
@server.mutex.synchronize do
|
225
|
+
(@server.subscribers[channel].dup || []).delete_if do |hash|
|
226
|
+
hash[:reactor] == Actor.current
|
227
|
+
end
|
226
228
|
end
|
227
229
|
end
|
228
230
|
|
@@ -295,7 +297,9 @@ module CelluloidPubsub
|
|
295
297
|
registry_channels = CelluloidPubsub::Registry.channels
|
296
298
|
@channels << channel
|
297
299
|
registry_channels << channel unless registry_channels.include?(channel)
|
298
|
-
@server.
|
300
|
+
@server.mutex.synchronize do
|
301
|
+
@server.subscribers[channel] = channel_subscribers(channel).push(reactor: Actor.current, message: message)
|
302
|
+
end
|
299
303
|
end
|
300
304
|
|
301
305
|
# method for publishing data to a channel
|
@@ -308,8 +312,11 @@ module CelluloidPubsub
|
|
308
312
|
# @api public
|
309
313
|
def publish_event(current_topic, message)
|
310
314
|
return if current_topic.blank? || message.blank?
|
311
|
-
|
312
|
-
|
315
|
+
log_debug "#{self.class} tries to publish to #{current_topic} with #{message} into subscribers #{@server.subscribers[current_topic].inspect}"
|
316
|
+
@server.mutex.synchronize do
|
317
|
+
(@server.subscribers[current_topic].dup || []).pmap do |hash|
|
318
|
+
hash[:reactor].websocket << message
|
319
|
+
end
|
313
320
|
end
|
314
321
|
rescue => exception
|
315
322
|
log_debug("could not publish message #{message} into topic #{current_topic} because of #{exception.inspect}")
|
@@ -337,10 +344,12 @@ module CelluloidPubsub
|
|
337
344
|
# @api public
|
338
345
|
def unsubscribe_from_channel(channel)
|
339
346
|
log_debug "#{self.class} runs 'unsubscribe_from_channel' method with #{channel}"
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
347
|
+
@server.mutex.synchronize do
|
348
|
+
(@server.subscribers[channel].dup || []).pmap do |hash|
|
349
|
+
reactor = hash[:reactor]
|
350
|
+
reactor.websocket.close
|
351
|
+
Celluloid::Actor.kill(reactor)
|
352
|
+
end
|
344
353
|
end
|
345
354
|
end
|
346
355
|
end
|
@@ -25,7 +25,7 @@ module CelluloidPubsub
|
|
25
25
|
# The name of the default adapter
|
26
26
|
CLASSIC_ADAPTER = 'classic'
|
27
27
|
|
28
|
-
attr_accessor :server_options, :subscribers
|
28
|
+
attr_accessor :server_options, :subscribers, :mutex
|
29
29
|
finalizer :shutdown
|
30
30
|
# receives a list of options that are used to configure the webserver
|
31
31
|
#
|
@@ -44,6 +44,7 @@ module CelluloidPubsub
|
|
44
44
|
Celluloid.boot unless Celluloid.running?
|
45
45
|
@server_options = parse_options(options)
|
46
46
|
@subscribers = {}
|
47
|
+
@mutex = Mutex.new
|
47
48
|
setup_celluloid_logger
|
48
49
|
log_debug "CelluloidPubsub::WebServer example starting on #{hostname}:#{port}"
|
49
50
|
super(hostname, port, { spy: spy, backlog: backlog }, &method(:on_connection))
|
@@ -115,10 +115,18 @@ describe CelluloidPubsub::Client do
|
|
115
115
|
let(:data) { 'some_message' }
|
116
116
|
it 'chats with the server' do
|
117
117
|
JSON.expects(:parse).with(data).returns(data)
|
118
|
+
@worker.actor.expects(:respond_to?).returns(true)
|
118
119
|
@worker.actor.expects(:async).returns(actor)
|
119
120
|
@worker.actor.expects(:on_message).with(data)
|
120
121
|
@worker.on_message(data)
|
121
122
|
end
|
123
|
+
|
124
|
+
it 'chats with the server without async' do
|
125
|
+
JSON.expects(:parse).with(data).returns(data)
|
126
|
+
@worker.actor.expects(:respond_to?).returns(false)
|
127
|
+
@worker.actor.expects(:on_message).with(data)
|
128
|
+
@worker.on_message(data)
|
129
|
+
end
|
122
130
|
end
|
123
131
|
|
124
132
|
describe '#on_close' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid_pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|