Class: OML4R::Channel
- Inherits:
-
Object
- Object
- OML4R::Channel
- Defined in:
- lib/oml4r.rb
Overview
Measurement Channel
Constant Summary collapse
- @@channels =
{}
- @@default_domain =
nil
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .[](name = :default, domain = :default) ⇒ Object
-
._connect(fquri) ⇒ IO
Parse the given fully-qualified collection URI, and return a suitably connected objet.
- ._create(key, domain, url) ⇒ Object
- .close_all ⇒ Object
- .create(name, url, domain = :default) ⇒ Object
- .init_all(domain, nodeID, appName, startTime, protocol) ⇒ Object
Instance Method Summary collapse
- #build_schema(mp_name, add_prefix, pdefs) ⇒ Object
- #close ⇒ Object
- #init(nodeID, appName, startTime, protocol) ⇒ Object
- #send(msg) ⇒ Object
- #send_schema_update(msg) ⇒ Object
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
608 609 610 |
# File 'lib/oml4r.rb', line 608 def url @url end |
Class Method Details
.[](name = :default, domain = :default) ⇒ Object
568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/oml4r.rb', line 568 def self.[](name = :default, domain = :default) key = "#{name}:#{domain}" unless (@@channels.key?(key)) # If domain != :default and we have one for :default, create a new one if (domain != :default) if (dc = @@channels["#{name}:default"]) return self._create(key, domain, dc.url) end end raise OML4RException.new "OML4R: Unknown channel '#{name}'" end @@channels[key] end |
._connect(fquri) ⇒ IO
Parse the given fully-qualified collection URI, and return a suitably connected objet
Supported URIs are
tcp:host:port
file:/P/A/T/H
554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/oml4r.rb', line 554 def self._connect(fquri) scheme, host, port = fquri.split(':') out = case scheme when 'tcp' out = TCPSocket.new(host, port) when 'file' # host is really a filename here out = (host == '-' ? $stdout : File.open(host, "w+")) else raise OML4RException.new "OML4R: Unknown scheme '#{scheme}" end out end |
._create(key, domain, url) ⇒ Object
539 540 541 |
# File 'lib/oml4r.rb', line 539 def self._create(key, domain, url) @@channels[key] = self.new(url, domain) end |
.close_all ⇒ Object
602 603 604 605 606 |
# File 'lib/oml4r.rb', line 602 def self.close_all() @@channels.values.each { |c| c.close } @@channels = {} MPBase.__unfreeze__() end |
.create(name, url, domain = :default) ⇒ Object
528 529 530 531 532 533 534 535 536 537 |
# File 'lib/oml4r.rb', line 528 def self.create(name, url, domain = :default) key = "#{name}:#{domain}" if channel = @@channels[key] if url != channel.url raise OML4RException.new "OML4R: Channel '#{name}' already defined with different url" end return channel end return self._create(key, domain, url) end |
.init_all(domain, nodeID, appName, startTime, protocol) ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
# File 'lib/oml4r.rb', line 582 def self.init_all(domain, nodeID, appName, startTime, protocol) @@default_domain = domain @@nodeID = nodeID @@appName = appName @@startTime = startTime @@protocol = protocol MPBase.__freeze__(appName, startTime) # send channel header @@channels.values.each { |c| c.init(nodeID, appName, startTime, protocol) } # send schema definitions MPBase.each_mp do |klass, defs| klass.(appName) end MPBase.__useOML__() end |
Instance Method Details
#build_schema(mp_name, add_prefix, pdefs) ⇒ Object
618 619 620 621 622 623 624 625 626 627 |
# File 'lib/oml4r.rb', line 618 def build_schema(mp_name, add_prefix, pdefs) @index += 1 line = [@index, (!@@appName.nil? && add_prefix)? "#{@@appName}_#{mp_name}" : mp_name] pdefs.each do |d| line << "#{d[:name]}:#{d[:type]}" end msg = line.join(' ') @schemas << msg [@index, msg] end |
#close ⇒ Object
643 644 645 646 |
# File 'lib/oml4r.rb', line 643 def close() @queue.push nil # indicate end of work @runner.join() end |
#init(nodeID, appName, startTime, protocol) ⇒ Object
638 639 640 641 |
# File 'lib/oml4r.rb', line 638 def init(nodeID, appName, startTime, protocol) @nodeID, @appName, @startTime, @protocol = nodeID, appName, startTime, protocol @out = _connect(@url) end |
#send(msg) ⇒ Object
629 630 631 |
# File 'lib/oml4r.rb', line 629 def send(msg) @queue.push msg end |
#send_schema_update(msg) ⇒ Object
633 634 635 636 |
# File 'lib/oml4r.rb', line 633 def send_schema_update(msg) @header_sent = true @queue.push msg end |