<commit_before>package almhirt.herder.herdingdogs

import scala.concurrent.duration._
import akka.actor._
import almhirt.common._
import almhirt.context._
import almhirt.herder.HerderMessages
import akka.actor.ActorRef
import almhirt.akkax.{ ComponentControl, ComponentId }

object ComponentControlHerdingDog {

  val actorname = "component-control-herdingdog"
}

private[almhirt] class ComponentControlHerdingDog()(implicit override val almhirtContext: AlmhirtContext) extends Actor with HasAlmhirtContext with ActorLogging {
  import HerderMessages.ComponentControlMessages._

  implicit val executor = almhirtContext.futuresContext

  var componentControls: Map[ComponentId, ComponentControl] = Map.empty

  def receiveRunning: Receive = {
    case RegisterComponentControl(ownerId, cb) ⇒
      log.info(s"""Component control registered for "${ownerId}".""")
      componentControls = componentControls + (ownerId → cb)

    case DeregisterComponentControl(ownerId) ⇒
      log.info(s"""Component control deregistered for "${ownerId}".""")
      componentControls = componentControls - ownerId

    case ReportComponentStates ⇒
      val pinnedSender = sender()
      val futs = componentControls.map({
        case (ownerId, cb) ⇒
          try {
          cb.state(1.second).recover(p ⇒ almhirt.akkax.ComponentState.Error(p)).map(st ⇒ (ownerId, st))
          } catch {
            case scala.util.control.NonFatal(exn) =>
              AlmFuture.successful((ownerId, almhirt.akkax.ComponentState.Error(UnspecifiedProblem(s"Failed to Report component state for $ownerId:\n$exn"))))
          }
      })
      val statesF = AlmFuture.sequence(futs.toSeq)
      statesF.onComplete(
        fail ⇒ log.error(s"Could not determine circuit states:\n$fail"),
        states ⇒ pinnedSender ! ComponentStates(states.toSeq.sortBy(_._1)))

    case AttemptComponentControlAction(ownerId, action) ⇒
      componentControls.find(_._1 == ownerId) match {
        case Some(cc) ⇒
          if (cc._2.supports(action)) {
            cc._2.changeState(action)
            log.info(s"""Sent request for action $action to component "$ownerId".""")
          } else {
            log.warning(s""""$ownerId" does not support $action.""")
          }
        case None ⇒ log.warning(s"""There is no component named "$ownerId".""")
      }
  }

  override def receive: Receive = receiveRunning
} <commit_msg>even more logging<commit_after>package almhirt.herder.herdingdogs

import scala.concurrent.duration._
import akka.actor._
import almhirt.common._
import almhirt.context._
import almhirt.herder.HerderMessages
import akka.actor.ActorRef
import almhirt.akkax.{ ComponentControl, ComponentId }
import almhirt.akkax._

object ComponentControlHerdingDog {

  val actorname = "component-control-herdingdog"
}

private[almhirt] class ComponentControlHerdingDog()(implicit override val almhirtContext: AlmhirtContext) extends AlmActor with HasAlmhirtContext with AlmActorLogging {
  import HerderMessages.ComponentControlMessages._

  implicit val executor = almhirtContext.futuresContext

  var componentControls: Map[ComponentId, ComponentControl] = Map.empty

  def receiveRunning: Receive = {
    case RegisterComponentControl(ownerId, cb) ⇒
      logInfo(s"""Component control registered for "${ownerId}".""")
      componentControls = componentControls + (ownerId → cb)

    case DeregisterComponentControl(ownerId) ⇒
      logInfo(s"""Component control deregistered for "${ownerId}".""")
      componentControls = componentControls - ownerId

    case ReportComponentStates ⇒
      val pinnedSender = sender()
      val futs = componentControls.map({
        case (ownerId, cb) ⇒
          try {
          cb.state(1.second).recover(p ⇒ almhirt.akkax.ComponentState.Error(p)).map(st ⇒ (ownerId, st))
          } catch {
            case scala.util.control.NonFatal(exn) =>
              logError(s"Failed to Report component state for $ownerId", exn)
              AlmFuture.successful((ownerId, almhirt.akkax.ComponentState.Error(UnspecifiedProblem(s"Failed to Report component state for $ownerId:\n$exn"))))
          }
      })
      val statesF = AlmFuture.sequence(futs.toSeq)
      statesF.onComplete(
        fail ⇒ logError(s"Could not determine circuit states:\n$fail"),
        states ⇒ pinnedSender ! ComponentStates(states.toSeq.sortBy(_._1)))

    case AttemptComponentControlAction(ownerId, action) ⇒
      componentControls.find(_._1 == ownerId) match {
        case Some(cc) ⇒
          if (cc._2.supports(action)) {
            cc._2.changeState(action)
            logInfo(s"""Sent request for action $action to component "$ownerId".""")
          } else {
            logWarning(s""""$ownerId" does not support $action.""")
          }
        case None ⇒ logWarning(s"""There is no component named "$ownerId".""")
      }
  }

  override def receive: Receive = receiveRunning
  
  override def preStart() {
    super.preStart()
    logInfo("Starting..")
  }
  
  override def postStop() {
    super.postStop()
    logInfo("Stopped..")
  }
  
} 
{'fraction_non_alphanumeric': 0.10884622996239858, 'fraction_numerical': 0.0019790223629527013, 'mean_word_length': 3.3871527777777777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5047972', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1485, 'n_words': 346}