<commit_before>package akka.viz.events

import akka.actor._

object FilteringRule {
  val Default: FilteringRule = IsUserActor
}

sealed trait FilteringRule {
  def apply(received: Received): Boolean
}

case object IsUserActor extends FilteringRule {
  private def isUserActor(actorRef: ActorRef): Boolean = actorRef.path.elements.headOption.contains("user")

  override def apply(event: Received) = {
    isUserActor(event.sender) || isUserActor(event.receiver)
  }
}

case object AllowAll extends FilteringRule { override def apply(event: Received) = true }

case class AllowedClasses(names: List[String]) extends FilteringRule {
  @transient private val allowedClasses = names.map(name => getClass.getClassLoader.loadClass(name)).toSet
  override def apply(event: Received): Boolean = {
    allowedClasses.exists(c => c.isAssignableFrom(event.message.getClass))
  }<commit_msg>add error handling for classes that failed to load<commit_after>package akka.viz.events

import akka.actor.Status.Success
import akka.actor._

import scala.util.{Failure, Try}

object FilteringRule {
  val Default: FilteringRule = IsUserActor
}

sealed trait FilteringRule {
  def apply(received: Received): Boolean
}

case object IsUserActor extends FilteringRule {
  private def isUserActor(actorRef: ActorRef): Boolean = actorRef.path.elements.headOption.contains("user")

  override def apply(event: Received) = {
    isUserActor(event.sender) || isUserActor(event.receiver)
  }
}

case object AllowAll extends FilteringRule { override def apply(event: Received) = true }

case class AllowedClasses(names: List[String]) extends FilteringRule {
  @transient private val allowedClasses = names.flatMap { name =>
    val loaded: Try[Class[_]] = Try(getClass.getClassLoader.loadClass(name))
    loaded.failed.foreach(thr => println(s"class loading failed: $thr"))
    loaded.toOption.toIterable
  }


  override def apply(event: Received): Boolean = {
    allowedClasses.exists(c => c.isAssignableFrom(event.message.getClass))
  }
{'fraction_non_alphanumeric': 0.1009950248756219, 'fraction_numerical': 0.0, 'mean_word_length': 5.304075235109718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3433452', 'n_tokens_mistral': 602, 'n_tokens_neox': 597, 'n_words': 149}