Class: RedisRing::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_ring/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Application

Returns a new instance of Application.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/redis_ring/application.rb', line 7

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.cluster_name,
                                                  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

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def configuration
  @configuration
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def http_client
  @http_client
end

#masterObject (readonly)

Returns the value of attribute master.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def master
  @master
end

#master_rpcObject (readonly)

Returns the value of attribute master_rpc.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def master_rpc
  @master_rpc
end

#node_providerObject (readonly)

Returns the value of attribute node_provider.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def node_provider
  @node_provider
end

#process_managerObject (readonly)

Returns the value of attribute process_manager.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def process_manager
  @process_manager
end

#shardsObject (readonly)

Returns the value of attribute shards.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def shards
  @shards
end

#slaveObject (readonly)

Returns the value of attribute slave.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def slave
  @slave
end

#slave_rpcObject (readonly)

Returns the value of attribute slave_rpc.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def slave_rpc
  @slave_rpc
end

#zookeeper_connectionObject (readonly)

Returns the value of attribute zookeeper_connection.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def zookeeper_connection
  @zookeeper_connection
end

#zookeeper_observerObject (readonly)

Returns the value of attribute zookeeper_observer.



5
6
7
# File 'lib/redis_ring/application.rb', line 5

def zookeeper_observer
  @zookeeper_observer
end

Instance Method Details

#startObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redis_ring/application.rb', line 24

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

#stopObject



46
47
48
49
50
# File 'lib/redis_ring/application.rb', line 46

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

#waitObject



40
41
42
43
44
# File 'lib/redis_ring/application.rb', line 40

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