Modularize configuration. See #1361
* Split config reference to one for each module/extension. * Adjusted signature of registerExtension to avoid race of extension init * Moved Duration.dilated to testkit * TestKitExtension * RemoteExtension * SerializationExtension * Durable mailboxes extensions * Fixed broken serialization bindings and added test * Updated configuration documentation * System properties akka.remote.hostname akka.remote.port replaced with akka.remote.server.hostname and akka.remote.server.port * Adjustments of ActorSystem initialization. Still don't like the two-phase constructor/init flow. Very fragile for changes. Review fixes. SerializationExtension
This commit is contained in:
parent
c56341b3a6
commit
179399296e
85 changed files with 1233 additions and 643 deletions
|
|
@ -8,7 +8,6 @@ import akka.AkkaException
|
|||
import akka.util.ReflectiveAccess
|
||||
import akka.actor.{ ActorSystem, ActorSystemImpl }
|
||||
import scala.util.DynamicVariable
|
||||
import akka.remote.RemoteSupport
|
||||
|
||||
case class NoSerializerFoundException(m: String) extends AkkaException(m)
|
||||
|
||||
|
|
@ -64,14 +63,15 @@ class Serialization(val system: ActorSystemImpl) {
|
|||
}
|
||||
}
|
||||
|
||||
// serializers and bindings needs to be lazy because Serialization is initialized from SerializationExtension, which is needed here
|
||||
|
||||
/**
|
||||
* A Map of serializer from alias to implementation (class implementing akka.serialization.Serializer)
|
||||
* By default always contains the following mapping: "default" -> akka.serialization.JavaSerializer
|
||||
* But "default" can be overridden in config
|
||||
*/
|
||||
val serializers: Map[String, Serializer] = {
|
||||
import scala.collection.JavaConverters._
|
||||
val serializersConf = system.settings.config.getConfig("akka.actor.serializers").toObject.unwrapped.asScala.toMap
|
||||
lazy val serializers: Map[String, Serializer] = {
|
||||
val serializersConf = SerializationExtension(system).settings.Serializers
|
||||
for ((k: String, v: String) ← serializersConf)
|
||||
yield k -> serializerOf(v).fold(throw _, identity)
|
||||
}
|
||||
|
|
@ -79,29 +79,27 @@ class Serialization(val system: ActorSystemImpl) {
|
|||
/**
|
||||
* bindings is a Map whose keys = FQN of class that is serializable and values = the alias of the serializer to be used
|
||||
*/
|
||||
val bindings: Map[String, String] = {
|
||||
import scala.collection.JavaConverters._
|
||||
val configPath = "akka.actor.serialization-bindings"
|
||||
system.settings.config.hasPath(configPath) match {
|
||||
case false ⇒ Map()
|
||||
case true ⇒
|
||||
val serializationBindings = system.settings.config.getConfig(configPath).toObject.unwrapped.asScala
|
||||
serializationBindings.foldLeft(Map[String, String]()) {
|
||||
case (result, (k: String, vs: List[_])) ⇒ result ++ (vs collect { case v: String ⇒ (v, k) }) //All keys which are lists, take the Strings from them and Map them
|
||||
case (result, _) ⇒ result //For any other values, just skip them, TODO: print out warnings?
|
||||
}
|
||||
lazy val bindings: Map[String, String] = {
|
||||
val configBindings = SerializationExtension(system).settings.SerializationBindings
|
||||
configBindings.foldLeft(Map[String, String]()) {
|
||||
case (result, (k: String, vs: Seq[_])) ⇒
|
||||
//All keys which are lists, take the Strings from them and Map them
|
||||
result ++ (vs collect { case v: String ⇒ (v, k) })
|
||||
case (result, x) ⇒
|
||||
//For any other values, just skip them
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* serializerMap is a Map whose keys = FQN of class that is serializable and values = the FQN of the serializer to be used for that class
|
||||
*/
|
||||
val serializerMap: Map[String, Serializer] = bindings mapValues serializers
|
||||
lazy val serializerMap: Map[String, Serializer] = bindings mapValues serializers
|
||||
|
||||
/**
|
||||
* Maps from a Serializer.Identifier (Byte) to a Serializer instance (optimization)
|
||||
*/
|
||||
val serializerByIdentity: Map[Serializer.Identifier, Serializer] =
|
||||
lazy val serializerByIdentity: Map[Serializer.Identifier, Serializer] =
|
||||
Map(NullSerializer.identifier -> NullSerializer) ++ serializers map { case (_, v) ⇒ (v.identifier, v) }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue