@@ -18,9 +18,8 @@ package kamon
1818package module
1919
2020import java .time .{Duration , Instant }
21- import java .util .concurrent .{CountDownLatch , Executors , ScheduledFuture , TimeUnit }
21+ import java .util .concurrent .{CountDownLatch , Executors , ForkJoinPool , ScheduledFuture , TimeUnit }
2222import java .util .concurrent .atomic .AtomicReference
23-
2423import com .typesafe .config .Config
2524import kamon .module .Module .Registration
2625import kamon .status .Status
@@ -39,8 +38,9 @@ import scala.util.control.NonFatal
3938class ModuleRegistry (configuration : Configuration , clock : Clock , metricRegistry : MetricRegistry , tracer : Tracer ) {
4039
4140 private val _logger = LoggerFactory .getLogger(classOf [ModuleRegistry ])
42- private val _metricsTickerExecutor = Executors .newScheduledThreadPool(1 , threadFactory(" kamon-metrics-ticker" , daemon = true ))
43- private val _spansTickerExecutor = Executors .newScheduledThreadPool(1 , threadFactory(" kamon-spans-ticker" , daemon = true ))
41+ private val _moduleRegistryEC : ExecutionContext = ExecutionContext .fromExecutor(newScheduledThreadPool(1 , threadFactory(" kamon-module-registry" , daemon = true )))
42+ private val _metricsTickerExecutor = newScheduledThreadPool(1 , threadFactory(" kamon-metrics-ticker" , daemon = true ))
43+ private val _spansTickerExecutor = newScheduledThreadPool(1 , threadFactory(" kamon-spans-ticker" , daemon = true ))
4444
4545 private val _metricsTickerSchedule = new AtomicReference [ScheduledFuture [_]]()
4646 private val _spansTickerSchedule = new AtomicReference [ScheduledFuture [_]]()
@@ -127,7 +127,7 @@ class ModuleRegistry(configuration: Configuration, clock: Clock, metricRegistry:
127127 * spans available until the call to stop.
128128 */
129129 def stopModules (): Future [Unit ] = synchronized {
130- implicit val cleanupExecutor = ExecutionContext . Implicits .global
130+ implicit val cleanupExecutor = _moduleRegistryEC
131131 stopReporterTickers()
132132
133133 var stoppedSignals : List [Future [Unit ]] = Nil
@@ -137,11 +137,7 @@ class ModuleRegistry(configuration: Configuration, clock: Clock, metricRegistry:
137137 true
138138 }
139139
140- val latch = new CountDownLatch (stoppedSignals.size)
141- stoppedSignals.foreach(f => f.onComplete(_ => latch.countDown()))
142-
143- // TODO: Completely destroy modules that fail to stop within the 30 second timeout.
144- Future (latch.await(30 , TimeUnit .SECONDS ))
140+ Future .sequence(stoppedSignals).map(_ => ())
145141 }
146142
147143
@@ -369,7 +365,7 @@ class ModuleRegistry(configuration: Configuration, clock: Clock, metricRegistry:
369365 * context. The returned future completes when the module finishes its stop procedure.
370366 */
371367 private def stopModule (entry : Entry [Module ]): Future [Unit ] = synchronized {
372- val cleanupExecutor = ExecutionContext . Implicits .global
368+ val cleanupExecutor = _moduleRegistryEC
373369
374370 // Remove the module from all registries
375371 _registeredModules = _registeredModules - entry.name
0 commit comments