diff --git a/akka-typed/src/main/scala/akka/typed/cluster/ActorRefResolver.scala b/akka-typed/src/main/scala/akka/typed/cluster/ActorRefResolver.scala new file mode 100644 index 0000000000..a5460ec1d0 --- /dev/null +++ b/akka-typed/src/main/scala/akka/typed/cluster/ActorRefResolver.scala @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2017 Lightbend Inc. + */ +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 path’s 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) +} + diff --git a/build.sbt b/build.sbt index 189521ed83..5db6120695 100644 --- a/build.sbt +++ b/build.sbt @@ -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")