<commit_before>package com.twitter.finagle.filter

import com.twitter.concurrent.NamedPoolThreadFactory
import com.twitter.finagle.offload.numWorkers
import com.twitter.finagle.stats.FinagleStatsReceiver
import com.twitter.finagle.{Service, ServiceFactory, SimpleFilter, Stack, Stackable}
import com.twitter.util.{Future, FuturePool, Promise}
import java.util.concurrent.{ExecutorService, Executors}

/**
 * These modules introduce async-boundary into the future chain, effectively shifting continuations
 * off of IO threads (into a given [[FuturePool]]).
 *
 * This filter can be enabled by default through the flag `com.twitter.finagle.offload.numWorkers`.
 */
private[finagle] object OffloadFilter {

  val Role = Stack.Role("OffloadWorkFromIO")
  val Description = "Offloading computations from IO threads"

  private[this] lazy val (defautPool, defautPoolStats) = {
    numWorkers.get match {
      case None =>
        (None, Seq.empty)
      case Some(threads) =>
        val factory = new NamedPoolThreadFactory("finagle/offload", makeDaemons = true)
        val pool = FuturePool.interruptible(Executors.newFixedThreadPool(threads, factory))
        val stats = FinagleStatsReceiver.scope("offload_pool")
        val gauges = Seq(
          stats.addGauge("pool_size") { pool.poolSize },
          stats.addGauge("active_tasks") { pool.numActiveTasks },
          stats.addGauge("completed_tasks") { pool.numCompletedTasks },
        )
        (Some(pool), gauges)
    }
  }

  sealed abstract class Param
  object Param {

    def apply(pool: FuturePool): Param = Enabled(pool)
    def apply(executor: ExecutorService): Param = Enabled(FuturePool(executor))

    final case class Enabled(pool: FuturePool) extends Param
    final case object Disabled extends Param

    implicit val param: Stack.Param[Param] =
      Stack.Param(defautPool.map(Enabled(_)).getOrElse(Disabled))<commit_msg>finagle-core: Remove extra comma for sbt compile<commit_after>package com.twitter.finagle.filter

import com.twitter.concurrent.NamedPoolThreadFactory
import com.twitter.finagle.offload.numWorkers
import com.twitter.finagle.stats.FinagleStatsReceiver
import com.twitter.finagle.{Service, ServiceFactory, SimpleFilter, Stack, Stackable}
import com.twitter.util.{Future, FuturePool, Promise}
import java.util.concurrent.{ExecutorService, Executors}

/**
 * These modules introduce async-boundary into the future chain, effectively shifting continuations
 * off of IO threads (into a given [[FuturePool]]).
 *
 * This filter can be enabled by default through the flag `com.twitter.finagle.offload.numWorkers`.
 */
private[finagle] object OffloadFilter {

  val Role = Stack.Role("OffloadWorkFromIO")
  val Description = "Offloading computations from IO threads"

  private[this] lazy val (defautPool, defautPoolStats) = {
    numWorkers.get match {
      case None =>
        (None, Seq.empty)
      case Some(threads) =>
        val factory = new NamedPoolThreadFactory("finagle/offload", makeDaemons = true)
        val pool = FuturePool.interruptible(Executors.newFixedThreadPool(threads, factory))
        val stats = FinagleStatsReceiver.scope("offload_pool")
        val gauges = Seq(
          stats.addGauge("pool_size") { pool.poolSize },
          stats.addGauge("active_tasks") { pool.numActiveTasks },
          stats.addGauge("completed_tasks") { pool.numCompletedTasks }
        )
        (Some(pool), gauges)
    }
  }

  sealed abstract class Param
  object Param {

    def apply(pool: FuturePool): Param = Enabled(pool)
    def apply(executor: ExecutorService): Param = Enabled(FuturePool(executor))

    final case class Enabled(pool: FuturePool) extends Param
    final case object Disabled extends Param

    implicit val param: Stack.Param[Param] =
      Stack.Param(defautPool.map(Enabled(_)).getOrElse(Disabled))
{'fraction_non_alphanumeric': 0.0994258872651357, 'fraction_numerical': 0.0, 'mean_word_length': 4.097074468085107, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5031367', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1085, 'n_words': 275}