| 831 | } |
| 832 | |
| 833 | void receive(const Event& event, bool isLocallyInjected) |
| 834 | { |
| 835 | // Check if we're are no longer subscribed but received an event. |
| 836 | if (!isLocallyInjected && state != SUBSCRIBED) { |
| 837 | LOG(WARNING) << "Ignoring " << stringify(event.type()) |
| 838 | << " event because we're no longer subscribed"; |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | if (isLocallyInjected) { |
| 843 | VLOG(1) << "Enqueuing locally injected event " << stringify(event.type()); |
| 844 | } else { |
| 845 | VLOG(1) << "Enqueuing event " << stringify(event.type()) << " received" |
| 846 | << " from " << master.get(); |
| 847 | } |
| 848 | |
| 849 | // Queue up the event and invoke the 'received' callback if this |
| 850 | // is the first event (between now and when the 'received' |
| 851 | // callback actually gets invoked more events might get queued). |
| 852 | events.push(event); |
| 853 | |
| 854 | if (events.size() == 1) { |
| 855 | mutex.lock() |
| 856 | .then(defer(self(), &Self::_receive)) |
| 857 | .onAny(lambda::bind(&Mutex::unlock, mutex)); |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | private: |
| 862 | struct Callbacks |