<commit_before>package com.twitter.finagle.service

/**
 * A service wrapper that expires the underlying service after a
 * certain amount of idle time. By default, expiring calls
 * ``.release()'' on the underlying channel, but this action is
 * customizable.
 */

import com.twitter.util
import com.twitter.util.{Duration, Future}

import com.twitter.finagle.util.Timer
import com.twitter.finagle.{Service, WriteException, ChannelClosedException}

class ExpiringService[Req, Rep](
    underlying: Service[Req, Rep],
    maxIdleTime: Option[Duration],
    maxLifeTime: Option[Duration],
    timer: util.Timer = Timer.default)
  extends Service[Req, Rep]
{
  private[this] var requestCount = 0
  private[this] var expired = false
  private[this] var idleTimeTask = maxIdleTime map { idleTime => timer.schedule(idleTime.fromNow) { maybeIdleExpire() } }
  private[this] var lifeTimeTask = maxLifeTime map { lifeTime => timer.schedule(lifeTime.fromNow) { maybeLifeTimeExpire() } }

  private[this] def maybeExpire(force_expire: Boolean) = {
    val justExpired = synchronized {
      // We check requestCount == 0 here to avoid the race between
      // cancellation & running of the timer.
      if (!expired && requestCount == 0) {
        expired = true
        true
      } else {
        if (force_expire) expired = true
        false
      }
    }

    if (justExpired) didExpire()
    justExpired
  }

  private[this] def maybeIdleExpire() {
    if (maybeExpire(false)) cancelLifeTimer()
  }
<commit_msg>use camelCase for forceExpire<commit_after>package com.twitter.finagle.service

/**
 * A service wrapper that expires the underlying service after a
 * certain amount of idle time. By default, expiring calls
 * ``.release()'' on the underlying channel, but this action is
 * customizable.
 */

import com.twitter.util
import com.twitter.util.{Duration, Future}

import com.twitter.finagle.util.Timer
import com.twitter.finagle.{Service, WriteException, ChannelClosedException}

class ExpiringService[Req, Rep](
    underlying: Service[Req, Rep],
    maxIdleTime: Option[Duration],
    maxLifeTime: Option[Duration],
    timer: util.Timer = Timer.default)
  extends Service[Req, Rep]
{
  private[this] var requestCount = 0
  private[this] var expired = false
  private[this] var idleTimeTask = maxIdleTime map { idleTime => timer.schedule(idleTime.fromNow) { maybeIdleExpire() } }
  private[this] var lifeTimeTask = maxLifeTime map { lifeTime => timer.schedule(lifeTime.fromNow) { maybeLifeTimeExpire() } }

  private[this] def maybeExpire(forceExpire: Boolean) = {
    val justExpired = synchronized {
      // We check requestCount == 0 here to avoid the race between
      // cancellation & running of the timer.
      if (!expired && requestCount == 0) {
        expired = true
        true
      } else {
        if (forceExpire) expired = true
        false
      }
    }

    if (justExpired) didExpire()
    justExpired
  }

  private[this] def maybeIdleExpire() {
    if (maybeExpire(false)) cancelLifeTimer()
  }

{'fraction_non_alphanumeric': 0.10363036303630363, 'fraction_numerical': 0.0019801980198019802, 'mean_word_length': 3.5924242424242423, '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': '2500069', 'n_tokens_mistral': 906, 'n_tokens_neox': 888, 'n_words': 257}