<commit_before>module.exports = function(configMetadata){
  var self = this;

  this.appConfig = mergeConfig(configMetadata);
  this.mvcxConfig = self.appConfig.mvcx;
  console.log(self.mvcxConfig);

  this.expressApp = null;
  this.logger = null;
  this.isInitializationSuccessful = false;

  this.initialize = function(done){
    try{
      console.log('info: [mvcx] Initializing...');

      if(self.mvcxConfig.clusteringEnabled) {
          var cluster = require('cluster');
          var http = require('http');
          var numCPUs = require('os').cpus().length;
          var appConfig = null;

          if (cluster.isMaster) {
              console.log('info: [mvcx] Clustering for ' + numCPUs + ' CPU cores...');

              // Fork workers.
              for (var i = 0; i < numCPUs; i++) {
                  console.log('info: [mvcx] Spawning worker ' + (i + 1) + '...');
                  cluster.fork();
              }

              console.log('info: [mvcx] Clustering intialized with ' + numCPUs + ' worker processes.');

              cluster.on('exit', function (worker, code, signal) {
                  console.log('info: [mvcx] Worker process with process id ' + worker.process.pid + ' terminated.');
              });
          } else {
              return initializeCore(done);
          }
      }
      else{
          console.log('info: [mvcx] Clustering is disabled.');
          return initializeCore(done);
      }
    }
    catch(e){
      done(e, null);
    }
  };

  this.createHttpServer = function() {
    if(!self.isInitializationSuccessful){
      throw new Error('[mvcx] Unable create server when mvcx has not been initialized successfully.');
    }

    self.logger.info('[mvcx] Creating http server...');

    var http = self.mvcxConfig.hooks.ioc.resolve('http');
    var server  = http.createServer(self.expressApp);

    self.logger.info('[mvcx] Http server created.');

    server.on('connection', function (socket) {
        if(self.mvcxConfig.keepAliveTimeoutSeconds > 0) {
            //logger.debug('Connection opened. Setting keep alive timeout to %s seconds', config.keepAliveTimeoutSeconds);
            socket.setKeepAlive(true);
            socket.setTimeout(self.mvcxConfig.keepAliveTimeoutSeconds * 1000, function () {
                //logger.debug('Connection closed after exceeding keep alive timeout.');
            });
        }
        else{
            socket.setKeepAlive(false);
        }
    });

    if(self.mvcxConfig.keepAliveTimeoutSeconds > 0) {
        self.logger.info('[mvcx] Server connection keep-alive timeout set to %s seconds.', self.mvcxConfig.keepAliveTimeoutSeconds);
    }else {
        self.logger.info('[mvcx] Server connection keep-alive is disabled.');
    }

    return server;
  };

  this.createWebSocketServer = function(server){
    if(!self.isInitializationSuccessful){
      throw new Error('[mvcx] Unable create server when mvcx has not been initialized successfully.');
    }

    self.logger.info('[mvcx] Creating web socket (socket.io) server...');

    var socketio = self.mvcxConfig.hooks.ioc.resolve('socket.io');
    return socketio(server);

    self.logger.info('[mvcx] Web socket server created.');
  }

  function initializeCore(done){
    try
    {
      var appConfig = null;

      self.logger = initializeLogging();

      initializeIoc();

      self.expressApp = initializeExpress();

      self.logger.info('[mvcx] Intialization completed.');

      self.isInitializationSuccessful = true;

      done(null, self.appConfig);
    }
    catch(e){
      var failureMessage = '[mvcx] Intialization failed.';
      if(self.logger != null){
        self.logger.info(failureMessage);
      }
      else{
        console.log(failureMessage);
      }

      done(e, null);
    }
  }

  function mergeConfig(configMetadata) {
    var environment;
    var config;
    console.log('info: [mvcx] Initializing configuration...');

    var baseConfig = configMetadata.baseConfig;
    if (typeof(baseConfig) === 'undefined' || baseConfig == null) {
        baseConfig = {};
    }

    var merge = require('merge');

    console.log('info: [mvcx] Checking environment configuration indicator...');
    var environment = null;
    if(!isEmpty(configMetadata.environmentIndicatorVariable)){
      environment = process.env[configMetadata.environmentIndicatorVariable];
    }

    if (!isEmpty(environment)) {
        console.log('info: [mvcx] Loading configuration override for ' + environment + ' environment.');
        var overrideConfig = require(configMetadata.environments[environment]);
        if (!(overrideConfig)) {
            throw new Error('[mvcx] The ' + env + ' environment configuration override is missing. Exiting...');
        }

        console.log('info: [mvcx] Merging configuration override for ' + environment + ' environment...');
        config = merge.recursive(true, baseConfig, overrideConfig);
    }
    else {
        console.log('info: [mvcx] No environment indicator found. Continuing with the base configuration...');
        config = baseConfig;
    }
<commit_msg>fixed incorrect dependency name for expressApp<commit_after>module.exports = function(configMetadata){
  var self = this;

  this.appConfig = mergeConfig(configMetadata);
  this.mvcxConfig = self.appConfig.mvcx;
  this.expressApp = null;
  this.logger = null;
  this.isInitializationSuccessful = false;

  this.initialize = function(done){
    try{
      console.log('info: [mvcx] Initializing...');

      if(self.mvcxConfig.clusteringEnabled) {
          var cluster = require('cluster');
          var http = require('http');
          var numCPUs = require('os').cpus().length;
          var appConfig = null;

          if (cluster.isMaster) {
              console.log('info: [mvcx] Clustering for ' + numCPUs + ' CPU cores...');

              // Fork workers.
              for (var i = 0; i < numCPUs; i++) {
                  console.log('info: [mvcx] Spawning worker ' + (i + 1) + '...');
                  cluster.fork();
              }

              console.log('info: [mvcx] Clustering intialized with ' + numCPUs + ' worker processes.');

              cluster.on('exit', function (worker, code, signal) {
                  console.log('info: [mvcx] Worker process with process id ' + worker.process.pid + ' terminated.');
              });
          } else {
              return initializeCore(done);
          }
      }
      else{
          console.log('info: [mvcx] Clustering is disabled.');
          return initializeCore(done);
      }
    }
    catch(e){
      done(e, null);
    }
  };

  this.createHttpServer = function() {
    if(!self.isInitializationSuccessful){
      throw new Error('[mvcx] Unable create server when mvcx has not been initialized successfully.');
    }

    self.logger.info('[mvcx] Creating http server...');

    var http = self.mvcxConfig.hooks.ioc.resolve('http');
    var server  = http.createServer(self.expressApp);

    self.logger.info('[mvcx] Http server created.');

    server.on('connection', function (socket) {
        if(self.mvcxConfig.keepAliveTimeoutSeconds > 0) {
            //logger.debug('Connection opened. Setting keep alive timeout to %s seconds', config.keepAliveTimeoutSeconds);
            socket.setKeepAlive(true);
            socket.setTimeout(self.mvcxConfig.keepAliveTimeoutSeconds * 1000, function () {
                //logger.debug('Connection closed after exceeding keep alive timeout.');
            });
        }
        else{
            socket.setKeepAlive(false);
        }
    });

    if(self.mvcxConfig.keepAliveTimeoutSeconds > 0) {
        self.logger.info('[mvcx] Server connection keep-alive timeout set to %s seconds.', self.mvcxConfig.keepAliveTimeoutSeconds);
    }else {
        self.logger.info('[mvcx] Server connection keep-alive is disabled.');
    }

    return server;
  };

  this.createWebSocketServer = function(server){
    if(!self.isInitializationSuccessful){
      throw new Error('[mvcx] Unable create server when mvcx has not been initialized successfully.');
    }

    self.logger.info('[mvcx] Creating web socket (socket.io) server...');

    var socketio = self.mvcxConfig.hooks.ioc.resolve('socket.io');
    return socketio(server);

    self.logger.info('[mvcx] Web socket server created.');
  }

  function initializeCore(done){
    try
    {
      var appConfig = null;

      self.logger = initializeLogging();

      initializeIoc();

      self.expressApp = initializeExpress();

      self.logger.info('[mvcx] Intialization completed.');

      self.isInitializationSuccessful = true;

      done(null, self.appConfig);
    }
    catch(e){
      var failureMessage = '[mvcx] Intialization failed.';
      if(self.logger != null){
        self.logger.error(failureMessage);
      }
      else{
        console.log(failureMessage);
      }

      done(e, null);
    }
  }

  function mergeConfig(configMetadata) {
    var environment;
    var config;
    console.log('info: [mvcx] Initializing configuration...');

    var baseConfig = configMetadata.baseConfig;
    if (typeof(baseConfig) === 'undefined' || baseConfig == null) {
        baseConfig = {};
    }

    var merge = require('merge');

    console.log('info: [mvcx] Checking environment configuration indicator...');
    var environment = null;
    if(!isEmpty(configMetadata.environmentIndicatorVariable)){
      environment = process.env[configMetadata.environmentIndicatorVariable];
    }

    if (!isEmpty(environment)) {
        console.log('info: [mvcx] Loading configuration override for ' + environment + ' environment.');
        var overrideConfig = require(configMetadata.environments[environment]);
        if (!(overrideConfig)) {
            throw new Error('[mvcx] The ' + env + ' environment configuration override is missing.');
        }

        console.log('info: [mvcx] Merging configuration override for ' + environment + ' environment...');
        config = merge.recursive(true, baseConfig, overrideConfig);
    }
    else {
        console.log('info: [mvcx] No environment indicator found. Continuing with the base configuration...');
        config = baseConfig;
    }

{'fraction_non_alphanumeric': 0.12939328490084429, 'fraction_numerical': 0.0015707834282348322, 'mean_word_length': 2.5643806857942617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3118577', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2848, 'n_words': 651}