Class: Puppet::Util::Instrumentation::Listener

Inherits:
Object
  • Object
show all
Extended by:
Indirector
Includes:
Puppet::Util, Warnings
Defined in:
lib/vendor/puppet/util/instrumentation/listener.rb

Constant Summary

Constants included from Indirector

Indirector::BadNameRegexp

Constants included from Puppet::Util

AbsolutePathPosix, AbsolutePathWindows

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

configure_routes, indirects

Methods included from Warnings

clear_warnings, notice_once, warnonce

Methods included from Puppet::Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Constructor Details

#initialize(listener, pattern = nil, enabled = false) ⇒ Listener

Returns a new instance of Listener.



15
16
17
18
19
20
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 15

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

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



13
14
15
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 13

def enabled
  @enabled
end

#listenerObject (readonly)

Returns the value of attribute listener.



12
13
14
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 12

def listener
  @listener
end

#patternObject (readonly)

Returns the value of attribute pattern.



12
13
14
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 12

def pattern
  @pattern
end

Class Method Details

.from_pson(data) ⇒ Object



56
57
58
59
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 56

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

Instance Method Details

#dataObject



40
41
42
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 40

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

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 32

def enabled?
  !!@enabled
end

#listen_to?(label) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 28

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

#nameObject



36
37
38
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 36

def name
  @listener.name.to_s
end

#notify(label, event, data) ⇒ Object



22
23
24
25
26
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 22

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

#to_pson(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vendor/puppet/util/instrumentation/listener.rb', line 44

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