def self.handle_poll(condition)
Thread.new do
begin
metric = self.directory[condition]
unless metric.nil?
watch = metric.watch
watch.mutex.synchronize do
result = condition.test
messages = self.log(watch, metric, condition, result)
if condition.notify && self.trigger?(metric, result)
self.notify(condition, messages.last)
end
condition.after
dest =
if result && condition.transition
condition.transition
else
metric.destination && metric.destination[result]
end
if dest
begin
watch.move(dest)
rescue EventRegistrationFailedError
msg = watch.name + ' Event registration failed, moving back to previous state'
applog(watch, :info, msg)
dest = watch.state
retry
end
else
Timer.get.schedule(condition)
end
end
end
rescue Exception => e
message = format("Unhandled exception (%s): %s\n%s",
e.class, e.message, e.backtrace.join("\n"))
applog(nil, :fatal, message)
end
end
end