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.



360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/omf-web/thin/server.rb', line 360

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



381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/omf-web/thin/server.rb', line 381

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



375
376
377
378
379
# File 'lib/omf-web/thin/server.rb', line 375

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