class Lightstreamer::CLI::Main

Implements the `lightstreamer stream` command.

Implements the `lightstreamer` command-line client.

Public Class Methods

bootstrap(argv) click to toggle source

This is the initial entry point for the execution of the command-line client. It is responsible for the –version/-v options and then invoking the main application.

@param [Array<String>] argv The array of command-line arguments.

# File lib/lightstreamer/cli/main.rb, line 13
def bootstrap(argv)
  if argv.index('--version') || argv.index('-v')
    puts VERSION
    exit
  end

  start argv
end

Public Instance Methods

stream() click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 22
def stream
  prepare_stream

  puts "Session ID: #{@session.session_id}"

  loop do
    data = @queue.pop

    if data.is_a? Lightstreamer::LightstreamerError
      puts "Error: #{data}"
      break
    end

    puts data
  end
end

Private Instance Methods

create_session() click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 48
def create_session
  @session = Lightstreamer::Session.new session_options
  @session.connect
  @session.on_message_result(&method(:on_message_result))
  @session.on_error(&method(:on_error))
end
create_subscription() click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 55
def create_subscription
  subscription = @session.build_subscription subscription_options

  subscription.on_data(&method(:on_data))
  subscription.on_overflow(&method(:on_overflow))
  subscription.on_end_of_snapshot(&method(:on_end_of_snapshot))

  subscription.start
end
on_data(_subscription, item_name, _item_data, new_data) click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 77
def on_data(_subscription, item_name, _item_data, new_data)
  @queue.push "#{item_name} - #{new_data.map { |key, value| "#{key}: #{value}" }.join ', '}"
end
on_end_of_snapshot(_subscription, item_name) click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 89
def on_end_of_snapshot(_subscription, item_name)
  @queue.push "End of snapshot for item #{item_name}"
end
on_error(error) click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 93
def on_error(error)
  @queue.push error
end
on_message_result(sequence, numbers, error) click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 85
def on_message_result(sequence, numbers, error)
  @queue.push "Message result for #{sequence}#{numbers} = #{error ? error.class : 'Done'}"
end
on_overflow(_subscription, item_name, overflow_size) click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 81
def on_overflow(_subscription, item_name, overflow_size)
  @queue.push "Overflow of size #{overflow_size} on item #{item_name}"
end
prepare_stream() click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 41
def prepare_stream
  @queue = Queue.new

  create_session
  create_subscription
end
session_options() click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 65
def session_options
  { server_url: options[:server_url], username: options[:username], password: options[:password],
    adapter_set: options[:adapter_set], requested_maximum_bandwidth: options[:requested_maximum_bandwidth],
    polling_enabled: options[:polling_enabled] }
end
subscription_options() click to toggle source
# File lib/lightstreamer/cli/commands/stream_command.rb, line 71
def subscription_options
  { items: options[:items], fields: options[:fields], mode: options[:mode], data_adapter: options[:data_adapter],
    maximum_update_frequency: options[:maximum_update_frequency], selector: options[:selector],
    snapshot: options[:snapshot] }
end