rabbitmq 0.2.5 → 1.0.0.pre.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,55 +0,0 @@
1
-
2
- module RabbitMQ
3
- class Connection
4
-
5
- class EventManager
6
- def initialize(connection)
7
- @connection = connection
8
- @event_handlers = Hash.new { |h,k| h[k] = {} }
9
- @incoming_events = Hash.new { |h,k| h[k] = {} }
10
- end
11
-
12
- def register_handler(id, method, handler)
13
- @event_handlers[id][method] = handler
14
- end
15
-
16
- def clear_event_handlers(id)
17
- @event_handlers.delete(id)
18
- end
19
-
20
- def clear_all_event_handlers
21
- @event_handlers.clear
22
- end
23
-
24
- # Execute the handler for this type of event, if any
25
- def handle_incoming_event(event)
26
- if (handlers = @event_handlers[event.fetch(:channel)])
27
- if (handler = (handlers[event.fetch(:method)]))
28
- handler.call(event)
29
- end
30
- end
31
- end
32
-
33
- # Store the event in short-term storage for retrieval by fetch_response.
34
- # If another event is received with the same method name, it will
35
- # overwrite this one - fetch_response gets the latest or next by method.
36
- def store_incoming_event(event)
37
- method = event.fetch(:method)
38
-
39
- case method
40
- when :channel_close
41
- raise_if_server_error!(event)
42
- when :connection_close
43
- raise_if_server_error!(event)
44
- else
45
- @incoming_events[event.fetch(:channel)][method] = event
46
- end
47
- end
48
-
49
- def fetch_stored_event(channel_id, method)
50
- @incoming_events[channel_id].delete(method)
51
- end
52
- end
53
-
54
- end
55
- end