Sha256: 359ad496f6df2fff70ddd5dc7a4e44d53335377c83b1cd4d18f1f5c5539b3133

Contents?: true

Size: 1.41 KB

Versions: 60

Compression:

Stored size: 1.41 KB

Contents

require 'puppet/indirector'
require 'puppet/util/instrumentation'
require 'puppet/util/instrumentation/data'

class Puppet::Util::Instrumentation::Listener
  include Puppet::Util
  include Puppet::Util::Warnings
  extend Puppet::Indirector

  indirects :instrumentation_listener, :terminus_class => :local

  attr_reader :pattern, :listener
  attr_accessor :enabled

  def initialize(listener, pattern = nil, enabled = false)
    @pattern = pattern.is_a?(Symbol) ? pattern.to_s : pattern
    raise "Listener isn't a correct listener (it doesn't provide the notify method)" unless listener.respond_to?(:notify)
    @listener = listener
    @enabled = enabled
  end

  def notify(label, event, data)
    listener.notify(label, event, data)
  rescue => e
    warnonce("Error during instrumentation notification: #{e}")
  end

  def listen_to?(label)
    enabled? and (!@pattern || @pattern === label.to_s)
  end

  def enabled?
    !!@enabled
  end

  def name
    @listener.name.to_s
  end

  def data
    { :data => @listener.data }
  end

  def to_pson(*args)
    result = {
      :document_type => "Puppet::Util::Instrumentation::Listener",
      :data => {
        :name => name,
        :pattern => pattern,
        :enabled => enabled?
      }
    }
    result.to_pson(*args)
  end

  def self.from_pson(data)
    result = Puppet::Util::Instrumentation[data["name"]]
    self.new(result.listener, result.pattern, data["enabled"])
  end
end

Version data entries

60 entries across 60 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/util/instrumentation/listener.rb
puppet-parse-0.1.3 lib/vendor/puppet/util/instrumentation/listener.rb
puppet-parse-0.1.2 lib/vendor/puppet/util/instrumentation/listener.rb
puppet-parse-0.1.1 lib/vendor/puppet/util/instrumentation/listener.rb
puppet-2.7.26 lib/puppet/util/instrumentation/listener.rb
puppet-2.7.25 lib/puppet/util/instrumentation/listener.rb
puppet-2.7.24 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.2 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.1 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.1.rc3 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.1.rc2 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.1.rc1 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.0 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.0.rc3 lib/puppet/util/instrumentation/listener.rb
puppet-3.3.0.rc2 lib/puppet/util/instrumentation/listener.rb
puppet-3.2.4 lib/puppet/util/instrumentation/listener.rb
puppet-2.7.23 lib/puppet/util/instrumentation/listener.rb
puppet-3.2.3 lib/puppet/util/instrumentation/listener.rb
puppet-3.2.3.rc1 lib/puppet/util/instrumentation/listener.rb
puppet-3.2.2 lib/puppet/util/instrumentation/listener.rb