From c9187e21f6200d9c70ec283d61b65f08e5037ebb Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Thu, 24 Nov 2011 14:34:42 +0100 Subject: [PATCH] Minor fixes from review --- .../java/com/typesafe/config/impl/Parseable.java | 2 +- .../src/main/scala/akka/actor/ActorSystem.scala | 14 +++++++------- .../src/main/scala/akka/actor/Extension.scala | 3 ++- .../scala/akka/testkit/TestEventListener.scala | 5 +++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/akka-actor/src/main/java/com/typesafe/config/impl/Parseable.java b/akka-actor/src/main/java/com/typesafe/config/impl/Parseable.java index ede18f5138..eef9e75b2a 100644 --- a/akka-actor/src/main/java/com/typesafe/config/impl/Parseable.java +++ b/akka-actor/src/main/java/com/typesafe/config/impl/Parseable.java @@ -78,7 +78,7 @@ public abstract class Parseable implements ConfigParseable { // so that exceptions are thrown from the public parse() function and not // from the creation of the Parseable. Essentially this is a lazy field. // The parser should close the reader when it's done with it. - // ALSO, IMPortANT: if the file or URL is not found, this must throw. + // ALSO, IMPORTANT: if the file or URL is not found, this must throw. // to support the "allow missing" feature. protected abstract Reader reader() throws IOException; diff --git a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala index be8c38add2..d15d237629 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala @@ -389,15 +389,15 @@ class ActorSystemImpl(val name: String, val applicationConfig: Config) extends A * Returns any extension registered to the specified key or returns null if not registered */ @tailrec - def lookupExtension[T <: AnyRef](key: ExtensionKey[T]): T = extensions.get(key) match { - case c: CountDownLatch ⇒ c.await(); lookupExtension(key) //Registration in process, await completion and retry - case e: Extension[_] ⇒ e.asInstanceOf[T] //Profit! - case null ⇒ null.asInstanceOf[T] //Doesn't exist + def findExtension[T <: AnyRef](key: ExtensionKey[T]): Option[T] = extensions.get(key) match { + case c: CountDownLatch ⇒ c.await(); findExtension(key) //Registration in process, await completion and retry + case e: Extension[_] ⇒ Some(e.asInstanceOf[T]) //Profit! + case null ⇒ None //Doesn't exist } - lookupExtension(ext.key) match { - case e: Extension[_] ⇒ e.asInstanceOf[Extension[T]] //Profit! - case null ⇒ //Doesn't already exist, commence registration + findExtension(ext.key) match { + case Some(e: Extension[_]) ⇒ e.asInstanceOf[Extension[T]] //Profit! + case None ⇒ //Doesn't already exist, commence registration val inProcessOfRegistration = new CountDownLatch(1) extensions.putIfAbsent(ext.key, inProcessOfRegistration) match { // Signal that registration is in process case null ⇒ try { // Signal was successfully sent diff --git a/akka-actor/src/main/scala/akka/actor/Extension.scala b/akka-actor/src/main/scala/akka/actor/Extension.scala index 29209cd9a8..7c582fa8c4 100644 --- a/akka-actor/src/main/scala/akka/actor/Extension.scala +++ b/akka-actor/src/main/scala/akka/actor/Extension.scala @@ -54,11 +54,12 @@ trait Extension[T <: AnyRef] { */ def key: ExtensionKey[T] + // FIXME ActorSystemImpl exposed to user API. We might well choose to introduce a new interface for this level of access, just so we can shuffle around the implementation /** * This method is called by the ActorSystem when the extension is registered * to trigger initialization of the extension. */ - def init(system: ActorSystemImpl) + def init(system: ActorSystemImpl): Unit } /** diff --git a/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala b/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala index a0c9e35d56..675bdfe8c1 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala @@ -82,11 +82,12 @@ abstract class EventFilter(occurrences: Int) { def intercept[T](code: ⇒ T)(implicit system: ActorSystem): T = { system.eventStream publish TestEvent.Mute(this) val testKitExtension = TestKitExtension(system) + val leeway = testKitExtension.settings.TestEventFilterLeeway try { val result = code - if (!awaitDone(testKitExtension.settings.TestEventFilterLeeway)) + if (!awaitDone(leeway)) if (todo > 0) - throw new AssertionError("Timeout (" + testKitExtension.settings.TestEventFilterLeeway + ") waiting for " + todo + " messages on " + this) + throw new AssertionError("Timeout (" + leeway + ") waiting for " + todo + " messages on " + this) else throw new AssertionError("Received " + (-todo) + " messages too many on " + this) result