Remoting for Akka Typed, #21225

* seems like it will just work when using the adapters, since
  it will simply delegate to the untyped RemoteActorRef
* ActorRefResolver was added for upporting erialization of typed ActorRef
* The ActorRef itself is not serializable with Java serialization,
  and we shouldn't do that
This commit is contained in:
Patrik Nordwall 2017-09-08 10:19:43 +02:00
parent 1e4e7cbba2
commit fd11b94b1f
2 changed files with 44 additions and 1 deletions

View file

@ -0,0 +1,43 @@
/**
* Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com>
*/
package akka.typed.cluster
import akka.typed.ActorSystem
import akka.typed.Extension
import akka.typed.ExtensionId
import akka.typed.ActorRef
import akka.actor.ExtendedActorSystem
object ActorRefResolver extends ExtensionId[ActorRefResolver] {
def get(system: ActorSystem[_]): ActorRefResolver = apply(system)
override def createExtension(system: ActorSystem[_]): ActorRefResolver =
new ActorRefResolver(system)
}
/**
* Serialization and deserialization of `ActorRef`.
*/
class ActorRefResolver(system: ActorSystem[_]) extends Extension {
import akka.typed.scaladsl.adapter._
private val untypedSystem = system.toUntyped.asInstanceOf[ExtendedActorSystem]
/**
* Generate full String representation including the uid for the actor cell
* instance as URI fragment, replacing the Address in the RootActor Path
* with the local one unless this paths address includes host and port
* information. This representation should be used as serialized
* representation.
*/
def toSerializationFormat[T](ref: ActorRef[T]): String =
ref.path.toSerializationFormatWithAddress(untypedSystem.provider.getDefaultAddress)
/**
* Deserialize an `ActorRef` in the [[#toSerializationFormat]].
*/
def resolveActorRef[T](serializedActorRef: String): ActorRef[T] =
untypedSystem.provider.resolveActorRef(serializedActorRef)
}

View file

@ -158,7 +158,7 @@ lazy val streamTestsTck = akkaModule("akka-stream-tests-tck")
.dependsOn(streamTestkit % "test->test", stream)
lazy val typed = akkaModule("akka-typed")
.dependsOn(testkit % "compile->compile;test->test")
.dependsOn(testkit % "compile->compile;test->test", cluster % "compile->compile;test->test")
lazy val typedTests = akkaModule("akka-typed-tests")
.dependsOn(typed, typedTestkit % "compile->compile;test->test")