Class: Lightstreamer::StreamConnection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ StreamConnection

Establishes a new stream connection using the authentication details from the passed session.

Parameters:

  • session (Session)

    The session to create a stream connection for.



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

#threadThread (readonly)

Returns The thread used to process incoming streaming data.

Returns:

  • (Thread)

    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

#disconnectObject

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_lineObject

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