Sha256: 730a84293339e57d8bc44dc0dafb706eef9f3ceb17eb75a95a6a96df245c292d

Contents?: true

Size: 532 Bytes

Versions: 18

Compression:

Stored size: 532 Bytes

Contents

module Dryad
  module Cluster
    class RoundRobin
      def initialize
        @index = Concurrent::AtomicFixnum.new
        @services = Concurrent::AtomicReference.new
      end

      def set_services(instances)
        @services.set(instances)
      end

      def service
        instances = @services.get()
        if instances.nil? || instances.empty?
          raise Dryad::Cluster::NoServicesError, "Round robin nodes are empty."
        end
        instances[@index.increment % instances.size]
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
dryad-cluster-1.1.0 lib/dryad/cluster/round_robin.rb
dryad-cluster-1.0.1 lib/dryad/cluster/round_robin.rb
dryad-cluster-1.0.0 lib/dryad/cluster/round_robin.rb
dryad-cluster-0.3.4 lib/dryad/cluster/round_robin.rb
dryad-cluster-0.3.2 lib/dryad/cluster/round_robin.rb
dryad-cluster-0.3.0 lib/dryad/cluster/round_robin.rb
dryad-cluster-0.2.7 lib/dryad/cluster/round_robin.rb
dryad-cluster-0.2.6 lib/dryad/cluster/round_robin.rb
dryad-0.2.5 dryad-cluster/lib/dryad/cluster/round_robin.rb
dryad-cluster-0.2.5 lib/dryad/cluster/round_robin.rb
dryad-0.2.3 dryad-cluster/lib/dryad/cluster/round_robin.rb
dryad-cluster-0.2.3 lib/dryad/cluster/round_robin.rb
dryad-0.2.1 dryad-cluster/lib/dryad/cluster/round_robin.rb
dryad-cluster-0.2.1 lib/dryad/cluster/round_robin.rb
dryad-0.2.0 dryad-cluster/lib/dryad/cluster/round_robin.rb
dryad-cluster-0.2.0 lib/dryad/cluster/round_robin.rb
dryad-0.1.1 dryad-cluster/lib/dryad/cluster/round_robin.rb
dryad-cluster-0.1.1 lib/dryad/cluster/round_robin.rb