lightstreamer 0.11 → 0.12

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: 712d0f7cae7367c26efde5f75b0481bb5a3d90a3
4
- data.tar.gz: 77a6882d44273754bb5c85a7739bb614860b7b82
3
+ metadata.gz: 979c7fa279f1b55d71b9525b8a8f5b67aaf1c45e
4
+ data.tar.gz: 15a5a203a5012063ab4b795d60486bc7c9882cad
5
5
  SHA512:
6
- metadata.gz: e6eec1efbbd9e79c891798f8833a820396caa40b0bbb275eee686b95cc93689651e7703495949953d66ea80e95278e0b3f2203e2ad032a1861981426d082473b
7
- data.tar.gz: 6164a9f932129439f3870081d55962ebae8f35f44169269f366bd64d2222d66d6bbd14e25fd92b9d59bfe7d3bff8ec52f8f8a5af8ee44a4cd6c144ccd9635377
6
+ metadata.gz: 8af68aba835e410dd291393dc187a1ac2af83d9406dfb34278c0ec2d5ecbb24cbb41cea1cfbe198407a21e47e1229a9ded930ec3ed394539f7caa63caf2dbc64
7
+ data.tar.gz: 8246eea6cf6d897232791b5a225e5d75f97bf954ca5c0742c63f86ac75225c657ee119ea5c1ea0b6308b68ef801e4f1bfb517c172d5a85b5372ab479ef3d4021
data/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # Lightstreamer Changelog
2
2
 
3
+ ### 0.12 — August 20, 2016
4
+
5
+ - Added `Lightstreamer::Session#remove_subscriptions`
6
+ - Removed `Lightstreamer::Subscription#session`, subscriptions now hold a weak reference to their session in order to
7
+ prevent a circular reference
8
+
3
9
  ### 0.11 — August 20, 2016
4
10
 
5
11
  - Added `Lightstreamer::Session#stop_subscriptions` for stopping multiple subscriptions in one request
6
12
  - Renamed `Lightstreamer::Session#bulk_subscription_start` to `Lightstreamer::Session#start_subscriptions`
7
13
  - Added support for combining all subscription actions via `Lightstreamer::Session#perform_subscription_actions`
8
14
  which allows subscription start, unsilence and stop requests to be easily bundled together
9
- - Fixed `Subscription#id` only being callable on the main thread
15
+ - Fixed `Lightstreamer::Subscription#id` only being callable on the main thread
10
16
 
11
17
  ### 0.10 — August 5, 2016
12
18
 
data/README.md CHANGED
@@ -40,8 +40,8 @@ $ gem install lightstreamer
40
40
 
41
41
  The two primary classes that make up the public API are:
42
42
 
43
- - [`Lightstreamer::Session`](http://www.rubydoc.info/github/rviney/lightstreamer/Lightstreamer/Session)
44
- - [`Lightstreamer::Subscription`](http://www.rubydoc.info/github/rviney/lightstreamer/Lightstreamer/Subscription)
43
+ - [`Lightstreamer::Session`](http://www.rubydoc.info/github/rviney/lightstreamer/master/Lightstreamer/Session)
44
+ - [`Lightstreamer::Subscription`](http://www.rubydoc.info/github/rviney/lightstreamer/master/Lightstreamer/Subscription)
45
45
 
46
46
  The following code demonstrates how to create a Lightstreamer session, build a subscription, then use a thread-safe
47
47
  queue to print streaming output as it arrives.
data/lib/lightstreamer.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'thread'
2
+ require 'weakref'
2
3
 
3
4
  require 'excon'
4
5
  require 'thor'
@@ -92,7 +92,8 @@ module Lightstreamer
92
92
  @stream_connection && @stream_connection.session_id
93
93
  end
94
94
 
95
- # Disconnects this Lightstreamer session and terminates the session on the server. All worker threads are exited.
95
+ # Disconnects this Lightstreamer session and terminates the session on the server. All worker threads are exited,
96
+ # and all subscriptions created during the connected session can no longer be used.
96
97
  def disconnect
97
98
  control_request LS_op: :destroy if @stream_connection
98
99
 
@@ -102,6 +103,7 @@ module Lightstreamer
102
103
  @processing_thread.exit if @processing_thread
103
104
 
104
105
  @subscriptions.each { |subscription| subscription.after_control_request :stop }
106
+ @subscriptions = []
105
107
 
106
108
  @processing_thread = @stream_connection = nil
107
109
  end
@@ -147,9 +149,29 @@ module Lightstreamer
147
149
  #
148
150
  # @param [Subscription] subscription The subscription to stop and remove from this session.
149
151
  def remove_subscription(subscription)
150
- subscription.stop
152
+ errors = remove_subscriptions [subscription]
153
+
154
+ raise errors.first if errors.first
155
+ end
156
+
157
+ # Stops the specified subscriptions and removes them from this session. To just stop subscriptions with the option
158
+ # of restarting them at a later date use {#stop_subscriptions} or {Subscription#stop}. The return value is an array
159
+ # with one entry per subscription and indicates the error state returned by the server for that subscription's stop
160
+ # request, or `nil` if no error occurred.
161
+ #
162
+ # @param [Array<Subscription>] subscriptions The subscriptions to stop and remove from this session.
163
+ #
164
+ # @return [Array<LightstreamerError, nil>]
165
+ def remove_subscriptions(subscriptions)
166
+ errors = stop_subscriptions subscriptions
167
+
168
+ @mutex.synchronize do
169
+ subscriptions.reject(&:active).each do |subscription|
170
+ @subscriptions.delete subscription
171
+ end
172
+ end
151
173
 
152
- @mutex.synchronize { @subscriptions.delete subscription }
174
+ errors
153
175
  end
154
176
 
155
177
  # This method performs {Subscription#start} on all the passed subscriptions. Calling {Subscription#start} on each
@@ -4,11 +4,6 @@ module Lightstreamer
4
4
  # streaming subscription data can be consumed by registering an asynchronous data callback using {#on_data}, or by
5
5
  # polling using {#item_data}.
6
6
  class Subscription
7
- # The session that this subscription is associated with.
8
- #
9
- # @return [Session]
10
- attr_reader :session
11
-
12
7
  # The names of the items to subscribe to.
13
8
  #
14
9
  # @return [Array]
@@ -58,7 +53,7 @@ module Lightstreamer
58
53
  def initialize(session, options)
59
54
  @mutex = Mutex.new
60
55
 
61
- @session = session
56
+ @session = WeakRef.new session
62
57
  @items = options.fetch(:items)
63
58
  @fields = options.fetch(:fields)
64
59
  @mode = options.fetch(:mode).to_sym
@@ -97,7 +92,7 @@ module Lightstreamer
97
92
  def start(options = {})
98
93
  return if @active
99
94
 
100
- session.control_request control_request_options(:start, options)
95
+ @session.control_request control_request_options(:start, options)
101
96
  after_control_request :start
102
97
  end
103
98
 
@@ -105,14 +100,14 @@ module Lightstreamer
105
100
  # this subscription was not started in silent mode then this method has no effect. If an error occurs then a
106
101
  # {LightstreamerError} subclass will be raised.
107
102
  def unsilence
108
- session.control_request control_request_options(:unsilence)
103
+ @session.control_request control_request_options(:unsilence)
109
104
  after_control_request :unsilence
110
105
  end
111
106
 
112
107
  # Stops streaming data for this Lightstreamer subscription. If an error occurs then a {LightstreamerError} subclass
113
108
  # will be raised.
114
109
  def stop
115
- session.control_request control_request_options(:stop) if @active
110
+ @session.control_request control_request_options(:stop) if @active
116
111
  after_control_request :stop
117
112
  end
118
113
 
@@ -125,7 +120,7 @@ module Lightstreamer
125
120
  # details.
126
121
  def maximum_update_frequency=(new_frequency)
127
122
  new_frequency = sanitize_frequency new_frequency
128
- session.control_request LS_op: :reconf, LS_table: id, LS_requested_max_frequency: new_frequency if @active
123
+ @session.control_request LS_op: :reconf, LS_table: id, LS_requested_max_frequency: new_frequency if @active
129
124
  @maximum_update_frequency = new_frequency
130
125
  end
131
126
 
@@ -224,9 +219,9 @@ module Lightstreamer
224
219
  when :start
225
220
  start_control_request_options options
226
221
  when :unsilence
227
- { LS_session: session.session_id, LS_op: :start, LS_table: id }
222
+ { LS_session: @session.session_id, LS_op: :start, LS_table: id }
228
223
  when :stop
229
- { LS_session: session.session_id, LS_op: :delete, LS_table: id }
224
+ { LS_session: @session.session_id, LS_op: :delete, LS_table: id }
230
225
  end
231
226
  end
232
227
 
@@ -286,7 +281,7 @@ module Lightstreamer
286
281
 
287
282
  operation = options[:silent] ? :add_silent : :add
288
283
 
289
- { LS_session: session.session_id, LS_op: operation, LS_table: id, LS_mode: mode.to_s.upcase, LS_id: items,
284
+ { LS_session: @session.session_id, LS_op: operation, LS_table: id, LS_mode: mode.to_s.upcase, LS_id: items,
290
285
  LS_schema: fields, LS_selector: selector, LS_snapshot: options.fetch(:snapshot, false),
291
286
  LS_requested_max_frequency: maximum_update_frequency, LS_data_adapter: data_adapter }
292
287
  end
@@ -1,4 +1,4 @@
1
1
  module Lightstreamer
2
2
  # The version of this gem.
3
- VERSION = '0.11'.freeze
3
+ VERSION = '0.12'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightstreamer
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.11'
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Viney