tengine_event 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDBjNjRmMTY0OTg2ODcyY2VjMjIwYWRiZDRhOTQyN2I2NDNmNzA5Zg==
5
+ data.tar.gz: !binary |-
6
+ NTgxZjRjY2QzYzA1MzNjMGQ4MThmOGQzODc0MDAzYzExMjgxODM2MA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDlmNGU2MmJmMzE0NDFhMzlmOTYzZTVkODI1Y2RlYzQwZjg0ZjJkMGQyZjZk
10
+ ODY0MDdiZTQ4YmUzM2Y0MjRkMzc1Y2QyNzNhOGJhMzg0YjU5YzNlYmQ1Yjhj
11
+ NGZjNDI1NDA5YWIxYmViZDdjMzVmNTNhM2Y0YzVlM2MxMWNmZTI=
12
+ data.tar.gz: !binary |-
13
+ NDdhOTFjZTkzMDdkNjBmNzcwOTczZTJkYzMzMjYzMjM0YTBjYTMyM2I3MzZh
14
+ NjhhZDBmMDUwMzkwNmQxYzBlYTE5ZTIyNDIxYjUxOGQ5NTg5OTdlMWQ4ZmFm
15
+ ZDYzN2I1OTY3MTYzMWFiMDc3MDMwYTdkNzYyZGM2MWJkOTk4YzQ=
@@ -1,40 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tengine_event (1.1.0)
4
+ tengine_event (1.2.0)
5
5
  activesupport (>= 3.0.0)
6
- amqp (~> 0.8.0)
7
- tengine_support (~> 1.1.0)
6
+ amqp (~> 0.9.10)
7
+ tengine_support (~> 1.2.0)
8
8
  uuid (~> 2.3.4)
9
9
 
10
10
  GEM
11
11
  remote: http://rubygems.org/
12
12
  specs:
13
- ZenTest (4.8.2)
14
- activesupport (3.2.9)
15
- i18n (~> 0.6)
13
+ ZenTest (4.9.1)
14
+ activesupport (3.2.13)
15
+ i18n (= 0.6.1)
16
16
  multi_json (~> 1.0)
17
- amq-client (0.8.7)
18
- amq-protocol (>= 0.8.4)
17
+ amq-client (0.9.12)
18
+ amq-protocol (>= 1.2.0)
19
19
  eventmachine
20
- amq-protocol (0.8.4)
21
- amqp (0.8.4)
22
- amq-client (~> 0.8.7)
23
- amq-protocol (~> 0.8.4)
20
+ amq-protocol (1.2.0)
21
+ amqp (0.9.10)
22
+ amq-client (~> 0.9.12)
23
+ amq-protocol (~> 1.2.0)
24
24
  eventmachine
25
25
  autotest (4.4.6)
26
26
  ZenTest (>= 4.4.1)
27
- builder (3.1.3)
28
- ci_reporter (1.6.9)
29
- builder (>= 2.1.2)
27
+ coderay (1.0.9)
28
+ columnize (0.3.6)
29
+ debugger (1.5.0)
30
+ columnize (>= 0.3.1)
31
+ debugger-linecache (~> 1.2.0)
32
+ debugger-ruby_core_source (~> 1.2.0)
33
+ debugger-linecache (1.2.0)
34
+ debugger-ruby_core_source (1.2.0)
30
35
  diff-lcs (1.1.3)
31
- eventmachine (1.0.0)
36
+ eventmachine (1.0.3)
32
37
  i18n (0.6.1)
33
38
  macaddr (1.6.1)
34
39
  systemu (~> 2.5.0)
35
- multi_json (1.3.6)
36
- rake (0.9.2.2)
37
- rdiscount (1.6.8)
40
+ method_source (0.8.1)
41
+ multi_json (1.7.2)
42
+ pry (0.9.12.1)
43
+ coderay (~> 1.0.5)
44
+ method_source (~> 0.8)
45
+ slop (~> 3.4)
46
+ pry-debugger (0.2.2)
47
+ debugger (~> 1.3)
48
+ pry (~> 0.9.10)
49
+ pry-doc (0.4.5)
50
+ pry (>= 0.9)
51
+ yard (>= 0.8)
52
+ rake (10.0.4)
38
53
  rspec (2.10.0)
39
54
  rspec-core (~> 2.10.0)
40
55
  rspec-expectations (~> 2.10.0)
@@ -43,27 +58,30 @@ GEM
43
58
  rspec-expectations (2.10.0)
44
59
  diff-lcs (~> 1.1.3)
45
60
  rspec-mocks (2.10.1)
46
- simplecov (0.6.4)
61
+ simplecov (0.7.1)
47
62
  multi_json (~> 1.0)
48
- simplecov-html (~> 0.5.3)
49
- simplecov-html (0.5.3)
63
+ simplecov-html (~> 0.7.1)
64
+ simplecov-html (0.7.1)
65
+ slop (3.4.4)
50
66
  systemu (2.5.2)
51
- tengine_support (1.1.0)
67
+ tengine_support (1.2.0)
52
68
  activesupport (>= 3.0.0)
53
- uuid (2.3.5)
69
+ uuid (2.3.7)
54
70
  macaddr (~> 1.0)
55
- yard (0.8.2.1)
71
+ yard (0.8.6.1)
56
72
 
57
73
  PLATFORMS
58
74
  ruby
59
75
 
60
76
  DEPENDENCIES
77
+ ZenTest (~> 4.9.0)
61
78
  autotest
62
79
  bundler
63
- ci_reporter (~> 1.6.5)
64
- rake (~> 0.9.2.2)
65
- rdiscount
80
+ pry
81
+ pry-debugger
82
+ pry-doc
83
+ rake
66
84
  rspec (~> 2.10.0)
67
- simplecov (~> 0.6.4)
85
+ simplecov
68
86
  tengine_event!
69
- yard (~> 0.8.1)
87
+ yard
@@ -80,7 +80,7 @@ class Tengine::Event::Sender
80
80
  # @option options [Hash] :retry_count
81
81
  # @return [Tengine::Event]
82
82
  def fire(event_or_event_type_name, options = {}, &block)
83
- # @logger.info("fire(#{event_or_event_type_name.inspect}, #{options}) called")
83
+ @logger.debug("#{self.class.name}#fire(#{event_or_event_type_name.inspect}, #{options}) called")
84
84
  opts = (options || {}).dup
85
85
  cfg = {
86
86
  :keep_connection => (opts.delete(:keep_connection) || default_keep_connection),
@@ -95,10 +95,10 @@ class Tengine::Event::Sender
95
95
  :event_type_name => event_or_event_type_name.to_s))
96
96
  end
97
97
  @mq_suite.fire self, event, cfg, block
98
- # @logger.info("fire(#{event_or_event_type_name.inspect}, #{options}) complete")
98
+ @logger.debug("#{self.class.name}#fire(#{event_or_event_type_name.inspect}, #{options}) complete")
99
99
  event
100
100
  rescue Exception => e
101
- @logger.warn("fire(#{event_or_event_type_name.inspect}, #{options}) raised [#{e.class.name}] #{e.message}")
101
+ @logger.warn("#{self.class.name}#fire(#{event_or_event_type_name.inspect}, #{options}) raised [#{e.class.name}] #{e.message}")
102
102
  raise e
103
103
  end
104
104
 
@@ -7,7 +7,6 @@ require 'tengine/support/core_ext/hash/compact'
7
7
  require 'tengine/support/core_ext/hash/deep_dup'
8
8
  require 'tengine/support/core_ext/hash/keys'
9
9
  require 'tengine/support/core_ext/enumerable/each_next_tick'
10
- require 'tengine/support/core_ext/enumerable/deep_freeze'
11
10
  require 'tengine/support/core_ext/module/private_constant'
12
11
  require 'amqp'
13
12
  require 'amqp/extensions/rabbitmq'
@@ -18,7 +17,12 @@ class Tengine::Mq::Suite
18
17
  private
19
18
  #######
20
19
 
21
- PendingEvent = Struct.new :tag, :sender, :event, :opts, :retry, :block
20
+ PendingEvent = Struct.new(:tag, :sender, :event, :opts, :retry, :block) do
21
+ def inspect
22
+ "#<struct #{self.class.name} tag=%d, opts=%s, retry=%d, &block=%s event.event_type_name=%s>" % [tag, opts.inspect, send(:retry), block.inspect, event.event_type_name.inspect]
23
+ end
24
+ end
25
+
22
26
  private_constant :PendingEvent
23
27
 
24
28
  # This is to accumulate a set of exceptions happend at a series of executions.
@@ -53,6 +57,8 @@ class Tengine::Mq::Suite
53
57
  end
54
58
  private_constant :ExceptionsContainer
55
59
 
60
+ autoload :DEFAULT_CONFIG, "tengine/mq/suite/default_config"
61
+
56
62
  # Some (not all) of the descriptions below are quoted from the AMQP gem's yardoc.
57
63
  #
58
64
  # @param [Hash] cfg Tons of optional arguments can be specified and they are settings for
@@ -181,53 +187,7 @@ class Tengine::Mq::Suite
181
187
  @retrying_events = Hash.new
182
188
  @pending_events = Hash.new
183
189
  @hooks = Hash.new do |h, k| h.store k, Array.new end
184
- @config = {
185
- :sender => {
186
- :keep_connection => false,
187
- :retry_interval => 1, # in seconds
188
- :retry_count => 30,
189
- },
190
- :connection => {
191
- :user => 'guest',
192
- :pass => 'guest',
193
- :vhost => '/',
194
- :logging => false,
195
- :insist => false,
196
- :host => 'localhost',
197
- :port => 5672,
198
- :auto_reconnect_delay => 1, # in seconds
199
- },
200
- :channel => {
201
- :prefetch => 1,
202
- :auto_recovery => true,
203
- },
204
- :exchange => {
205
- :name => 'tengine_event_exchange',
206
- :type => :direct,
207
- :passive => false,
208
- :durable => true,
209
- :auto_delete => false,
210
- :internal => false,
211
- :nowait => false,
212
- :publish => {
213
- :content_type => "application/json", # RFC4627
214
- :persistent => true,
215
- },
216
- },
217
- :queue => {
218
- :name => 'tengine_event_queue',
219
- :passive => false,
220
- :durable => true,
221
- :auto_delete => false,
222
- :exclusive => false,
223
- :nowait => false,
224
- :subscribe => {
225
- :ack => true,
226
- :nowait => false,
227
- :confirm => nil,
228
- },
229
- },
230
- }
190
+ @config = DEFAULT_CONFIG.deep_dup
231
191
  @config.deep_merge! cfg.to_hash.deep_symbolize_keys.compact
232
192
  @config.deep_freeze
233
193
  install_default_hooks
@@ -270,6 +230,7 @@ class Tengine::Mq::Suite
270
230
  raise ArgumentError, "no block given" unless block_given?
271
231
  ensures :queue do |q|
272
232
  opts = @config[:queue][:subscribe].merge cfg.compact
233
+ logger :debug, "start subscribe(#{opts.inspect})"
273
234
  q.subscribe opts do |h, b|
274
235
  yield h, b
275
236
  end
@@ -333,7 +294,10 @@ class Tengine::Mq::Suite
333
294
  # べつに何も難しいことがしたいわけではなくて最終的にp0を呼べばいいんだけど、EMがいるかいないか、@connectionがいるかいないかの条件分
334
295
  # けで無駄に長いメソッドになっている。
335
296
 
297
+ logger :debug, "#{self.class.name}#stop " << ("#" * 30)
298
+
336
299
  p0 = lambda do
300
+ logger :debug, "#{self.class.name}#stop p0"
337
301
  EM.cancel_timer @reconnection_timer if ivar? :reconnection_timer
338
302
  @retrying_events.each_value do |(idx, *)|
339
303
  EM.cancel_timer idx if idx
@@ -342,6 +306,7 @@ class Tengine::Mq::Suite
342
306
  stop_firing_queue
343
307
 
344
308
  @state = :uninitialized # この後またEM.run{ .. }されるかも
309
+ logger :debug, "#{self.class.name}#stop #{__LINE__} @state: #{@state.inspect}"
345
310
  @setting_up.clear
346
311
  @firing_queue = EM::Queue.new
347
312
  @connection = nil
@@ -360,6 +325,7 @@ class Tengine::Mq::Suite
360
325
  end
361
326
 
362
327
  p1 = lambda do
328
+ logger :debug, "#{self.class.name}#stop p1"
363
329
  if ivar? :connection
364
330
  @connection.disconnect do
365
331
  synchronize do
@@ -372,6 +338,7 @@ class Tengine::Mq::Suite
372
338
  end
373
339
 
374
340
  p2 = lambda do
341
+ logger :debug, "#{self.class.name}#stop p2"
375
342
  if ivar? :channel
376
343
  @channel.close do
377
344
  synchronize do
@@ -384,6 +351,7 @@ class Tengine::Mq::Suite
384
351
  end
385
352
 
386
353
  p3 = lambda do
354
+ logger :debug, "#{self.class.name}#stop p3"
387
355
  if ivar? :queue and @queue.default_consumer
388
356
  @queue.unsubscribe :nowait => false do
389
357
  synchronize do
@@ -396,13 +364,19 @@ class Tengine::Mq::Suite
396
364
  end
397
365
 
398
366
  p4 = lambda do
367
+ logger :debug, "#{self.class.name}#stop p4"
399
368
  synchronize do
400
369
  logger :info, "finishing up, now sending remaining events."
401
- @condvar.wait @mutex until @pending_events.empty?
370
+ until @pending_events.empty?
371
+ logger :debug, "@condvar.wait @mutex until @pending_events.empty?" << ('?' * 50)
372
+ @condvar.wait @mutex
373
+ logger :debug, "@condvar.wait @mutex done " << ('!' * 50)
374
+ end
402
375
  end
403
376
  end
404
377
 
405
378
  p5 = lambda do |a|
379
+ logger :debug, "#{self.class.name}#stop p5"
406
380
  synchronize do
407
381
  p3.call
408
382
  end
@@ -500,7 +474,9 @@ class Tengine::Mq::Suite
500
474
  # recursive locking happens.
501
475
  def synchronize
502
476
  begin
477
+ logger :debug, "GETTING LOCK mutex" << ('?' * 50)
503
478
  @mutex.lock
479
+ logger :debug, "GOT LOCK mutex" << ('!' * 50)
504
480
  rescue ThreadError => e
505
481
  # A deadlock was detected, which means of course, we have the lock.
506
482
  bt = e.backtrace.join "\n\tfrom "
@@ -511,11 +487,12 @@ class Tengine::Mq::Suite
511
487
  ensure
512
488
  begin
513
489
  @mutex.unlock
490
+ logger :debug, "RELEASE LOCK mutex" << ('-' * 50)
514
491
  rescue ThreadError => e
515
492
  # @mutex might magically be unlocked... For instance, the execution context might have been splitted from inside of the
516
493
  # yielded block. That case, the context who reached here do not own @mutex so should not unlock.
517
494
  bt = e.backtrace.join "\n\tfrom "
518
- logger :debug, "%s\n¥tfrom %s\n", e, bt
495
+ logger :warn, "%s\n¥tfrom %s\n", e, bt
519
496
  end
520
497
  end
521
498
  end
@@ -581,31 +558,50 @@ class Tengine::Mq::Suite
581
558
  end
582
559
  end
583
560
 
584
- # @yields [obj] yields generated object
585
- def ensures klass
586
- raise "eventmachine's reactor needed" unless EM.reactor_running?
587
- # このメソッドはEM.deferでklassの初期化を待つ。EM.deferだから戻り値を使ってはいけない。引数のブロックは、klassが初期化されたことが確
588
- # 認された後にcallされる。
589
- p1 = lambda do
561
+ def ensures_waiting_block(klass)
562
+ logger :debug, "#{self.class.name}#ensures_waiting_block(#{klass.inspect}) #{__LINE__}"
563
+ lambda do
564
+ logger :debug, "#{self.class.name}#ensures_waiting_block(#{klass.inspect}) p1 #{__LINE__}"
590
565
  synchronize do
591
566
  unless ivar? klass
567
+ logger :debug, "#{@setting_up.inspect}"
592
568
  setups klass unless @setting_up[klass]
593
- @condvar.wait @mutex until ivar? klass
569
+ until ivar? klass
570
+ logger :debug, "@condvar.wait @mutex until ivar? klass " << ('?' * 50)
571
+ @condvar.wait @mutex
572
+ logger :debug, "@condvar.wait @mutex done " << ('!' * 50)
573
+ end
574
+ logger :debug, "#{self.class.name}#ensures_waiting_block(#{klass.inspect}) p1 #{__LINE__}"
594
575
  end
576
+ logger :debug, "#{self.class.name}#ensures_waiting_block(#{klass.inspect}) p1 #{__LINE__}"
595
577
  end
578
+ logger :debug, "#{self.class.name}#ensures_waiting_block(#{klass.inspect}) p1 #{__LINE__}"
596
579
  end
580
+ end
581
+
582
+ # @yields [obj] yields generated object
583
+ def ensures klass
584
+ logger :debug, "#ensures(#{klass.inspect}) " << ("#" * 30)
585
+ raise "eventmachine's reactor needed" unless EM.reactor_running?
586
+ # このメソッドはEM.deferでklassの初期化を待つ。EM.deferだから戻り値を使ってはいけない。引数のブロックは、klassが初期化されたことが確
587
+ # 認された後にcallされる。
588
+ p1 = ensures_waiting_block(klass)
597
589
  p2 = lambda do |a|
590
+ logger :debug, "#{self.class.name}#ensures(#{klass.inspect}) p2"
598
591
  obj = ivar? klass
599
592
  yield obj if block_given?
600
593
  end
594
+ logger :debug, "#{self.class.name}#ensures(#{klass.inspect}) #{__LINE__}"
601
595
  EM.defer p1, p2
602
596
  end
603
597
 
604
598
  def generate_connection cb
605
599
  cfg = cb.merge @config[:connection] do |k, v1, v2| v2 end
600
+ logger :debug, "AMQP.connect(#{cfg.inspect})"
606
601
  AMQP.connect cfg do |conn|
607
602
  synchronize do
608
603
  @state = :connected
604
+ logger :debug, "#{self.class.name}#generate_connection #{__LINE__} @state: #{@state.inspect}"
609
605
  end
610
606
  yield conn
611
607
  end
@@ -619,6 +615,7 @@ class Tengine::Mq::Suite
619
615
  cfg = @config[:channel]
620
616
  ensures :connection do |conn|
621
617
  id = AMQP::Channel.next_channel_id
618
+ logger :debug, "AMQP::Channel.new(conn, #{id.inspect}, #{cfg.inspect})"
622
619
  AMQP::Channel.new conn, id, cfg do |ch|
623
620
  yield ch
624
621
  end
@@ -649,6 +646,7 @@ class Tengine::Mq::Suite
649
646
  type = cfg.delete :type
650
647
  cfg.delete :publish # not needed here
651
648
  ensures :channel do |ch|
649
+ logger :debug, "AMQP::Exchange.new(ch, #{type.intern.inspect}, #{name.inspect}, #{cfg.inspect})"
652
650
  if cfg[:nowait]
653
651
  xchg = AMQP::Exchange.new ch, type.intern, name, cfg
654
652
  yield xchg
@@ -722,16 +720,19 @@ class Tengine::Mq::Suite
722
720
 
723
721
  synchronize do
724
722
  instance_variable_set "@#{klass}", obj
723
+ logger :debug, "before @condvar.broadcast" << ('-' * 50)
725
724
  @condvar.broadcast
725
+ logger :debug, " after @condvar.broadcast"
726
726
  end
727
727
  end
728
728
  end
729
729
 
730
730
  #######
731
731
 
732
- def ensures_handshake
732
+ def ensures_handshake(*extra_waitings)
733
733
  raise ArgumentError, "no block given" unless block_given?
734
734
  raise "eventmachine's reactor needed" unless EM.reactor_running?
735
+ logger :debug, "#{self.class.name}##ensures_handshake @state: #{@state.inspect} " << ("#" * 30)
735
736
  case @state when :established, :unsupported
736
737
  EM.next_tick do yield end
737
738
  else
@@ -741,27 +742,43 @@ class Tengine::Mq::Suite
741
742
  logger :info, "waiting for MQ to be set up (now %s)...", @state
742
743
 
743
744
  d4 = lambda do |a|
745
+ logger :debug, "#{self.class.name}#ensures_handshake d4"
744
746
  yield
745
747
  end
746
748
  d3 = lambda do
749
+ logger :debug, "#{self.class.name}#ensures_handshake d3"
747
750
  synchronize do
748
751
  unless ensures_handshake_internal
749
752
  setups_handshake unless @setting_up[:handshake]
750
- # @condvar.wait @mutex until ensures_handshake_internal
751
- @mutex.sleep 0.1 until ensures_handshake_internal
753
+ until ensures_handshake_internal
754
+ logger :debug, "@mutex.sleep 0.1 until ensures_handshake_internal " << ('?' * 50)
755
+ # @condvar.wait @mutex
756
+ @mutex.sleep 0.1
757
+ logger :debug, "@mutex.sleep 0.1 done " << ('!' * 50)
758
+ end
752
759
  end
753
760
  end
761
+ extra_waitings.each(&:call)
754
762
  end
763
+
755
764
  d2 = lambda do |a|
765
+ logger :debug, "#{self.class.name}#ensures_handshake d2"
756
766
  EM.defer d3, d4
757
767
  end
768
+
758
769
  d1 = lambda do
770
+ logger :debug, "#{self.class.name}#ensures_handshake d1"
759
771
  synchronize do
760
772
  ensures :channel
761
- @condvar.wait @mutex until ivar? :channel
773
+ until ivar? :channel
774
+ logger :debug, "@condvar.wait @mutex until ivar? :channel" << ('?' * 50)
775
+ @condvar.wait @mutex
776
+ logger :debug, "@condvar.wait @mutex done " << ('!' * 50)
777
+ end
762
778
  end
763
779
  end
764
780
  d0 = lambda do
781
+ logger :debug, "#{self.class.name}#ensures_handshake d0"
765
782
  EM.defer d1, d2
766
783
  end
767
784
  d0.call
@@ -769,6 +786,7 @@ class Tengine::Mq::Suite
769
786
  end
770
787
 
771
788
  def ensures_handshake_internal
789
+ logger :debug, "#{self.class.name}#ensures_handshake_internal @state: #{@state.inspect}"
772
790
  case @state when :established, :unsupported
773
791
  true
774
792
  else
@@ -787,24 +805,35 @@ class Tengine::Mq::Suite
787
805
  # :established --- proper handshake was made
788
806
  # :unsupported --- peer rejected handshake, but the connection itself is OK.
789
807
  cap = @connection.server_capabilities
808
+
809
+ logger :debug, "#{self.class.name}#setups_handshake cap: #{cap.inspect}"
810
+
790
811
  if cap and cap["publisher_confirms"] then
791
812
  @state = :handshaking
813
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__} @state: #{@state.inspect}"
792
814
  @channel.confirm_select do
793
815
  # this is in next EM loop...
816
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__}"
794
817
  synchronize do
818
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__}"
795
819
  reinvoke_retry_timers unless @retrying_events.empty?
796
820
  @channel.on_ack do |ack|
797
821
  # this is in another EM loop...
798
- consume_basic_ack ack
822
+ consume_basic_ack ack
799
823
  end
800
- @channel.on_nack do |ack|
824
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__}"
825
+ @channel.on_nack do |nack|
801
826
  # this is in yet another EM loop...
802
- consume_basic_nack ack
827
+ consume_basic_nack nack
803
828
  end
829
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__}"
804
830
  @tag = 0
805
831
  @state = :established
832
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__} @state: #{@state.inspect}"
806
833
  @setting_up.delete :handshake
834
+ logger :debug, "before @condvar.broadcast" << ('-' * 50)
807
835
  @condvar.broadcast
836
+ logger :debug, " after @condvar.broadcast"
808
837
  end
809
838
  end
810
839
  else
@@ -817,8 +846,11 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
817
846
 
818
847
  end
819
848
  @state = :unsupported
849
+ logger :debug, "#{self.class.name}#setups_handshake #{__LINE__} @state: #{@state.inspect}"
820
850
  @setting_up.delete :handshake
851
+ logger :debug, "before @condvar.broadcast" << ('-' * 50)
821
852
  @condvar.broadcast
853
+ logger :debug, " after @condvar.broadcast"
822
854
  end
823
855
  end
824
856
 
@@ -858,7 +890,9 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
858
890
  @retrying_events.delete e
859
891
  @pending_events.delete e
860
892
  end
893
+ logger :debug, "before @condvar.broadcast" << ('-' * 50)
861
894
  @condvar.broadcast
895
+ logger :debug, " after @condvar.broadcast"
862
896
  f = ok.inject f do |r, e| r | e.opts[:keep_connection] end
863
897
  end
864
898
  # 帰ってきたackが最後のackで、もう待ちがなくて、かつackに対応するイベントがすべてkeep_connection: falseで送信されていた場合、もう
@@ -895,9 +929,11 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
895
929
  #######
896
930
 
897
931
  def revoke_retry_timers
932
+ logger :debug, "#{self.class.name}#revoke_retry_timers"
898
933
  synchronize do
899
934
  if @state != :disconnected
900
935
  @state = :disconnected
936
+ logger :debug, "#{self.class.name}#revoke_retry_timers #{__LINE__} @state: #{@state.inspect}"
901
937
  @retrying_events.each_value do |(idx, *)|
902
938
  EM.cancel_timer idx if idx
903
939
  end
@@ -911,6 +947,7 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
911
947
  end
912
948
 
913
949
  def reinvoke_retry_timers
950
+ logger :debug, "#{self.class.name}#reinvoke_retry_timers"
914
951
  synchronize do
915
952
  @retrying_events.each_pair.to_a.each_next_tick do |i, (j, k)|
916
953
  u = (k + (i.opts[:retry_interval] || 0)) - Time.now
@@ -980,13 +1017,16 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
980
1017
  ch.prefetch @config[:channel][:prefetch] do
981
1018
  @setting_up.delete :handshake # re-initialize
982
1019
  reinvoke_retry_timers
1020
+ logger :debug, "before @condvar.broadcast" << ('-' * 50)
983
1021
  @condvar.broadcast
1022
+ logger :debug, " after @condvar.broadcast"
984
1023
  end
985
1024
  end
986
1025
 
987
1026
  add_hook :'connection.after_recovery' do |conn|
988
1027
  synchronize do
989
1028
  @state = :connected
1029
+ logger :debug, "#{self.class.name}#install_default_hooks #{__LINE__} @state: #{@state.inspect}"
990
1030
  end
991
1031
  end
992
1032
  end
@@ -1012,23 +1052,23 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
1012
1052
  @firing_queue.push ev
1013
1053
  end
1014
1054
  end
1055
+ @gencb
1015
1056
  end
1016
1057
 
1017
1058
  def trigger_firing_thread
1018
1059
  # inside mutex
1019
1060
  # event already pushed
1020
- ensures_handshake do
1021
- ensures :exchange do
1061
+ ensures_handshake(ensures_waiting_block(:exchange)) do
1022
1062
  synchronize do
1023
1063
  @firing_queue.pop(&gencb)
1024
1064
  end
1025
- end
1026
1065
  end
1027
1066
  end
1028
1067
 
1029
1068
  def fire_internal ev
1030
1069
  publish ev
1031
1070
  rescue Exception => ex
1071
+ logger :warn, "#{self.class.name}#fire_internal [#{ex.class}] #{ex.message}"
1032
1072
  # exchange.publish はたとえば RuntimeError を raise したりするようだ
1033
1073
  publish_failed ev, ex
1034
1074
  else
@@ -1036,10 +1076,12 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
1036
1076
  end
1037
1077
 
1038
1078
  def publish ev
1079
+ logger :debug, "#{self.class.name}#publish(#{ev.inspect})"
1039
1080
  @exchange.publish ev.event.to_json, @config[:exchange][:publish]
1040
1081
  end
1041
1082
 
1042
1083
  def publish_failed ev, ex
1084
+ logger :debug, "#{self.class.name}#publish_failed(#{ev.inspect}, #{ex.inspect})"
1043
1085
  if resendable_p ev
1044
1086
  idx = EM.add_timer ev.opts[:retry_interval] do
1045
1087
  synchronize do
@@ -1054,7 +1096,9 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
1054
1096
  @retrying_events.delete ev
1055
1097
  @pending_events.delete ev
1056
1098
  @publishing_events.reject! {|i| i == ev }
1099
+ logger :debug, "before @condvar.broadcast" << ('-' * 50)
1057
1100
  @condvar.broadcast
1101
+ logger :debug, " after @condvar.broadcast"
1058
1102
  logger :fatal, "SEND FAILED: EVENT LOST %p", ev.event
1059
1103
  stop unless ev.opts[:keep_connection] # 送信失敗かつコネクション維持しないということはここで停止すべき
1060
1104
  end
@@ -1067,6 +1111,7 @@ you to use a relatively recent version of RabbitMQ. [BEWARE!]
1067
1111
  end
1068
1112
 
1069
1113
  def published ev
1114
+ logger :debug, "#{self.class.name}#published(#{ev.inspect})"
1070
1115
  case @state
1071
1116
  when :unsupported then
1072
1117
  # ackなし、next_tickをもって送信終了と見なす