<commit_before>package akka.osgi.ds.impl

import java.util.concurrent.CyclicBarrier
import java.util.Properties

import org.osgi.framework.Bundle
import org.osgi.framework.BundleContext
import org.osgi.framework.ServiceFactory
import org.osgi.framework.ServiceRegistration

import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory

import akka.actor.ActorSystem
import akka.osgi.BundleDelegatingClassLoader

class ActorSystemServiceFactory(config: Config) extends ServiceFactory[ActorSystem] {

  val akkaClassLoader = classOf[ActorSystem].getClassLoader()

  val akkaConfig = config.withFallback(ConfigFactory.load(akkaClassLoader)).resolve

  val actorSystemName = Option(akkaConfig.getString("akka.system-name")).getOrElse("system")

  val dynamicConfig = new DynamicConfig(akkaConfig)

  val actorSystem = ActorSystem(actorSystemName,
    Some(dynamicConfig.config),
    Some(akkaClassLoader),
    None)

  def getService(bundle: Bundle, registration: ServiceRegistration[ActorSystem]): ActorSystem = {
    val bundleContext = bundle.getBundleContext
    val bundleClassLoader = BundleDelegatingClassLoader(bundleContext, None)
    val bundleConfig = ConfigFactory.load(bundleClassLoader)
    dynamicConfig.add(bundleContext, bundleConfig)
    val bundleSettings = new ActorSystem.Settings(bundleClassLoader, bundleConfig, actorSystemName)
    ActorSystemFacadeExtension(actorSystem)(dynamicConfig, bundleContext, bundleSettings)
  }

  def ungetService(bundle: Bundle, registration: ServiceRegistration[ActorSystem], actorSystem: ActorSystem): Unit =
    dynamicConfig.remove(bundle.getBundleContext)

  def shutdown(): Unit = {
    val barrier = new CyclicBarrier(2)
    actorSystem.registerOnTermination(barrier.await())
    actorSystem.shutdown()
    barrier.await()
  }

}<commit_msg>Use ActorSystem.awaitTermination to ensure synchronous termination with ActorSystemComponent.<commit_after>package akka.osgi.ds.impl

import java.util.concurrent.CyclicBarrier
import java.util.Properties

import org.osgi.framework.Bundle
import org.osgi.framework.BundleContext
import org.osgi.framework.ServiceFactory
import org.osgi.framework.ServiceRegistration

import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory

import akka.actor.ActorSystem
import akka.osgi.BundleDelegatingClassLoader

class ActorSystemServiceFactory(config: Config) extends ServiceFactory[ActorSystem] {

  val akkaClassLoader = classOf[ActorSystem].getClassLoader()

  val akkaConfig = config.withFallback(ConfigFactory.load(akkaClassLoader)).resolve

  val actorSystemName = Option(akkaConfig.getString("akka.system-name")).getOrElse("system")

  val dynamicConfig = new DynamicConfig(akkaConfig)

  val actorSystem = ActorSystem(actorSystemName,
    Some(dynamicConfig.config),
    Some(akkaClassLoader),
    None)

  def getService(bundle: Bundle, registration: ServiceRegistration[ActorSystem]): ActorSystem = {
    val bundleContext = bundle.getBundleContext
    val bundleClassLoader = BundleDelegatingClassLoader(bundleContext, None)
    val bundleConfig = ConfigFactory.load(bundleClassLoader)
    dynamicConfig.add(bundleContext, bundleConfig)
    val bundleSettings = new ActorSystem.Settings(bundleClassLoader, bundleConfig, actorSystemName)
    ActorSystemFacadeExtension(actorSystem)(dynamicConfig, bundleContext, bundleSettings)
  }

  def ungetService(bundle: Bundle, registration: ServiceRegistration[ActorSystem], actorSystem: ActorSystem): Unit =
    dynamicConfig.remove(bundle.getBundleContext)

  def shutdown(): Unit = {
    actorSystem.shutdown()
    actorSystem.awaitTermination()
  }

}
{'fraction_non_alphanumeric': 0.08418437758763456, 'fraction_numerical': 0.0002760143527463428, 'mean_word_length': 6.365853658536586, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3143707', 'n_tokens_mistral': 1020, 'n_tokens_neox': 973, 'n_words': 186}