class MotherBrain::ConfigManager

Constants

UPDATE_MSG

Attributes

config[R]

@return [MB::Config]

reload_mutex[R]

@return [Mutex]

Public Class Methods

instance() click to toggle source

@raise [Celluloid::DeadActorError] if ConfigManager has not been started

@return [Celluloid::Actor(ConfigManager)]

# File lib/mb/config_manager.rb, line 7
def instance
  MB::Application[:config_manager] or raise Celluloid::DeadActorError, "config manager not running"
end
new(new_config) click to toggle source

@param [MB::Config] new_config

# File lib/mb/config_manager.rb, line 24
def initialize(new_config)
  log.debug { "Config Manager starting..." }
  @reload_mutex = Mutex.new
  @reloading    = false
  set_config(new_config)
end

Public Instance Methods

reload() click to toggle source

Reload the current configuration from disk

# File lib/mb/config_manager.rb, line 42
def reload
  reload_mutex.synchronize do
    unless reloading?
      @reloading = true
      update(config.reload)
    end
  end

  @reloading = false
end
reloading?() click to toggle source

Check if the config manager is already attempting to reload it’s configuration

@return [Boolean]

# File lib/mb/config_manager.rb, line 56
def reloading?
  @reloading
end
update(new_config) click to toggle source

Update the current configuration

@param [MB::Config] new_config

# File lib/mb/config_manager.rb, line 34
def update(new_config)
  set_config(new_config)

  MB.log.info "[ConfigManager] Configuration has changed: notifying subscribers..."
  publish(UPDATE_MSG, self.config)
end

Private Instance Methods

finalize_callback() click to toggle source
# File lib/mb/config_manager.rb, line 65
def finalize_callback
  log.debug { "Config Manager stopping..." }
end
set_config(new_config) click to toggle source

@param [MB::Config] new_config

# File lib/mb/config_manager.rb, line 70
def set_config(new_config)
  new_config.validate!
  @config = new_config
end