Class: Clepsydra::Notifier

Inherits:
Object
  • Object
show all
Includes:
Mutex_m
Defined in:
lib/clepsydra/notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNotifier

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

#idObject (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

Returns:

  • (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