4 # directory to hold conditions and their corresponding metric
9 def self.attach(condition, metric)
10 # add the condition to the directory
11 @@directory[condition] = metric
13 # schedule poll condition
14 # register event condition
15 if condition.kind_of?(PollCondition)
16 Timer.get.schedule(condition, 0)
22 def self.detach(condition)
23 # remove the condition from the directory
24 @@directory.delete(condition)
26 # unschedule any pending polls
27 Timer.get.unschedule(condition)
29 # deregister event condition
30 if condition.kind_of?(EventCondition)
35 def self.trigger(condition)
36 if condition.kind_of?(PollCondition)
37 self.handle_poll(condition)
38 elsif condition.kind_of?(EventCondition)
39 self.handle_event(condition)
43 def self.handle_poll(condition)
46 metric = @@directory[condition]
49 watch.mutex.synchronize do
50 result = condition.test
52 msg = watch.name + ' ' + condition.class.name + " [#{result}] " + metric.destination.inspect
58 if dest = metric.destination[result]
62 Timer.get.schedule(condition)
66 message = format("Unhandled exception (%s): %s\n%s",
67 e.class, e.message, e.backtrace.join("\n"))
74 def self.handle_event(condition)
76 metric = @@directory[condition]
79 watch.mutex.synchronize do
80 msg = watch.name + ' ' + condition.class.name + " [true] " + metric.destination.inspect
84 dest = metric.destination[true]