Sha256: 6aaaffa806062f0530011a73e56df17c00922bd4ce1d1d2f0a094cb2baca8a87

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

module RedisRing

  class Application

    attr_reader :shards, :configuration, :process_manager, :zookeeper_observer, :master, :slave, :zookeeper_connection, :master_rpc, :http_client, :node_provider, :slave_rpc

    def initialize(config)
      @configuration = config
      @process_manager = ProcessManager.new
      @http_client = HttpClient.new
      @master_rpc = MasterRPC.new(http_client)
      @slave_rpc = SlaveRPC.new(http_client)
      @node_provider = NodeProvider.new(slave_rpc)
      @zookeeper_connection = ZookeeperConnection.new(config.host_name,
                                                      config.base_port,
                                                      config.zookeeper_address)
      @master = Master.new(zookeeper_connection, config.ring_size, node_provider)
      @slave = Slave.new(configuration, master_rpc, process_manager)
      @zookeeper_observer = ZookeeperObserver.new(zookeeper_connection, master, slave)
      @web_interface_runner = WebInterfaceRunner.new(config.base_port, master, slave)
    end

    def start
      self.stop

      @web_thread = @web_interface_runner.run

      @zookeeper_connection.connect
      @slave.node_id = @zookeeper_connection.current_node

      @zookeeper_thread = @zookeeper_observer.run
      @pm_thread = @process_manager.run

      [:INT, :TERM, :QUIT].each do |sig|
        trap(sig) { self.stop }
      end
    end

    def wait
      @pm_thread.join if @pm_thread
      @zookeeper_thread.join if @zookeeper_thread
      @web_thread.join if @web_thread
    end

    def stop
      @process_manager.halt
      @zookeeper_observer.halt
      @web_interface_runner.halt
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redis_ring-0.1.1 lib/redis_ring/application.rb
redis_ring-0.1.0 lib/redis_ring/application.rb