Class: Lightstreamer::StreamConnection
- Inherits:
-
Object
- Object
- Lightstreamer::StreamConnection
- Defined in:
- lib/lightstreamer/stream_connection.rb
Overview
Manages a long-running Lightstreamer connection that handles incoming streaming data on a separate thread and makes it available for consumption via the #read_line method.
Instance Attribute Summary collapse
-
#thread ⇒ Thread
readonly
The thread used to process incoming streaming data.
Instance Method Summary collapse
-
#disconnect ⇒ Object
Disconnects this stream connection by shutting down the streaming thread.
-
#initialize(session) ⇒ StreamConnection
constructor
Establishes a new stream connection using the authentication details from the passed session.
-
#read_line ⇒ Object
Reads the next line of streaming data.
Constructor Details
#initialize(session) ⇒ StreamConnection
Establishes a new stream connection using the authentication details from the passed session.
11 12 13 14 15 16 17 |
# File 'lib/lightstreamer/stream_connection.rb', line 11 def initialize(session) @session = session @queue = Queue.new create_stream create_stream_thread end |
Instance Attribute Details
#thread ⇒ Thread (readonly)
Returns The thread used to process incoming streaming data.
6 7 8 |
# File 'lib/lightstreamer/stream_connection.rb', line 6 def thread @thread end |
Instance Method Details
#disconnect ⇒ Object
Disconnects this stream connection by shutting down the streaming thread.
20 21 22 23 24 25 |
# File 'lib/lightstreamer/stream_connection.rb', line 20 def disconnect return unless @thread Thread.kill @thread @thread.join end |
#read_line ⇒ Object
Reads the next line of streaming data. This method blocks the calling thread until a line of data is available.
28 29 30 |
# File 'lib/lightstreamer/stream_connection.rb', line 28 def read_line @queue.pop end |