<commit_before>package io.vamp.core.pulse

import akka.actor.{Actor, ActorLogging, ActorRef}
import io.vamp.core.model.event.Event

import scala.collection.mutable


case class PercolatorEntry(tags: Set[String], actor: ActorRef, message: Any)

trait Percolator {
  this: Actor with ActorLogging =>

  private val percolators = mutable.Map[String, PercolatorEntry]()

  def registerPercolator(name: String, tags: Set[String], message: Any) = {
    log.info(s"Registering percolator '$name' for tags '${tags.mkString(", ")}'.")
    percolators.put(name, PercolatorEntry(tags, sender(), message))
  }

  def unregisterPercolator(name: String) = {
    if (percolators.remove(name).nonEmpty)
      log.info(s"Percolator successfully removed for '$name'.")
  }

  def percolate: (Event => Event) = { (event: Event) =>
    percolators.foreach { case (name, percolator) =>
      if (percolator.tags.forall(event.tags.contains)) {
        log.debug(s"Percolate match for '$name'.")
        percolator.actor ! (percolator.message -> event.tags)<commit_msg>event streaming - core events only<commit_after>package io.vamp.core.pulse

import akka.actor.{Actor, ActorLogging, ActorRef}
import io.vamp.core.model.event.Event

import scala.collection.mutable


case class PercolatorEntry(tags: Set[String], actor: ActorRef, message: Any)

trait Percolator {
  this: Actor with ActorLogging =>

  private val percolators = mutable.Map[String, PercolatorEntry]()

  def registerPercolator(name: String, tags: Set[String], message: Any) = {
    log.info(s"Registering percolator '$name' for tags '${tags.mkString(", ")}'.")
    percolators.put(name, PercolatorEntry(tags, sender(), message))
  }

  def unregisterPercolator(name: String) = {
    if (percolators.remove(name).nonEmpty)
      log.info(s"Percolator successfully removed for '$name'.")
  }

  def percolate: (Event => Event) = { (event: Event) =>
    percolators.foreach { case (name, percolator) =>
      if (percolator.tags.forall(event.tags.contains)) {
        log.debug(s"Percolate match for '$name'.")
        percolator.actor ! (percolator.message -> event)
{'fraction_non_alphanumeric': 0.13946869070208728, 'fraction_numerical': 0.0, 'mean_word_length': 4.407692307692308, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6196472', 'n_tokens_mistral': 706, 'n_tokens_neox': 680, 'n_words': 153}