Sha256: 649c7ebce09f75dd275474d3523092951892393eef2e08d56cc2acbf0e2ee040

Contents?: true

Size: 1.87 KB

Versions: 65

Compression:

Stored size: 1.87 KB

Contents

module Elasticsearch
  module Transport
    module Transport
      module Connections
        module Selector

          # @abstract Common functionality for connection selector implementations.
          #
          module Base
            attr_reader :connections

            # @option arguments [Connections::Collection] :connections Collection with connections.
            #
            def initialize(arguments={})
              @connections = arguments[:connections]
            end

            # @abstract Selector strategies implement this method to
            #           select and return a connection from the pool.
            #
            # @return [Connection]
            #
            def select(options={})
              raise NoMethodError, "Implement this method in the selector implementation."
            end
          end

          # "Random connection" selector strategy.
          #
          class Random
            include Base

            # Returns a random connection from the collection.
            #
            # @return [Connections::Connection]
            #
            def select(options={})
              connections.to_a.send( defined?(RUBY_VERSION) && RUBY_VERSION > '1.9' ? :sample : :choice)
            end
          end

          # "Round-robin" selector strategy (default).
          #
          class RoundRobin
            include Base

            # Returns the next connection from the collection, rotating them in round-robin fashion.
            #
            # @return [Connections::Connection]
            #
            def select(options={})
              # On Ruby 1.9, Array#rotate could be used instead
              @current = !defined?(@current) || @current.nil? ? 0 : @current+1
              @current = 0 if @current >= connections.size
              connections[@current]
            end
          end

        end
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 6 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.8.1 lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.8.0 lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.3.1 lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.3.0 lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.2.0 lib/elasticsearch/transport/transport/connections/selector.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.1.0 lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-6.0.3 lib/elasticsearch/transport/transport/connections/selector.rb
elasticsearch-transport-5.0.5 lib/elasticsearch/transport/transport/connections/selector.rb