celluloid_pubsub 0.7.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a3359e6bed373e2823baba89ebc16b1c23a7854
4
- data.tar.gz: 8863612bacc3f790b801fb5ee83a2cc64448de1b
3
+ metadata.gz: f9a9695736f77a9058642129bc301b000da27ed4
4
+ data.tar.gz: 5d626707aec391b2e7e409a402a8da9cc2dbfb98
5
5
  SHA512:
6
- metadata.gz: 2d3d910f4eb374c47bfe50073c59f4e10e2b3cf01de8a33a7e7870dae3b55d72a91ae0522a7f0ee0e427f47a7aaae5cf79937f67561e629f8a3eae5d06c690ca
7
- data.tar.gz: d43bbebe970d977110d1096edc17f30167f95fdbe43c0ffc5d5193f819c970d521545da864a084d725c6c51c40409e44ebfe685d79faa17ebab14ac7cfdbc56b
6
+ metadata.gz: b583c4c34ff483903aaf081d8a204e67514112210c76976b17ab4809dfade9f7a90dd763d04955da135361b497d4291a312ed1a4a8c6ba88f5f199bc3c49172f
7
+ data.tar.gz: 7424cf9bf1ebc91c08e334f3da91736ef7c2f531310823283e531d0eab7b46bf89be1f791e1df1e5ca741d3b96110d562ab37c14a9673661d8c66c51c85a6500
@@ -33,7 +33,7 @@ module CelluloidPubsub
33
33
  end
34
34
 
35
35
  def version_less_than_seventeen?
36
- verify_gem_version('celluloid', '0.17', operator: '<')
36
+ verify_gem_version(celluloid_version, '0.17', operator: '<')
37
37
  end
38
38
 
39
39
  def setup_actor_supervision(class_name, options)
@@ -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
- 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)
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
- (@server.subscribers[channel] || []).delete_if do |hash|
225
- hash[:reactor] == Actor.current
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.subscribers[channel] = channel_subscribers(channel).push(reactor: Actor.current, message: message)
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
- (@server.subscribers[current_topic].dup || []).pmap do |hash|
312
- hash[:reactor].websocket << message
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
- (@server.subscribers[channel].dup || []).pmap do |hash|
341
- reactor = hash[:reactor]
342
- reactor.websocket.close
343
- Celluloid::Actor.kill(reactor)
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
@@ -15,9 +15,9 @@ module CelluloidPubsub
15
15
  # major release version
16
16
  MAJOR = 0
17
17
  # minor release version
18
- MINOR = 7
18
+ MINOR = 8
19
19
  # tiny release version
20
- TINY = 9
20
+ TINY = 0
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -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.7.9
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-06-13 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid