-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
akka-typed/src/main/scala/akka/typed/cluster/ddata/javadsl/DistributedData.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.typed.cluster.ddata.javadsl | ||
|
||
import akka.typed.ActorSystem | ||
import akka.typed.Extension | ||
import akka.typed.ExtensionId | ||
import akka.typed.ActorRef | ||
import akka.typed.cluster.ddata.scaladsl | ||
|
||
object DistributedData extends ExtensionId[DistributedData] { | ||
def get(system: ActorSystem[_]): DistributedData = apply(system) | ||
|
||
override def createExtension(system: ActorSystem[_]): DistributedData = | ||
new DistributedData(system) | ||
} | ||
|
||
/** | ||
* Akka extension for convenient configuration and use of the | ||
* [[Replicator]]. Configuration settings are defined in the | ||
* `akka.cluster.ddata` section, see `reference.conf`. | ||
* | ||
* This is using the same underlying `Replicator` instance as | ||
* [[akka.akka.cluster.ddata.DistributedData]] and that means that typed | ||
* and untyped actors can share the same data. | ||
*/ | ||
class DistributedData(system: ActorSystem[_]) extends Extension { | ||
|
||
/** | ||
* `ActorRef` of the [[Replicator]] . | ||
*/ | ||
val replicator: ActorRef[Replicator.Command] = | ||
scaladsl.DistributedData(system).replicator.narrow[Replicator.Command] | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
akka-typed/src/main/scala/akka/typed/cluster/ddata/scaladsl/DistributedData.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.typed.cluster.ddata.scaladsl | ||
|
||
import akka.typed.ActorSystem | ||
import akka.typed.Extension | ||
import akka.typed.ExtensionId | ||
import akka.typed.ActorRef | ||
import akka.actor.ExtendedActorSystem | ||
|
||
object DistributedData extends ExtensionId[DistributedData] { | ||
def get(system: ActorSystem[_]): DistributedData = apply(system) | ||
|
||
override def createExtension(system: ActorSystem[_]): DistributedData = | ||
new DistributedData(system) | ||
} | ||
|
||
/** | ||
* Akka extension for convenient configuration and use of the | ||
* [[Replicator]]. Configuration settings are defined in the | ||
* `akka.cluster.ddata` section, see `reference.conf`. | ||
* | ||
* This is using the same underlying `Replicator` instance as | ||
* [[akka.akka.cluster.ddata.DistributedData]] and that means that typed | ||
* and untyped actors can share the same data. | ||
*/ | ||
class DistributedData(system: ActorSystem[_]) extends Extension { | ||
import akka.typed.scaladsl.adapter._ | ||
|
||
private val untypedSystem = system.toUntyped.asInstanceOf[ExtendedActorSystem] | ||
private val config = system.settings.config.getConfig("akka.cluster.distributed-data") | ||
private val settings = ReplicatorSettings(config) | ||
|
||
/** | ||
* `ActorRef` of the [[Replicator]] . | ||
*/ | ||
val replicator: ActorRef[Replicator.Command] = { | ||
val configuredName = config.getString("name") | ||
val name = "typed" + configuredName.take(1).toUpperCase + configuredName.drop(1) | ||
|
||
val underlyingReplicator = akka.cluster.ddata.DistributedData(untypedSystem).replicator | ||
val replicatorBehavior = Replicator.behavior(settings, underlyingReplicator) | ||
|
||
untypedSystem.systemActorOf(PropsAdapter(replicatorBehavior), name) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters