Switching over to immutable.Iterable where possible
This commit is contained in:
parent
8f131c680f
commit
b00c47854b
44 changed files with 385 additions and 369 deletions
|
|
@ -5,8 +5,7 @@
|
|||
package akka.serialization
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import akka.AkkaException
|
||||
import akka.actor.{ Extension, ExtendedActorSystem, Address, DynamicAccess }
|
||||
import akka.actor.{ Extension, ExtendedActorSystem, Address }
|
||||
import akka.event.Logging
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
|
|
@ -28,17 +27,13 @@ object Serialization {
|
|||
val currentTransportAddress = new DynamicVariable[Address](null)
|
||||
|
||||
class Settings(val config: Config) {
|
||||
val Serializers: Map[String, String] = configToMap("akka.actor.serializers")
|
||||
val SerializationBindings: Map[String, String] = configToMap("akka.actor.serialization-bindings")
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import config._
|
||||
|
||||
val Serializers: Map[String, String] = configToMap(getConfig("akka.actor.serializers"))
|
||||
|
||||
val SerializationBindings: Map[String, String] = configToMap(getConfig("akka.actor.serialization-bindings"))
|
||||
|
||||
private def configToMap(cfg: Config): Map[String, String] =
|
||||
cfg.root.unwrapped.asScala.toMap.map { case (k, v) ⇒ (k, v.toString) }
|
||||
|
||||
private final def configToMap(path: String): Map[String, String] = {
|
||||
import scala.collection.JavaConverters._
|
||||
config.getConfig(path).root.unwrapped.asScala.mapValues(_.toString).toMap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,16 +58,16 @@ class Serialization(val system: ExtendedActorSystem) extends Extension {
|
|||
* using the optional type hint to the Serializer and the optional ClassLoader ot load it into.
|
||||
* Returns either the resulting object or an Exception if one was thrown.
|
||||
*/
|
||||
def deserialize(bytes: Array[Byte],
|
||||
serializerId: Int,
|
||||
clazz: Option[Class[_]]): Try[AnyRef] = Try(serializerByIdentity(serializerId).fromBinary(bytes, clazz))
|
||||
def deserialize(bytes: Array[Byte], serializerId: Int, clazz: Option[Class[_]]): Try[AnyRef] =
|
||||
Try(serializerByIdentity(serializerId).fromBinary(bytes, clazz))
|
||||
|
||||
/**
|
||||
* Deserializes the given array of bytes using the specified type to look up what Serializer should be used.
|
||||
* You can specify an optional ClassLoader to load the object into.
|
||||
* Returns either the resulting object or an Exception if one was thrown.
|
||||
*/
|
||||
def deserialize(bytes: Array[Byte], clazz: Class[_]): Try[AnyRef] = Try(serializerFor(clazz).fromBinary(bytes, Some(clazz)))
|
||||
def deserialize(bytes: Array[Byte], clazz: Class[_]): Try[AnyRef] =
|
||||
Try(serializerFor(clazz).fromBinary(bytes, Some(clazz)))
|
||||
|
||||
/**
|
||||
* Returns the Serializer configured for the given object, returns the NullSerializer if it's null.
|
||||
|
|
@ -96,8 +91,7 @@ class Serialization(val system: ExtendedActorSystem) extends Extension {
|
|||
*/
|
||||
def serializerFor(clazz: Class[_]): Serializer =
|
||||
serializerMap.get(clazz) match {
|
||||
case null ⇒
|
||||
// bindings are ordered from most specific to least specific
|
||||
case null ⇒ // bindings are ordered from most specific to least specific
|
||||
def unique(possibilities: immutable.Seq[(Class[_], Serializer)]): Boolean =
|
||||
possibilities.size == 1 ||
|
||||
(possibilities forall (_._1 isAssignableFrom possibilities(0)._1)) ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue