Module: Server::Listenable
- Included in:
- ModularHandler
- Defined in:
- lib/server/listenable.rb
Overview
The Listenable module
Instance Method Summary collapse
- #add_listener(*listener) ⇒ Object
- #listeners ⇒ Object
- #notify(event, *args) ⇒ Object
- #remove_listener(*listener) ⇒ Object
- #replace_listeners(*listener) ⇒ Object
Instance Method Details
#add_listener(*listener) ⇒ Object
23 24 25 |
# File 'lib/server/listenable.rb', line 23 def add_listener(*listener) listeners.addAll(listener) end |
#listeners ⇒ Object
19 20 21 |
# File 'lib/server/listenable.rb', line 19 def listeners @listeners ||= java.util.concurrent.CopyOnWriteArrayList.new end |
#notify(event, *args) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/server/listenable.rb', line 38 def notify(event, *args) listeners.each do |listener| next unless listener.respond_to?(event.to_sym) log.trace "Notifying listener #{listener} of event: #{event}" listener.send(event.to_sym, *args) end end |
#remove_listener(*listener) ⇒ Object
27 28 29 |
# File 'lib/server/listenable.rb', line 27 def remove_listener(*listener) listeners.removeAll(listener) end |
#replace_listeners(*listener) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/server/listenable.rb', line 31 def replace_listeners(*listener) listeners.clear add_listener(*listener) ensure log.trace "Listeners after replacement: #{listeners}" end |