diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-03-14 10:52:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-14 10:52:40 +0100 |
commit | c0dac6d7eb9bbd4aa2a5212f9d211dd32e9fb37f (patch) | |
tree | 3e77fccdd468cadced53a530f2a5625ef7690413 | |
parent | 7d4178fabce892fdb64b09fd16693a3d3f3ac240 (diff) | |
parent | 1bc1d08b34d0bb0fb8842a1417968395c13763b5 (diff) | |
download | Kamon-c0dac6d7eb9bbd4aa2a5212f9d211dd32e9fb37f.tar.gz Kamon-c0dac6d7eb9bbd4aa2a5212f9d211dd32e9fb37f.tar.bz2 Kamon-c0dac6d7eb9bbd4aa2a5212f9d211dd32e9fb37f.zip |
Merge pull request #446 from pjfanning/issue-443
[issue 443] actor system terminate
-rw-r--r-- | kamon-core/src/main/scala/kamon/ActorSystemTools.scala | 30 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/Kamon.scala | 2 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala | 6 |
3 files changed, 34 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/ActorSystemTools.scala b/kamon-core/src/main/scala/kamon/ActorSystemTools.scala new file mode 100644 index 00000000..31c8e7e7 --- /dev/null +++ b/kamon-core/src/main/scala/kamon/ActorSystemTools.scala @@ -0,0 +1,30 @@ +/* ========================================================================================= + * Copyright © 2013-2016 the kamon project <http://kamon.io/> + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + * ========================================================================================= + */ +package kamon + +import scala.util.control.NonFatal + +import akka.actor.ActorSystem + +object ActorSystemTools { + //first try akka 2.4 system terminate() and then failover to akka 2.3 system shutdown() + private[kamon] def terminateActorSystem(system: ActorSystem): Unit = { + try { + system.terminate() + } catch { + case NonFatal(e) => system.shutdown() + } + } +} diff --git a/kamon-core/src/main/scala/kamon/Kamon.scala b/kamon-core/src/main/scala/kamon/Kamon.scala index 61480073..c02d0505 100644 --- a/kamon-core/src/main/scala/kamon/Kamon.scala +++ b/kamon-core/src/main/scala/kamon/Kamon.scala @@ -76,7 +76,7 @@ object Kamon { def shutdown(): Unit = { if (started) { - actorSystem.shutdown() + ActorSystemTools.terminateActorSystem(actorSystem) } } diff --git a/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala b/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala index a615dde4..995f15fa 100644 --- a/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala +++ b/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala @@ -19,7 +19,7 @@ package kamon.testkit import akka.actor.ActorSystem import akka.testkit.{ImplicitSender, TestKitBase} import com.typesafe.config.Config -import kamon.Kamon +import kamon.{ActorSystemTools, Kamon} import kamon.metric.{Entity, EntitySnapshot, SubscriptionsDispatcher} import kamon.trace.TraceContext import kamon.util.LazyActorRef @@ -27,7 +27,7 @@ import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike} abstract class BaseKamonSpec(actorSystemName: String) extends TestKitBase with WordSpecLike with Matchers with ImplicitSender with BeforeAndAfterAll { lazy val collectionContext = Kamon.metrics.buildDefaultCollectionContext - implicit lazy val system: ActorSystem = { + override implicit lazy val system: ActorSystem = { Kamon.start(mergedConfig) ActorSystem(actorSystemName, mergedConfig) } @@ -65,6 +65,6 @@ abstract class BaseKamonSpec(actorSystemName: String) extends TestKitBase with W override protected def afterAll(): Unit = { Kamon.shutdown() - system.shutdown() + ActorSystemTools.terminateActorSystem(system) } } |