Module: OnStomp::Failover::FailoverEvents

Includes:
Interfaces::EventManager
Included in:
Client
Defined in:
lib/onstomp/failover/failover_events.rb

Overview

Events mixin for failover clients.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interfaces::EventManager

#bind_event, #event_callbacks, included, #trigger_event

Class Method Details

.create_client_event_method(name) ⇒ Object

Creates a forwarded binding for client events.



11
12
13
# File 'lib/onstomp/failover/failover_events.rb', line 11

def create_client_event_method name
  module_eval "def #{name}(&block); bind_client_event(:#{name}, block); end"
end

Instance Method Details

#bind_client_event(name, block) ⇒ Object

Sets up a forwarded event binding, applying it to all clients in Client#client_pool.



48
49
50
51
52
53
54
55
56
# File 'lib/onstomp/failover/failover_events.rb', line 48

def bind_client_event(name, block)
  client_pool.each do |client|
    client.__send__ name do |*args|
      if client == active_client
        block.call *args
      end
    end
  end
end

#on_connection_closed(&block) ⇒ Object

Binds a callback to Client#on_connection_closed. This has to be handled directly because :on_connection_closed isn’t a true event.



42
43
44
# File 'lib/onstomp/failover/failover_events.rb', line 42

def on_connection_closed &block
  bind_client_event(:on_connection_closed, block)
end

#on_connection_died(&block) ⇒ Object

Binds a callback to Client#on_connection_died. This has to be handled directly because :on_connection_died isn’t a true event.



30
31
32
# File 'lib/onstomp/failover/failover_events.rb', line 30

def on_connection_died &block
  bind_client_event(:on_connection_died, block)
end

#on_connection_established(&block) ⇒ Object

Binds a callback to Client#on_connction_established. This has to be handled directly because :on_connection_established isn’t a true event.



24
25
26
# File 'lib/onstomp/failover/failover_events.rb', line 24

def on_connection_established &block
  bind_client_event(:on_connection_established, block)
end

#on_connection_terminated(&block) ⇒ Object

Binds a callback to Client#on_connection_terminated. This has to be handled directly because :on_connection_terminated isn’t a true event.



36
37
38
# File 'lib/onstomp/failover/failover_events.rb', line 36

def on_connection_terminated &block
  bind_client_event(:on_connection_terminated, block)
end

#trigger_failover_event(ev, pref, *args) ⇒ Object

Triggers a general failover event



93
94
95
# File 'lib/onstomp/failover/failover_events.rb', line 93

def trigger_failover_event ev, pref, *args
  trigger_event :"#{pref}_failover_#{ev}", self, *args
end

#trigger_failover_retry(pref, attempt) ⇒ Object

Triggers a failover retry event



88
89
90
# File 'lib/onstomp/failover/failover_events.rb', line 88

def trigger_failover_retry pref, attempt
  trigger_failover_event :retry, pref, attempt, self.active_client
end