Load all reactors into an object that can be injected
@returns {{}}
172579
function loadReactors() {
        var reactors = {};
        var reactorsDir = path.join(this.injector.rootDir, this.injector.servicesDir + '/reactors');

        if (!fs.existsSync(reactorsDir)) {
            return reactors;
        }

        var me = this;
        var reactorNames = fs.readdirSync(reactorsDir);

        _.each(reactorNames, function (reactorName) {
            reactorName = reactorName.substring(0, reactorName.length - 3);
            reactors[reactorName] = me.injector.loadModule(utils.getCamelCase(reactorName));
        });

        // add the reactors that come from plugins to the list
        _.extend(reactors, this.injector.reactors);

        return reactors;
    }
1183438
function initReactors(container) {
        var isBatch = container === 'batch';

        // loop through each reactor and call init if it exists
        _.each(reactors, function (reactor) {
            if (reactor.init) {
                reactor.init({ config: config, pancakes: pancakes });
            }
        });

        // most reactors will be through the resource reactor definitions
        _.each(resources, function (resource) {                     // loop through all the resources
            _.each(resource.reactors, function (reactData) {        // loop through reactors
                if (isBatch && reactData.type === 'audit') {        // don't do anything if audit for batch
                    return;                                         // since audit not needed for batch
                }

                var eventTriggers = {                               // events that will trigger this propgation
                    resources:  [resource.name],
                    adapters:   reactData.trigger.adapters,
                    methods:    reactData.trigger.methods
                };

                // add the event handler
                eventBus.addHandlers(eventTriggers, reactHandler(reactData));
            });
        });
    }
379726
function initAdapters(container) {

        var calls = [];

        if (container === 'webserver') {
            _.each(adapters, function (adapter) {
                if (adapter.webInit) {
                    calls.push(adapter.webInit);
                }
            });
        }
        else {
            _.each(adapters, function (adapter) {
                if (adapter.init) {
                    calls.push(adapter.init);
                }
            });
        }

        return chainPromises(calls, config)
            .then(function (returnConfig) {
                if (returnConfig) {
                    return returnConfig;
                }
                else {
                    throw new Error('An adapter in the chain is not returning the config.');
                }
            });
    }
616077
function InternalObjectFactory(injector) {
    this.injector = injector;
    this.internalObjects = {
        resources: true,
        reactors: true,
        adapters: true,
        appConfigs: true,
        eventBus: eventBus,
        chainPromises: utils.chainPromises
    };
}
79088
function createLoader(handlers) {
  let _handlersType = t.nullable(t.object());

  t.param("handlers", _handlersType).assert(handlers);

  const handlerMap = new Map(Object.keys(handlers).map(key => [key, handlers[key]]));
  handlers = _handlersType.assert(undefined);

  return (state, data) => {
    const keys = Object.keys(data);
    return Promise.all(keys.map(key => {
      const handler = handlerMap.get(key);
      if (!handler) throw new Error(`Missing handler for "${key}".`);
      return handler(state, data[key]);
    })).then(results => {
      const data = Object.create(null);
      results.forEach((result, index) => {
        data[keys[index]] = result;
      });
      return data;
    });
  };
}
36560
function(object, callback) {
      return inject(object, [], function(selected, key, value){
        if (callIterator(callback, key, value))
          selected.push(value)
      })
    }
367843
function processCleanupData(cleanupData, options) {
        var fns = [];

        cleanupData.forEach(function (item) {
            var reactData = item.reactData;
            var reactor = reactors[reactData.type + '.reactor'];
            var req = _.extend({ resourceName: item.resource.name, reactData: reactData }, options);

            fns.push(function () {
                log.info('Cleanup source=' + item.resource.name +
                    ' reactor=' + reactData.type +
                    ' target=' + (reactData.target || reactData.parent || reactData.child || ''));

                return reactor && reactor.cleanup ? reactor.cleanup(req) : new Q();
            });
        });

        return chainPromises(fns, {});
    }
1300316
function loadEngines() {
  
  // Initialize engine properties
  this.enginesByExtension = {};
  
  // Engine local variables
  var exts = [];
  var loadedEngines = this.loadedEngines = Object.keys(protos.engines);
  
  if (loadedEngines.length > 0) {
    
    // Get view engines
    var engine, instance, engineProps = ['className', 'extensions'];
    for (engine in protos.engines) {
      instance = new protos.engines[engine]();
      instance.className = instance.constructor.name;
      protos.util.onlySetEnumerable(instance, engineProps);
      this.engines[engine] = instance;
    }

    // Register engine extensions
    for (var key in this.engines) {
      engine = this.engines[key];
      exts = exts.concat(engine.extensions);
      for (var i=0; i < engine.extensions.length; i++) {
        key = engine.extensions[i];
        this.enginesByExtension[key] = engine;
      }
    }
    
    // Set default view extension if not set
    if (typeof this.config.viewExtensions.html == 'undefined') {
      this.config.viewExtensions.html = 'ejs';
    }

    // Override engine extensions (from config)
    var ext, extOverrides = this.config.viewExtensions;
    
    for (ext in extOverrides) {
      if (exts.indexOf(ext) == -1) exts.push(ext); // Register extension on `exts`
      engine = this.engines[extOverrides[ext]]; // Get engine object
      if (engine) {
        engine.extensions.push(ext); // Add ext to engine extensions
        this.enginesByExtension[ext] = engine; // Override engine extension
      } else {
        this.debug(util.format("Ignoring '%s' extension: the '%s' engine is not loaded"), ext, extOverrides[ext]);
      }
    }

    // Set default template engine
    this.defaultEngine = (this.engines.ejs || this.engines[loadedEngines[0]]);

    // Add the engines regular expression
    this.engineRegex = new RegExp('^(' + Object.keys(this.engines).join('|').replace(/\-/, '\\-') + ')$');

  }
  
  // Generate template file regex from registered template extensions
  this.regex.templateFile = new RegExp('\\.(' + exts.join('|') + ')$');
  this.templateExtensions = exts;

  this.emit('engines_loaded', this.engines); // Emit regardless
  
}
530224
void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors) {
    List<BindingImpl<?>> candidateBindings = new ArrayList<>();
    @SuppressWarnings("unchecked") // casting Collection<Binding> to Collection<BindingImpl> is safe
    Collection<BindingImpl<?>> bindingsAtThisLevel =
        (Collection) injector.state.getExplicitBindingsThisLevel().values();
    candidateBindings.addAll(bindingsAtThisLevel);
    synchronized (injector.state.lock()) {
      // jit bindings must be accessed while holding the lock.
      candidateBindings.addAll(injector.jitBindings.values());
    }
    InternalContext context = injector.enterContext();
    try {
      for (BindingImpl<?> binding : candidateBindings) {
        if (isEagerSingleton(injector, binding, stage)) {
          Dependency<?> dependency = Dependency.get(binding.getKey());
          Dependency previous = context.pushDependency(dependency, binding.getSource());

          try {
            binding.getInternalFactory().get(context, dependency, false);
          } catch (InternalProvisionException e) {
            errors.withSource(dependency).merge(e);
          } finally {
              context.popStateAndSetDependency(previous);
            }
        }
      }
    } finally {
      context.close();
    }
  }
1255624
function() {

        /* Find all modules to import */
        var server = this;
        return utils.resolve(arguments).then(function(modules) {

          /* Prune modules already injected in the worker */
          var injectables = [];
          for (var moduleName in modules) {
            if (injectedModules[moduleName]) continue;
            injectables.push(modules[moduleName]);
          }

          /* Inject each module in the worker */
          var promises = [];
          for (var i in injectables) {

            /* Message id, deferred, and (derived) promise */
            promises.push(server.send({module: injectables[i]})
              .then(function(moduleName) {
                injectedModules[moduleName] = true;
                return moduleName;
              })
            );
          }

          /* Return a promise combining all imports */
          return Promise.all(promises);
        });
      }
255700
function getState(reactor, data) {
  var state = {}
  each(data, function(value, key) {
    state[key] = reactor.evaluate(value)
  })
  return state
}
1020873
function(map, callback) {

            // Walk through all modules in parallel
            async.map(map, function(module, callback) {

                logger.info('Loading ' + (module.name).blue + ' module');

                // Walk through all possible controllers of the module
                async.map(module.paths, function(path, callback) {

                    self.loadController(
                        path,
                        basename(path.replace(/\.js$/g, '')),
                        module.name,
                        callback
                    );

                }, function(err, controllers) {
                    module.controllers = controllers;
                    callback(err, module);
                });

            }, callback);
        }
711924
def populate_client_cache(self, low):
        '''
        
        '''
        reaction_type = low['state']
        if reaction_type not in self.client_cache:
            log.debug('Reactor is populating %s client cache', reaction_type)
            if reaction_type in ('runner', 'wheel'):
                # Reaction types that run locally on the master want the full
                # opts passed.
                self.client_cache[reaction_type] = \
                    self.reaction_class[reaction_type](self.opts)
                # The len() function will cause the module functions to load if
                # they aren't already loaded. We want to load them so that the
                # spawned threads don't need to load them. Loading in the
                # spawned threads creates race conditions such as sometimes not
                # finding the required function because another thread is in
                # the middle of loading the functions.
                len(self.client_cache[reaction_type].functions)
            else:
                # Reactions which use remote pubs only need the conf file when
                # instantiating a client instance.
                self.client_cache[reaction_type] = \
                    self.reaction_class[reaction_type](self.opts['conf_file'])
661815
function () {
      this._objects.push.apply(this._objects, arguments);
      for (var i = arguments.length; i--; ) {
        this._initObject(arguments[i]);
      }
      this.renderOnAddition && this.renderAll();
      return this;
    }
372246
function loadFactories(opts) {
        this.flapjackFactory = new FlapjackFactory(this);

        return [
            new InternalObjFactory(this),
            new AdapterFactory(this),
            new ServiceFactory(this),
            new ModelFactory(this),
            new UipartFactory(this),
            this.flapjackFactory,
            new ModulePluginFactory(this, opts.modulePlugins),
            new DefaultFactory(this)
        ];
    }
499206
function loadModels() {
  const modelSpecsPath = path.join(process.cwd(), plugin.config.modelsPath);

  return plugin.myrmex.fire('beforeModelsLoad')
  .spread(() => {
    return Promise.promisify(fs.readdir)(modelSpecsPath);
  })
  .then(fileNames => {
    // Load all the model specifications
    return Promise.map(fileNames, fileName => {
      const modelSpecPath = path.join(modelSpecsPath, fileName);
      const modelName = path.parse(fileName).name;
      return loadModel(modelSpecPath, modelName);
    });
  })
  .then(models => {
    return plugin.myrmex.fire('afterModelsLoad', models);
  })
  .spread(models => {
    return Promise.resolve(models);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === path.basename(plugin.config.modelsPath)) {
      return Promise.resolve([]);
    }
    Promise.reject(e);
  });
}
951066
function loadTemplates() {
  const templatesPath = path.join(process.cwd(), plugin.config.templatesPath);

  return plugin.myrmex.fire('beforeTemplatesLoad')
  .then(() => {
    // Retrieve paths of all node packages
    return Promise.promisify(fs.readdir)(templatesPath);
  })
  .then(files => {
    // Load all packages configurations
    const templatePromises = [];
    _.forEach(files, (fileName) => {
      const templatePath = path.join(templatesPath, fileName);
      // subdir is the identifier of the template, so we pass it as the second argument
      templatePromises.push(loadTemplate(templatePath, fileName));
    });
    return Promise.all(templatePromises);
  })
  .then(templates => {
    // This event allows to inject code to add or delete or alter node templates configurations
    return plugin.myrmex.fire('afterTemplatesLoad', templates);
  })
  .spread(templates => {
    return Promise.resolve(templates);
  })
  .catch(e => {
    // In case the project does not have any template yet, an exception will be thrown
    // We silently ignore it
    if (e.code === 'ENOENT' && path.basename(e.path) === 'templates') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}