CDS: Implement front-end support for local transactions
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / LeaderLocalDelegateFactory.java
index 891c0bf6d426c5a65690e55772bb8d82c9f8c0b3..3f927736b5a8eaf5ee1be0e355a43f616fb2d9a1 100644 (file)
@@ -7,14 +7,55 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import akka.actor.ActorPath;
+import akka.actor.ActorRef;
+import akka.actor.ActorSelection;
+import akka.actor.Props;
+import com.google.common.base.Preconditions;
+
 /**
  * Base class for factories instantiating delegates which are local to the
  * shard leader.
  *
  * <D> delegate type
  * <M> message type
+ * <I> initial state type
  */
-abstract class LeaderLocalDelegateFactory<M, D> extends DelegateFactory<M, D> {
+abstract class LeaderLocalDelegateFactory<M, D, I> extends DelegateFactory<M, D, I> {
+    private final Shard shard;
+
+    protected LeaderLocalDelegateFactory(final Shard shard) {
+        this.shard = Preconditions.checkNotNull(shard);
+    }
+
+    protected final ActorRef getSelf() {
+        return shard.getSelf();
+    }
+
+    protected final Shard getShard() {
+        return shard;
+    }
+
+    protected final String persistenceId() {
+        return shard.persistenceId();
+    }
+
+    protected final void tellSender(final Object message) {
+        shard.getSender().tell(message, getSelf());
+    }
+
+    protected final ActorRef createActor(final Props props) {
+        return shard.getContext().actorOf(props);
+    }
+
+    protected final ActorSelection selectActor(ActorRef ref) {
+        return shard.getContext().system().actorSelection(ref.path());
+    }
+
+    protected final ActorSelection selectActor(ActorPath path) {
+        return shard.getContext().system().actorSelection(path);
+    }
+
     /**
      * Invoked whenever the local shard's leadership role changes.
      *