Class: OMF::Web::Server::OmspEndpointProxy

Inherits:
Base::LObject
  • Object
show all
Defined in:
lib/omf-web/thin/server.rb

Overview

This class manages an OMSP Endpoint and all the related data sources

Instance Method Summary collapse

Constructor Details

#initialize(port) ⇒ OmspEndpointProxy

Returns a new instance of OmspEndpointProxy.



447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/omf-web/thin/server.rb', line 447

def initialize(port)
  @streams = {}
  @sources = {}
  @tables = {}
  require 'omf_oml/endpoint'
  @ep = OMF::OML::OmlEndpoint.new(port)
  @ep.on_new_stream() do |name, stream|
    _on_new_stream(name, stream)
  end
  Thread.new do # delay starting up endpoint, can't use EM yet
    sleep 2
    @ep.run(false)
  end
end

Instance Method Details

#_on_new_stream(name, stream) ⇒ Object



468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/omf-web/thin/server.rb', line 468

def _on_new_stream(name, stream)
  debug "New stream: #{name}-#{stream}"
  (@sources[name] || []).each do |tdef|
    puts "TDEF: #{tdef}"
    tname = tdef.dup.delete(:id)
    unless table = @tables[tname]
      table = @tables[tname] = stream.create_table(tname, tdef)
      OMF::Web.register_datasource table
      puts "ADDED: #{table}"
    else
      warn "Looks like reconnection, should reconnect to table as well"
    end
  end
end

#add_datasource(name, config) ⇒ Object



462
463
464
465
466
# File 'lib/omf-web/thin/server.rb', line 462

def add_datasource(name, config)
  stream_name = config[:omsp][:stream_name] || name
  config.delete(:omsp)
  (@sources[stream_name.to_s] ||= []) << config
end