Class: Wonkavision::EventCoordinator
- Inherits:
-
Object
- Object
- Wonkavision::EventCoordinator
- Defined in:
- lib/wonkavision/event_coordinator.rb
Instance Attribute Summary collapse
-
#broadcast_transport ⇒ Object
Returns the value of attribute broadcast_transport.
-
#job_queue ⇒ Object
Returns the value of attribute job_queue.
-
#root_namespace ⇒ Object
readonly
Returns the value of attribute root_namespace.
Instance Method Summary collapse
- #before_receive_event(&block) ⇒ Object
- #clear_filters ⇒ Object
- #configure(&block) ⇒ Object
-
#initialize ⇒ EventCoordinator
constructor
A new instance of EventCoordinator.
- #map {|root_namespace| ... } ⇒ Object
- #publish(event_path, event_data) ⇒ Object
- #receive_event(event_path, event_data) ⇒ Object
- #submit_job(event_path, event_data) ⇒ Object
- #subscribe(event_path, final_segment_type = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ EventCoordinator
Returns a new instance of EventCoordinator.
7 8 9 10 11 12 13 |
# File 'lib/wonkavision/event_coordinator.rb', line 7 def initialize @root_namespace = Wonkavision::EventNamespace.new #@lock = Mutex.new #@event_cache = {} @incoming_event_filters = [] end |
Instance Attribute Details
#broadcast_transport ⇒ Object
Returns the value of attribute broadcast_transport.
5 6 7 |
# File 'lib/wonkavision/event_coordinator.rb', line 5 def broadcast_transport @broadcast_transport end |
#job_queue ⇒ Object
Returns the value of attribute job_queue.
5 6 7 |
# File 'lib/wonkavision/event_coordinator.rb', line 5 def job_queue @job_queue end |
#root_namespace ⇒ Object (readonly)
Returns the value of attribute root_namespace.
4 5 6 |
# File 'lib/wonkavision/event_coordinator.rb', line 4 def root_namespace @root_namespace end |
Instance Method Details
#before_receive_event(&block) ⇒ Object
15 16 17 |
# File 'lib/wonkavision/event_coordinator.rb', line 15 def before_receive_event(&block) @incoming_event_filters << block end |
#clear_filters ⇒ Object
19 20 21 |
# File 'lib/wonkavision/event_coordinator.rb', line 19 def clear_filters @incoming_event_filters = [] end |
#configure(&block) ⇒ Object
23 24 25 |
# File 'lib/wonkavision/event_coordinator.rb', line 23 def configure(&block) self.instance_eval(&block) end |
#map {|root_namespace| ... } ⇒ Object
27 28 29 |
# File 'lib/wonkavision/event_coordinator.rb', line 27 def map yield root_namespace if block_given? end |
#publish(event_path, event_data) ⇒ Object
51 52 53 54 |
# File 'lib/wonkavision/event_coordinator.rb', line 51 def publish(event_path, event_data) raise "No transport was configured with the EventCoordinator to deliver broadcast messages. Please set Wonkavision.event_coordinator.broadcast_transport = <some transport>." unless broadcast_transport broadcast_transport.publish(event_path, event_data) end |
#receive_event(event_path, event_data) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wonkavision/event_coordinator.rb', line 37 def receive_event(event_path, event_data) #@lock.synchronize do #If process_incoming_event returns nil or false, it means a filter chose to abort #the event processing, in which case we'll break for lunch. return unless event_data = process_incoming_event(event_path,event_data) event_path = Wonkavision.normalize_event_path(event_path) targets = root_namespace.find_matching_segments(event_path).values #If the event wasn't matched, maybe someone is subscribing to '/*' ? targets = [root_namespace] if targets.blank? targets.each{|target|target.notify_subscribers(event_data,event_path)} #end end |
#submit_job(event_path, event_data) ⇒ Object
56 57 58 59 |
# File 'lib/wonkavision/event_coordinator.rb', line 56 def submit_job(event_path, event_data) job_queue ? job_queue.publish(event_path,event_data) : receive_event(event_path, event_data) end |
#subscribe(event_path, final_segment_type = nil, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/wonkavision/event_coordinator.rb', line 31 def subscribe(event_path,final_segment_type=nil,&block) event_path, final_segment_type = *detect_final_segment(event_path) unless final_segment_type segment = (event_path.blank? ? root_namespace : root_namespace.find_or_create(event_path,final_segment_type)) segment.subscribe(&block) end |