Class: Clepsydra::Notifier
- Inherits:
-
Object
- Object
- Clepsydra::Notifier
- Includes:
- Mutex_m
- Defined in:
- lib/clepsydra/notifier.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #finish(event_name, event_id, instrumenter_id, payload) ⇒ Object
-
#initialize ⇒ Notifier
constructor
A new instance of Notifier.
- #start(event_name, event_id) ⇒ Object
- #subscribe(event_name, monotonic, &block) ⇒ Object
- #subscribed?(event_name) ⇒ Boolean
- #unsubscribe(subscriber) ⇒ Object
- #unsubscribe_all(event_name) ⇒ Object
Constructor Details
#initialize ⇒ Notifier
Returns a new instance of Notifier.
11 12 13 14 15 16 |
# File 'lib/clepsydra/notifier.rb', line 11 def initialize @id = "notifier_#{Clepsydra::TokenProvider.generate}" @subscribers = Hash.new { |h, k| h[k] = [] } super end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/clepsydra/notifier.rb', line 9 def id @id end |
Instance Method Details
#finish(event_name, event_id, instrumenter_id, payload) ⇒ Object
40 41 42 |
# File 'lib/clepsydra/notifier.rb', line 40 def finish(event_name, event_id, instrumenter_id, payload) synchronize { @subscribers[event_name].each { |s| s.finish(event_id, instrumenter_id, payload) } } end |
#start(event_name, event_id) ⇒ Object
34 35 36 37 38 |
# File 'lib/clepsydra/notifier.rb', line 34 def start(event_name, event_id) synchronize { @subscribers[event_name].each { |s| s.start(event_id) } } event_id end |
#subscribe(event_name, monotonic, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/clepsydra/notifier.rb', line 18 def subscribe(event_name, monotonic, &block) subscriber = Clepsydra::Subscriber.new(event_name, monotonic, block) synchronize { @subscribers[event_name] << subscriber } subscriber end |
#subscribed?(event_name) ⇒ Boolean
44 45 46 |
# File 'lib/clepsydra/notifier.rb', line 44 def subscribed?(event_name) synchronize { @subscribers[event_name] }.any? end |
#unsubscribe(subscriber) ⇒ Object
30 31 32 |
# File 'lib/clepsydra/notifier.rb', line 30 def unsubscribe(subscriber) synchronize { @subscribers[subscriber.event_name].delete(subscriber) } end |
#unsubscribe_all(event_name) ⇒ Object
26 27 28 |
# File 'lib/clepsydra/notifier.rb', line 26 def unsubscribe_all(event_name) synchronize { @subscribers.delete(event_name) } end |