Class: OnStomp::Failover::Pools::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/onstomp/failover/pools/base.rb

Overview

An abstract pool of clients. This class manages the shared behaviors of client pools, but has no means of picking successive clients. Subclasses must define next_client or pool will not function.

Direct Known Subclasses

RoundRobin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uris) ⇒ Base

Creates a new client pool by mapping an array of URIs into an array of clients.



11
12
13
14
15
# File 'lib/onstomp/failover/pools/base.rb', line 11

def initialize uris
  @clients = uris.map do |u|
    OnStomp::Client.new u
  end
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



7
8
9
# File 'lib/onstomp/failover/pools/base.rb', line 7

def clients
  @clients
end

Instance Method Details

#each {|client| ... } ⇒ self

Yields each client in the pool to the supplied block. Raises an error if no block is provided.

Yields:

  • (client)

    block to call for each client in the pool

Yield Parameters:

Returns:

  • (self)

Raises:

  • (ArgumentError)

    if no block is given



34
35
36
37
38
# File 'lib/onstomp/failover/pools/base.rb', line 34

def each &block
  raise ArgumentError, 'no block provided' unless block_given?
  clients.each &block
  self
end

#next_clientObject

Raises an error, because it is up to subclasses to define this behavior.

Raises:

  • (StandardError)


19
20
21
# File 'lib/onstomp/failover/pools/base.rb', line 19

def next_client
  raise 'implemented in subclasses'
end

#shuffle!Object

Shuffles the client pool.



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

def shuffle!
  clients.shuffle!
end