<commit_before>package io.reactors
package concurrent



import java.text.SimpleDateFormat
import java.util.Date
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.atomic._
import scala.annotation.tailrec
import scala.annotation.unchecked
import scala.collection._
import scala.concurrent.duration._
import scala.reflect.ClassTag
import scala.util.DynamicVariable



/** Defines services used by an reactor system.
 */
abstract class Services {
  def system: ReactorSystem

  private val services = mutable.Map[ClassTag[_], AnyRef]()

  /** System configuration */
  def config = system.bundle.config

  /** Clock services. */
  val clock = service[Services.Clock]

  /** Debugger services. */
  val debugger = service[Services.Debugger]

  /** Logging services. */
  val log = service[Services.Log]

  /** Naming services. */
  val names = service[Services.Names]

  /** I/O services. */
  val io = service[Platform.Services.Io]

  /** Network services. */
  val net = service[Platform.Services.Net]

  /** Remoting services, used to contact other reactor systems. */
  lazy val remote = service[Remote]

  /** The register of channels in this reactor system.
   *
   *  Used for creating and finding channels.
   */
  val channels: Services.Channels = service[Services.Channels]

  /** Arbitrary service. */
  def service[T <: Protocol.Service: ClassTag] = {
    val tag = implicitly[ClassTag[T]]
    if (!services.contains(tag)) {
      val ctor = tag.runtimeClass.getConstructor(classOf[ReactorSystem])
      services(tag) = ctor.newInstance(system).asInstanceOf[AnyRef]
    }
    services(tag).asInstanceOf[T]
  }

  /** Shut down all services. */
  protected def shutdownServices() {
    for ((_, service) <- services) {
      service.asInstanceOf[Protocol.Service].shutdown()
    }
  }

}


/** Contains common service implementations.
 */
object Services {

  private val timestampFormat = new SimpleDateFormat("dd/MM/yy hh:mm:ss")

  private def loggingTag(): String = {
    val time = System.currentTimeMillis()
    val formattedTime = timestampFormat.format(new Date(time))
    val frame = Reactor.self[Nothing].frame
    s"[$formattedTime | ${frame.name} (${frame.uid})] "
  }

  /** Contains services needed to communicate with the debugger.
   */
  class Debugger(val system: ReactorSystem) extends Protocol.Service {
    object terminal {<commit_msg>Use `Platform.Reflect` to instantiate plugin services.<commit_after>package io.reactors
package concurrent



import java.text.SimpleDateFormat
import java.util.Date
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.atomic._
import scala.annotation.tailrec
import scala.annotation.unchecked
import scala.collection._
import scala.concurrent.duration._
import scala.reflect.ClassTag
import scala.util.DynamicVariable



/** Defines services used by an reactor system.
 */
abstract class Services extends Platform.Reflectable {
  def system: ReactorSystem

  private val services = mutable.Map[ClassTag[_], AnyRef]()

  /** System configuration */
  def config = system.bundle.config

  /** Clock services. */
  val clock = service[Services.Clock]

  /** Debugger services. */
  val debugger = service[Services.Debugger]

  /** Logging services. */
  val log = service[Services.Log]

  /** Naming services. */
  val names = service[Services.Names]

  /** I/O services. */
  val io = service[Platform.Services.Io]

  /** Network services. */
  val net = service[Platform.Services.Net]

  /** Remoting services, used to contact other reactor systems. */
  lazy val remote = service[Remote]

  /** The register of channels in this reactor system.
   *
   *  Used for creating and finding channels.
   */
  val channels: Services.Channels = service[Services.Channels]

  /** Arbitrary service. */
  def service[T <: Protocol.Service: ClassTag] = {
    val tag = implicitly[ClassTag[T]]
    if (!services.contains(tag)) {
      services(tag) = Platform.Reflect.instantiate(tag.runtimeClass, Seq(system))
    }
    services(tag).asInstanceOf[T]
  }

  /** Shut down all services. */
  protected def shutdownServices() {
    for ((_, service) <- services) {
      service.asInstanceOf[Protocol.Service].shutdown()
    }
  }

}


/** Contains common service implementations.
 */
object Services {

  private val timestampFormat = new SimpleDateFormat("dd/MM/yy hh:mm:ss")

  private def loggingTag(): String = {
    val time = System.currentTimeMillis()
    val formattedTime = timestampFormat.format(new Date(time))
    val frame = Reactor.self[Nothing].frame
    s"[$formattedTime | ${frame.name} (${frame.uid})] "
  }

  /** Contains services needed to communicate with the debugger.
   */
  class Debugger(val system: ReactorSystem) extends Protocol.Service {
    object terminal {
{'fraction_non_alphanumeric': 0.11803962460896768, 'fraction_numerical': 0.0, 'mean_word_length': 3.6517943743937926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5014110', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1357, 'n_words': 369}