Permalink
Browse files

Switching over to immutable.Iterable where possible

  • Loading branch information...
1 parent 8f131c6 commit b00c47854b5a6645896ba3cdc9e24ce2e7696264 @viktorklang viktorklang committed Nov 7, 2012
Showing with 382 additions and 366 deletions.
  1. +2 −1 akka-actor-tests/src/test/java/akka/routing/CustomRouteTest.java
  2. +4 −7 akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala
  3. +3 −3 akka-actor-tests/src/test/scala/akka/routing/CustomRouteSpec.scala
  4. +3 −4 akka-actor-tests/src/test/scala/akka/routing/ResizerSpec.scala
  5. +9 −12 akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala
  6. +1 −1 akka-actor/src/main/java/akka/japi/JAPI.java
  7. +3 −3 akka-actor/src/main/scala/akka/actor/ActorCell.scala
  8. +11 −12 akka-actor/src/main/scala/akka/actor/ActorPath.scala
  9. +4 −6 akka-actor/src/main/scala/akka/actor/ActorRefProvider.scala
  10. +10 −12 akka-actor/src/main/scala/akka/actor/ActorSystem.scala
  11. +4 −5 akka-actor/src/main/scala/akka/actor/Address.scala
  12. +3 −2 akka-actor/src/main/scala/akka/actor/Deployer.scala
  13. +9 −14 akka-actor/src/main/scala/akka/actor/FaultHandling.scala
  14. +2 −2 akka-actor/src/main/scala/akka/actor/Scheduler.scala
  15. +2 −1 akka-actor/src/main/scala/akka/actor/TypedActor.scala
  16. +5 −6 akka-actor/src/main/scala/akka/actor/dungeon/Children.scala
  17. +30 −13 akka-actor/src/main/scala/akka/actor/dungeon/ChildrenContainer.scala
  18. +2 −2 akka-actor/src/main/scala/akka/actor/dungeon/FaultHandling.scala
  19. +1 −1 akka-actor/src/main/scala/akka/dispatch/Future.scala
  20. +2 −2 akka-actor/src/main/scala/akka/event/EventBus.scala
  21. +34 −2 akka-actor/src/main/scala/akka/japi/JavaAPI.scala
  22. +7 −10 akka-actor/src/main/scala/akka/routing/ConsistentHashingRouter.scala
  23. +73 −81 akka-actor/src/main/scala/akka/routing/Routing.scala
  24. +3 −1 akka-actor/src/main/scala/akka/routing/package.scala
  25. +12 −18 akka-actor/src/main/scala/akka/serialization/Serialization.scala
  26. +54 −0 akka-actor/src/main/scala/akka/util/Collections.scala
  27. +0 −45 akka-actor/src/main/scala/akka/util/Convert.scala
  28. +1 −1 akka-actor/src/main/scala/akka/util/Index.scala
  29. +4 −5 akka-camel/src/main/scala/akka/camel/Camel.scala
  30. +1 −3 akka-cluster/src/main/scala/akka/cluster/ClusterSettings.scala
  31. +8 −12 akka-cluster/src/main/scala/akka/cluster/routing/ClusterRouterConfig.scala
  32. +2 −2 akka-docs/rst/java/code/docs/actor/FaultHandlingTestBase.java
  33. +3 −5 akka-docs/rst/java/code/docs/jrouting/CustomRouterDocTestBase.java
  34. +26 −0 akka-docs/rst/project/migration-guide-2.1.x-2.2.x.rst
  35. +1 −0 akka-docs/rst/project/migration-guides.rst
  36. +3 −4 akka-osgi/src/test/scala/akka/osgi/PojoSRTestSupport.scala
  37. +2 −4 akka-remote-tests/src/main/scala/akka/remote/testkit/MultiNodeSpec.scala
  38. +5 −4 akka-remote/src/main/scala/akka/remote/RemoteDeployer.scala
  39. +9 −32 akka-remote/src/main/scala/akka/remote/netty/Settings.scala
  40. +10 −12 akka-remote/src/main/scala/akka/remote/routing/RemoteRouterConfig.scala
  41. +6 −6 akka-testkit/src/main/java/akka/testkit/JavaTestKit.java
  42. +4 −4 akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala
  43. +2 −2 akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedIncrementTest.java
  44. +2 −4 akka-transactor/src/test/java/akka/transactor/UntypedTransactorTest.java
@@ -15,7 +15,8 @@
// only to test compilability
public void testRoute() {
final ActorRef ref = system.actorOf(new Props().withRouter(new RoundRobinRouter(1)));
- final scala.Function1<scala.Tuple2<ActorRef, Object>, scala.collection.Iterable<Destination>> route = ExtractRoute.apply(ref);
+ final scala.Function1<scala.Tuple2<ActorRef, Object>,
+ scala.collection.immutable.Iterable<Destination>> route = ExtractRoute.apply(ref);
route.apply(null);
}
@@ -4,14 +4,15 @@
package akka.actor
import language.postfixOps
+
import akka.testkit._
import org.scalatest.junit.JUnitSuite
import com.typesafe.config.ConfigFactory
import scala.concurrent.Await
import scala.concurrent.duration._
-import scala.collection.JavaConverters
-import java.util.concurrent.{ TimeUnit, RejectedExecutionException, CountDownLatch, ConcurrentLinkedQueue }
+import java.util.concurrent.{ RejectedExecutionException, ConcurrentLinkedQueue }
import akka.util.Timeout
+import akka.japi.Util.immutableSeq
import scala.concurrent.Future
import akka.pattern.ask
@@ -102,8 +103,6 @@ class ActorSystemSpec extends AkkaSpec("""akka.extensions = ["akka.actor.TestExt
}
"run termination callbacks in order" in {
- import scala.collection.JavaConverters._
-
val system2 = ActorSystem("TerminationCallbacks", AkkaSpec.testConf)
val result = new ConcurrentLinkedQueue[Int]
val count = 10
@@ -121,13 +120,11 @@ class ActorSystemSpec extends AkkaSpec("""akka.extensions = ["akka.actor.TestExt
Await.ready(latch, 5 seconds)
val expected = (for (i 1 to count) yield i).reverse
- result.asScala.toSeq must be(expected)
+ immutableSeq(result) must be(expected)
}
"awaitTermination after termination callbacks" in {
- import scala.collection.JavaConverters._
-
val system2 = ActorSystem("AwaitTermination", AkkaSpec.testConf)
@volatile
var callbackWasRun = false
@@ -19,7 +19,7 @@ class CustomRouteSpec extends AkkaSpec {
provider.createRoutees(1)
{
- case (sender, message: String) Seq(Destination(sender, target))
+ case (sender, message: String) List(Destination(sender, target))
case (sender, message) toAll(sender, provider.routees)
}
}
@@ -43,8 +43,8 @@ class CustomRouteSpec extends AkkaSpec {
val r = Await.result(router.ask(CurrentRoutees)(1 second).
mapTo[RouterRoutees], 1 second)
r.routees.size must be(1)
- route(testActor -> "hallo") must be(Seq(Destination(testActor, target)))
- route(testActor -> 12) must be(Seq(Destination(testActor, r.routees.head)))
+ route(testActor -> "hallo") must be(List(Destination(testActor, target)))
+ route(testActor -> 12) must be(List(Destination(testActor, r.routees.head)))
//#test-route
}
@@ -10,10 +10,9 @@ import akka.testkit.TestEvent._
import akka.actor.Props
import scala.concurrent.Await
import scala.concurrent.duration._
+import scala.collection.immutable
import akka.actor.ActorRef
-import java.util.concurrent.atomic.AtomicInteger
import akka.pattern.ask
-import java.util.concurrent.TimeoutException
import scala.util.Try
object ResizerSpec {
@@ -61,10 +60,10 @@ class ResizerSpec extends AkkaSpec(ResizerSpec.config) with DefaultTimeout with
lowerBound = 2,
upperBound = 3)
- val c1 = resizer.capacity(IndexedSeq.empty[ActorRef])
+ val c1 = resizer.capacity(immutable.IndexedSeq.empty[ActorRef])
c1 must be(2)
- val current = IndexedSeq(system.actorOf(Props[TestActor]), system.actorOf(Props[TestActor]))
+ val current = immutable.IndexedSeq(system.actorOf(Props[TestActor]), system.actorOf(Props[TestActor]))
val c2 = resizer.capacity(current)
c2 must be(0)
}
@@ -7,7 +7,7 @@ import language.postfixOps
import java.util.concurrent.atomic.AtomicInteger
import akka.actor._
-import scala.collection.mutable.LinkedList
+import scala.collection.immutable
import akka.testkit._
import scala.concurrent.duration._
import scala.concurrent.Await
@@ -17,7 +17,7 @@ import akka.pattern.{ ask, pipe }
import java.util.concurrent.ConcurrentHashMap
import com.typesafe.config.Config
import akka.dispatch.Dispatchers
-import akka.util.Timeout
+import akka.util.Collections.EmptyImmutableSeq
object RoutingSpec {
@@ -54,11 +54,10 @@ object RoutingSpec {
class MyRouter(config: Config) extends RouterConfig {
val foo = config.getString("foo")
def createRoute(routeeProvider: RouteeProvider): Route = {
- val routees = IndexedSeq(routeeProvider.context.actorOf(Props[Echo]))
- routeeProvider.registerRoutees(routees)
+ routeeProvider.registerRoutees(List(routeeProvider.context.actorOf(Props[Echo])))
{
- case (sender, message) Nil
+ case (sender, message) EmptyImmutableSeq
}
}
def routerDispatcher: String = Dispatchers.DefaultDispatcherId
@@ -251,15 +250,15 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with
val doneLatch = new TestLatch(connectionCount)
//lets create some connections.
- var actors = new LinkedList[ActorRef]
- var counters = new LinkedList[AtomicInteger]
+ @volatile var actors = immutable.IndexedSeq[ActorRef]()
+ @volatile var counters = immutable.IndexedSeq[AtomicInteger]()
for (i 0 until connectionCount) {
counters = counters :+ new AtomicInteger()
val actor = system.actorOf(Props(new Actor {
def receive = {
case "end" doneLatch.countDown()
- case msg: Int counters.get(i).get.addAndGet(msg)
+ case msg: Int counters(i).addAndGet(msg)
}
}))
actors = actors :+ actor
@@ -278,10 +277,8 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with
//now wait some and do validations.
Await.ready(doneLatch, remaining)
- for (i 0 until connectionCount) {
- val counter = counters.get(i).get
- counter.get must be((iterationCount * (i + 1)))
- }
+ for (i 0 until connectionCount)
+ counters(i).get must be((iterationCount * (i + 1)))
}
"deliver a broadcast message using the !" in {
@@ -5,7 +5,7 @@
public class JAPI {
public static <T> Seq<T> seq(T... ts) {
- return Util.arrayToSeq(ts);
+ return Util.immutableSeq(ts);
}
}
@@ -6,7 +6,7 @@ package akka.actor
import java.io.{ ObjectOutputStream, NotSerializableException }
import scala.annotation.tailrec
-import scala.collection.immutable.TreeSet
+import scala.collection.immutable
import scala.concurrent.duration.Duration
import scala.util.control.NonFatal
import akka.actor.dungeon.ChildrenContainer
@@ -108,7 +108,7 @@ trait ActorContext extends ActorRefFactory {
* val goodLookup = context.actorFor("kid")
* }}}
*/
- def children: Iterable[ActorRef]
+ def children: immutable.Iterable[ActorRef]
/**
* Get the child with the given name if it exists.
@@ -287,7 +287,7 @@ private[akka] object ActorCell {
final val emptyBehaviorStack: List[Actor.Receive] = Nil
- final val emptyActorRefSet: Set[ActorRef] = TreeSet.empty
+ final val emptyActorRefSet: Set[ActorRef] = immutable.TreeSet.empty
}
//ACTORCELL IS 64bytes and should stay that way unless very good reason not to (machine sympathy, cache line fit)
@@ -3,6 +3,8 @@
*/
package akka.actor
import scala.annotation.tailrec
+import scala.collection.immutable
+import akka.japi.Util.immutableSeq
import java.net.MalformedURLException
object ActorPath {
@@ -20,6 +22,8 @@ object ActorPath {
* http://www.ietf.org/rfc/rfc2396.txt
*/
val ElementRegex = """(?:[-\w:@&=+,.!~*'_;]|%\p{XDigit}{2})(?:[-\w:@&=+,.!~*'$_;]|%\p{XDigit}{2})*""".r
+
+ private[akka] final val emptyActorPath: immutable.Iterable[String] = List("")
}
/**
@@ -68,23 +72,18 @@ sealed trait ActorPath extends Comparable[ActorPath] with Serializable {
/**
* ''Java API'': Recursively create a descendant’s path by appending all child names.
*/
- def descendant(names: java.lang.Iterable[String]): ActorPath = {
- import scala.collection.JavaConverters._
- /(names.asScala)
- }
+ def descendant(names: java.lang.Iterable[String]): ActorPath = /(immutableSeq(names))
/**
* Sequence of names for this path from root to this. Performance implication: has to allocate a list.
*/
- def elements: Iterable[String]
+ def elements: immutable.Iterable[String]
/**
* ''Java API'': Sequence of names for this path from root to this. Performance implication: has to allocate a list.
*/
- def getElements: java.lang.Iterable[String] = {
- import scala.collection.JavaConverters._
- elements.asJava
- }
+ def getElements: java.lang.Iterable[String] =
+ scala.collection.JavaConverters.asJavaIterableConverter(elements).asJava
/**
* Walk up the tree to obtain and return the RootActorPath.
@@ -112,7 +111,7 @@ final case class RootActorPath(address: Address, name: String = "/") extends Act
override def /(child: String): ActorPath = new ChildActorPath(this, child)
- override val elements: Iterable[String] = List("")
+ override def elements: immutable.Iterable[String] = ActorPath.emptyActorPath
override val toString: String = address + name
@@ -134,9 +133,9 @@ final class ChildActorPath(val parent: ActorPath, val name: String) extends Acto
override def /(child: String): ActorPath = new ChildActorPath(this, child)
- override def elements: Iterable[String] = {
+ override def elements: immutable.Iterable[String] = {
@tailrec
- def rec(p: ActorPath, acc: List[String]): Iterable[String] = p match {
+ def rec(p: ActorPath, acc: List[String]): immutable.Iterable[String] = p match {
case r: RootActorPath acc
case _ rec(p.parent, p.name :: acc)
}
@@ -8,8 +8,9 @@ import akka.dispatch._
import akka.routing._
import akka.event._
import akka.util.{ Switch, Helpers }
+import akka.japi.Util.immutableSeq
+import akka.util.Collections.EmptyImmutableSeq
import scala.util.{ Success, Failure }
-import scala.util.control.NonFatal
import scala.concurrent.{ Future, Promise }
import java.util.concurrent.atomic.AtomicLong
@@ -271,10 +272,7 @@ trait ActorRefFactory {
*
* For maximum performance use a collection with efficient head & tail operations.
*/
- def actorFor(path: java.lang.Iterable[String]): ActorRef = {
- import scala.collection.JavaConverters._
- provider.actorFor(lookupRoot, path.asScala)
- }
+ def actorFor(path: java.lang.Iterable[String]): ActorRef = provider.actorFor(lookupRoot, immutableSeq(path))
/**
* Construct an [[akka.actor.ActorSelection]] from the given path, which is
@@ -480,7 +478,7 @@ class LocalActorRefProvider(
def registerExtraNames(_extras: Map[String, InternalActorRef]): Unit = extraNames ++= _extras
private def guardianSupervisorStrategyConfigurator =
- dynamicAccess.createInstanceFor[SupervisorStrategyConfigurator](settings.SupervisorStrategyClass, Nil).get
+ dynamicAccess.createInstanceFor[SupervisorStrategyConfigurator](settings.SupervisorStrategyClass, EmptyImmutableSeq).get
/**
* Overridable supervision strategy to be used by the “/user” guardian.
@@ -6,7 +6,7 @@ package akka.actor
import akka.event._
import akka.dispatch._
-import akka.pattern.ask
+import akka.japi.Util.immutableSeq
import com.typesafe.config.{ Config, ConfigFactory }
import scala.annotation.tailrec
import scala.collection.immutable
@@ -144,7 +144,7 @@ object ActorSystem {
final val LogLevel: String = getString("akka.loglevel")
final val StdoutLogLevel: String = getString("akka.stdout-loglevel")
- final val EventHandlers: immutable.Seq[String] = getStringList("akka.event-handlers").asScala.to[Vector]
+ final val EventHandlers: immutable.Seq[String] = immutableSeq(getStringList("akka.event-handlers"))
final val EventHandlerStartTimeout: Timeout = Timeout(Duration(getMilliseconds("akka.event-handler-startup-timeout"), MILLISECONDS))
final val LogConfigOnStart: Boolean = config.getBoolean("akka.log-config-on-start")
@@ -273,8 +273,7 @@ abstract class ActorSystem extends ActorRefFactory {
/**
* ''Java API'': Recursively create a descendant’s path by appending all child names.
*/
- def descendant(names: java.lang.Iterable[String]): ActorPath =
- /(scala.collection.JavaConverters.iterableAsScalaIterableConverter(names).asScala)
+ def descendant(names: java.lang.Iterable[String]): ActorPath = /(immutableSeq(names))
/**
* Start-up time in milliseconds since the epoch.
@@ -674,15 +673,14 @@ private[akka] class ActorSystemImpl(val name: String, applicationConfig: Config,
def hasExtension(ext: ExtensionId[_ <: Extension]): Boolean = findExtension(ext) != null
private def loadExtensions() {
- scala.collection.JavaConverters.collectionAsScalaIterableConverter(
- settings.config.getStringList("akka.extensions")).asScala foreach { fqcn
- dynamicAccess.getObjectFor[AnyRef](fqcn) recoverWith { case _ dynamicAccess.createInstanceFor[AnyRef](fqcn, Nil) } match {
- case Success(p: ExtensionIdProvider) registerExtension(p.lookup())
- case Success(p: ExtensionId[_]) registerExtension(p)
- case Success(other) log.error("[{}] is not an 'ExtensionIdProvider' or 'ExtensionId', skipping...", fqcn)
- case Failure(problem) log.error(problem, "While trying to load extension [{}], skipping...", fqcn)
- }
+ immutableSeq(settings.config.getStringList("akka.extensions")) foreach { fqcn
+ dynamicAccess.getObjectFor[AnyRef](fqcn) recoverWith { case _ dynamicAccess.createInstanceFor[AnyRef](fqcn, Nil) } match {
+ case Success(p: ExtensionIdProvider) registerExtension(p.lookup())
+ case Success(p: ExtensionId[_]) registerExtension(p)
+ case Success(other) log.error("[{}] is not an 'ExtensionIdProvider' or 'ExtensionId', skipping...", fqcn)
+ case Failure(problem) log.error(problem, "While trying to load extension [{}], skipping...", fqcn)
}
+ }
}
override def toString: String = lookupRoot.path.root.address.toString
@@ -120,13 +120,12 @@ object AddressFromURIString {
* Given an ActorPath it returns the Address and the path elements if the path is well-formed
*/
object ActorPathExtractor extends PathUtils {
- def unapply(addr: String): Option[(Address, Iterable[String])] =
+ def unapply(addr: String): Option[(Address, immutable.Iterable[String])] =
try {
val uri = new URI(addr)
- if (uri.getRawPath == null) None
- else AddressFromURIString.unapply(uri) match {
- case None None
- case Some(addr) Some((addr, split(uri.getRawPath).drop(1)))
+ uri.getRawPath match {
+ case null None
+ case path AddressFromURIString.unapply(uri).map((_, split(path).drop(1)))
}
} catch {
case _: URISyntaxException None
@@ -7,10 +7,11 @@ package akka.actor
import scala.concurrent.duration.Duration
import com.typesafe.config._
import akka.routing._
+import akka.japi.Util.immutableSeq
import java.util.concurrent.{ TimeUnit }
import akka.util.WildcardTree
import java.util.concurrent.atomic.AtomicReference
-import annotation.tailrec
+import scala.annotation.tailrec
/**
* This class represents deployment configuration for a given actor path. It is
@@ -141,7 +142,7 @@ private[akka] class Deployer(val settings: ActorSystem.Settings, val dynamicAcce
val deployment = config.withFallback(default)
- val routees = Vector() ++ deployment.getStringList("routees.paths").asScala
+ val routees = immutableSeq(deployment.getStringList("routees.paths"))
val nrOfInstances = deployment.getInt("nr-of-instances")
Oops, something went wrong.

0 comments on commit b00c478

Please sign in to comment.