Permalink
Browse files

reduce thread locals

  • Loading branch information...
tenderlove committed Jun 19, 2012
1 parent a01d9da commit e4de78aec504b885d40c0244ce3222c05ca3dc2e
Showing with 20 additions and 3 deletions.
  1. +20 −3 activesupport/lib/active_support/notifications.rb
@@ -137,6 +137,23 @@ module ActiveSupport
module Notifications
@instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }
+ class Registry # :nodoc:
+ def self.instance
+ Thread.current[name] ||= new
+ end
+
+ attr_reader :notifier, :instrumenter
+
+ def initialize
+ self.notifier = Fanout.new
+ end
+
+ def notifier=(notifier)
+ @notifier = notifier
+ @instrumenter = Instrumenter.new(notifier)
+ end
+ end
+
class << self
def publish(name, *args)
notifier.publish(name, *args)
@@ -169,15 +186,15 @@ def unsubscribe(args)
end
def instrumenter
- Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
+ Registry.instance.instrumenter
end
def notifier
- Thread.current[:notifier] ||= Fanout.new
+ Registry.instance.notifier
end
def notifier=(notifier)
- Thread.current[:notifier] = notifier
+ Registry.instance.notifier = notifier
end
end
end

0 comments on commit e4de78a

Please sign in to comment.