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.



406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/omf-web/thin/server.rb', line 406

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



427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/omf-web/thin/server.rb', line 427

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



421
422
423
424
425
# File 'lib/omf-web/thin/server.rb', line 421

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