Class: Messagebus::ClusterMap

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/messagebus/cluster_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

#valid_host?, #validate_connection_config, #validate_destination_config

Constructor Details

#initialize(config) ⇒ ClusterMap

Returns a new instance of ClusterMap.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/messagebus/cluster_map.rb', line 38

def initialize(config)
  config = DottableHash.new(config)
  Messagebus::Client.logger.debug { "Initializing ClusterMap with config: #{config.inspect}" }

  if clusters = config.clusters
    config.clusters.each do |cluster_config|
      # Merge cluster config with top level config.
      # cluster level values should override top level values.
      cluster = config.merge(cluster_config)
      create_cluster(cluster)
    end
  end
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



35
36
37
# File 'lib/messagebus/cluster_map.rb', line 35

def address
  @address
end

#destinationsObject (readonly)

Returns the value of attribute destinations.



35
36
37
# File 'lib/messagebus/cluster_map.rb', line 35

def destinations
  @destinations
end

Instance Method Details

#find(destination_name) ⇒ Object



70
71
72
# File 'lib/messagebus/cluster_map.rb', line 70

def find(destination_name)
  destinations[destination_name]
end

#startObject



52
53
54
55
56
57
# File 'lib/messagebus/cluster_map.rb', line 52

def start
  cluster_producer_map.each do |cluster_name, producer|
    Messagebus::Client.logger.info "Starting producer for cluster: #{cluster_name} with host_params: #{producer.host_params}"
    producer.start
  end
end

#stopObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/messagebus/cluster_map.rb', line 59

def stop
  cluster_producer_map.each do |cluster_name, producer|
    Messagebus::Client.logger.info "Stopping producer for cluster: #{cluster_name} with host_params: #{producer.host_params}"
    if producer.started?
      producer.stop
    else
      Messagebus::Client.logger.warn "#{producer.host_params} was not active, ignoring stop request."
    end
  end
end

#update_config(config) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/messagebus/cluster_map.rb', line 78

def update_config(config)
  Messagebus::Client.logger.debug { "Reloading ClusterMap with config: #{config.inspect}" }
  config = DottableHash.new(config)
  if clusters = config.clusters
    config.clusters.each do |cluster_config|
      cluster = config.merge(cluster_config)
      #cluster exists - check and update configs
      if cluster_producer_map.has_key?(cluster.name)
        #check for prodcuer config
        update_cluster(cluster)
      else
        #new cluster => create it
        create_cluster(cluster, true)
      end
    end
  end
end