+
+ private void createTransactionIfMissing(ActorContext actorContext, YangInstanceIdentifier path) {
+ String shardName = ShardStrategyFactory.getStrategy(path).findShard(path);
+
+ TransactionContext transactionContext =
+ remoteTransactionPaths.get(shardName);
+
+ if(transactionContext != null){
+ // A transaction already exists with that shard
+ return;
+ }
+
+ Object response = actorContext.executeShardOperation(shardName, new CreateTransaction(identifier).toSerializable(), ActorContext.ASK_DURATION);
+ if(response.getClass().equals(CreateTransactionReply.SERIALIZABLE_CLASS)){
+ CreateTransactionReply reply = CreateTransactionReply.fromSerializable(response);
+ String transactionPath = actorContext.getRemoteActorPath(shardName, reply.getTransactionPath());
+
+ ActorSelection transactionActor = actorContext.actorSelection(transactionPath);
+ transactionContext = new TransactionContext(shardName, transactionPath, transactionActor);
+
+ remoteTransactionPaths.put(shardName, transactionContext);
+ }
+ }
+
+
+ private class TransactionContext {
+ private final String shardName;
+ private final String actorPath;
+ private final ActorSelection actor;
+
+
+ private TransactionContext(String shardName, String actorPath,
+ ActorSelection actor) {
+ this.shardName = shardName;
+ this.actorPath = actorPath;
+ this.actor = actor;
+ }
+
+
+ public String getShardName() {
+ return shardName;
+ }
+
+ public String getActorPath() {
+ return actorPath;
+ }
+
+ public ActorSelection getActor() {
+ return actor;
+ }
+
+ public String getResolvedCohortPath(String cohortPath){
+ return actorContext.resolvePath(actorPath, cohortPath);
+ }
+ }
+