1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Creating an object to consolidate thread locals which hold the

instrumenters for the AS::Notifications module.
This commit is contained in:
wangjohn 2013-04-08 16:50:05 -04:00
parent 5afaf4e2ba
commit b62c197a22

View file

@ -177,7 +177,33 @@ module ActiveSupport
end
def instrumenter
Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
InstrumentationRegistry.instrumenter_for(notifier)
end
end
# This class is a registry which holds all of the +Instrumenter+ objects
# in a particular thread local. To access the +Instrumenter+ object for a
# particular +notifier+, you can call the following method:
#
# InstrumentationRegistry.instrumenter_for(notifier)
#
# The instrumenters for multiple notifiers are held in a single instance of
# this class.
class InstrumentationRegistry # :nodoc:
class << self
delegate :instrumenter_for, to: :current
def current
Thread.current[:instrumentation_registry] ||= new
end
end
def initialize
@registry = {}
end
def instrumenter_for(notifier)
@registry[notifier] ||= Instrumenter.new(notifier)
end
end