<commit_before>package mesosphere.chaos

import com.google.inject.{Module, Guice}
import org.rogach.scallop.ScallopConf
import com.google.common.util.concurrent.Service
import java.util.logging.LogManager
import java.io.FileInputStream

/**
 * @author <NAME> (<EMAIL>)
 * @author <NAME> (<EMAIL>)
 */
trait App extends scala.App {
  import scala.collection.JavaConverters._

  lazy val injector = Guice.createInjector(modules().asJava)

  def conf(): ScallopConf with AppConfiguration

  def modules(): Iterable[_ <: Module]

  def configureLogging(file: String) {
    LogManager.getLogManager.readConfiguration(new FileInputStream(file))
  }

  def initConf() {
    conf().afterInit()
    if (conf().logConfigFile.isSupplied) {
      configureLogging(conf().logConfigFile())
    }
  }

  def run(clazz: Iterable[Class[_ <: Service]]) {
    initConf()

    //TODO(FL|TK): Think about pulling this out and maybe using JSR250.
    clazz.foreach(x => injector.getInstance(x).start())
  }
}<commit_msg>Shut down services on JVM exit<commit_after>package mesosphere.chaos

import com.google.inject.{Module, Guice}
import org.rogach.scallop.ScallopConf
import com.google.common.util.concurrent.Service
import java.util.logging.{Logger, LogManager}
import java.io.FileInputStream
import scala.collection.mutable.ListBuffer

/**
 * @author <NAME> (<EMAIL>)
 * @author <NAME> (<EMAIL>)
 */
trait App extends scala.App {
  import scala.collection.JavaConverters._

  lazy val injector = Guice.createInjector(modules().asJava)
  val services = ListBuffer.empty[Service]
  private val log = Logger.getLogger(getClass.getName)

  def conf(): ScallopConf with AppConfiguration

  def modules(): Iterable[_ <: Module]

  def configureLogging(file: String) {
    LogManager.getLogManager.readConfiguration(new FileInputStream(file))
  }

  def initConf() {
    conf().afterInit()
    if (conf().logConfigFile.isSupplied) {
      configureLogging(conf().logConfigFile())
    }
  }

  def run(classes: Iterable[Class[_ <: Service]]) {
    initConf()

    sys.addShutdownHook(shutdownAndWait())

    classes.foreach(c => {
      val service = injector.getInstance(c)
      services += service
      service.start()
    })
  }

  def shutdown() {
    log.info("Shutting down services")
    services.foreach(_.stop())
  }

  def shutdownAndWait() {
    log.info("Waiting for services to shut down")
    services.foreach(_.stopAndWait())
  }
}
{'fraction_non_alphanumeric': 0.12969847170590665, 'fraction_numerical': 0.0012391573729863693, 'mean_word_length': 4.13135593220339, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '5438941', 'n_tokens_mistral': 782, 'n_tokens_neox': 760, 'n_words': 158}