Sha256: 77da04896c191836897299e419eff5422eb524b365d15623acd62342f5973b6b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module RedisRing

  class Application

    attr_reader :shards, :configuration, :process_manager

    def initialize(configuration)
      @configuration = configuration
      @process_manager = ProcessManager.new
      @shards = {}
    end

    def start
      self.stop

      @configuration.ring_size.times do |shard_number|
        shard_conf = ShardConfig.new(shard_number, configuration)
        @shards[shard_number] = Shard.new(shard_conf)
      end

      @shards.each do |shard_no, shard|
        @process_manager.start_shard(shard)
      end

      @process_manager.run
    end

    def stop
      @process_manager.halt

      @shards.each do |shard_no, shard|
        @process_manager.stop_shard(shard)
      end

      @shards = {}
    end

    def shards_hash
      shards_hash = {}
      shards.each do |shard_no, shard|
        shards_hash[shard_no] = { :host => shard.host, :port => shard.port, :status => shard.status }
      end

      return { :count => configuration.ring_size, :shards => shards_hash }
    end

    class << self
      attr_accessor :instance
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redis_ring-0.0.2 lib/redis_ring/application.rb