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

+ (Object) create_client_event_method(name)

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

- (Object) after_failover_retry {|failover, attempt, client| ... }

Binds a callback to be invoked when a failover client is attempting to connect through a new client in its Client#pool.

Yields:

  • (failover, attempt, client)

    callback invoked when event is triggered

Yield Parameters:



65
# File 'lib/onstomp/failover/failover_events.rb', line 65

create_event_methods :failover_retry, :before, :after

- (Object) before_failover_retry {|failover, attempt, client| ... }

Binds a callback to be invoked when a failover client is attempting to connect through a new client in its Client#pool.

Yields:

  • (failover, attempt, client)

    callback invoked when event is triggered

Yield Parameters:



65
# File 'lib/onstomp/failover/failover_events.rb', line 65

create_event_methods :failover_retry, :before, :after

- (Object) bind_client_event(name, block)

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

- (Object) failover_connect_failure {|failover, client, error_message| ... }

Binds a callback to be invoked when a failover client fails to establish a connection through a client while reconnecting.

Yields:

  • (failover, client, error_message)

    callback invoked when event is triggered

Yield Parameters:



72
# File 'lib/onstomp/failover/failover_events.rb', line 72

create_event_methods :failover_connect_failure, :on

- (Object) failover_connected {|failover, client| ... }

Binds a callback to be invoked when a connection through a client is established.

Yields:

  • (failover, client)

    callback invoked when event is triggered

Yield Parameters:



85
# File 'lib/onstomp/failover/failover_events.rb', line 85

create_event_methods :failover_connected, :on

- (Object) failover_lost {|failover, client| ... }

create_event_methods :failover_retries_exceeded, :on Binds a callback to be invoked when an established connection through a client is lost.

Yields:

  • (failover, client)

    callback invoked when event is triggered

Yield Parameters:



79
# File 'lib/onstomp/failover/failover_events.rb', line 79

create_event_methods :failover_lost, :on

- (Object) failover_retries_exceeded {|failover| ... }

Binds a callback to be invoked when the maximum retries has been exceeded.

Yields:

  • (failover)

    callback invoked when event is triggered

Yield Parameters:



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

create_event_methods :failover_retries_exceeded, :on

- (Object) failover_retry {|failover, attempt, client| ... }

Binds a callback to be invoked when a failover client is attempting to connect through a new client in its Client#pool.

Yields:

  • (failover, attempt, client)

    callback invoked when event is triggered

Yield Parameters:



65
# File 'lib/onstomp/failover/failover_events.rb', line 65

create_event_methods :failover_retry, :before, :after

- (Object) on_connection_closed(&block)

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

- (Object) on_connection_died(&block)

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

- (Object) on_connection_established(&block)

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

- (Object) on_connection_terminated(&block)

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

- (Object) on_failover_connect_failure {|failover, client, error_message| ... }

Binds a callback to be invoked when a failover client fails to establish a connection through a client while reconnecting.

Yields:

  • (failover, client, error_message)

    callback invoked when event is triggered

Yield Parameters:



72
# File 'lib/onstomp/failover/failover_events.rb', line 72

create_event_methods :failover_connect_failure, :on

- (Object) on_failover_connected {|failover, client| ... }

Binds a callback to be invoked when a connection through a client is established.

Yields:

  • (failover, client)

    callback invoked when event is triggered

Yield Parameters:



85
# File 'lib/onstomp/failover/failover_events.rb', line 85

create_event_methods :failover_connected, :on

- (Object) on_failover_lost {|failover, client| ... }

create_event_methods :failover_retries_exceeded, :on Binds a callback to be invoked when an established connection through a client is lost.

Yields:

  • (failover, client)

    callback invoked when event is triggered

Yield Parameters:



79
# File 'lib/onstomp/failover/failover_events.rb', line 79

create_event_methods :failover_lost, :on

- (Object) on_failover_retries_exceeded {|failover| ... }

Binds a callback to be invoked when the maximum retries has been exceeded.

Yields:

  • (failover)

    callback invoked when event is triggered

Yield Parameters:



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

create_event_methods :failover_retries_exceeded, :on

- (Object) trigger_failover_event(ev, pref, *args)

Triggers a general failover event



98
99
100
# File 'lib/onstomp/failover/failover_events.rb', line 98

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

- (Object) trigger_failover_retry(pref, attempt)

Triggers a failover retry event



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

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