Improve orphan transaction logging
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / AbstractShardDataTreeNotificationPublisherActorProxy.java
index 61a22d4c2c958be3dddd5a0197710f3339b9919f..6b348fb76f904e6de35e105b0bc46cf796aabe32 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore;
 
 import akka.actor.ActorContext;
 import akka.actor.ActorRef;
+import akka.actor.Props;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
@@ -23,41 +24,45 @@ import org.slf4j.LoggerFactory;
  */
 @NotThreadSafe
 abstract class AbstractShardDataTreeNotificationPublisherActorProxy implements ShardDataTreeNotificationPublisher {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractShardDataTreeNotificationPublisherActorProxy.class);
+    private static final Logger LOG = LoggerFactory.getLogger(
+            AbstractShardDataTreeNotificationPublisherActorProxy.class);
 
     private final ActorContext actorContext;
     private final String actorName;
+    private final String logContext;
     private ActorRef notifierActor;
 
-    protected AbstractShardDataTreeNotificationPublisherActorProxy(ActorContext actorContext, String actorName) {
+    protected AbstractShardDataTreeNotificationPublisherActorProxy(ActorContext actorContext, String actorName,
+            String logContext) {
         this.actorContext = actorContext;
         this.actorName = actorName;
+        this.logContext = logContext;
     }
 
-    protected AbstractShardDataTreeNotificationPublisherActorProxy(
-            AbstractShardDataTreeNotificationPublisherActorProxy other) {
-        this.actorContext = null;
-        this.actorName = null;
-        this.notifierActor = other.getNotifierActor();
+    protected abstract Props props();
+
+    protected final String actorName() {
+        return actorName;
     }
 
-    protected abstract ShardDataTreeNotificationPublisher getDelegatePublisher();
+    protected final String logContext() {
+        return logContext;
+    }
 
     @Override
     public void publishChanges(DataTreeCandidate candidate, String logContext) {
-        getNotifierActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(
-                getDelegatePublisher(), candidate, logContext), ActorRef.noSender());
+        notifierActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(candidate),
+                ActorRef.noSender());
     }
 
-    private ActorRef getNotifierActor() {
-        if(notifierActor == null) {
+    protected final ActorRef notifierActor() {
+        if (notifierActor == null) {
             LOG.debug("Creating actor {}", actorName);
 
             String dispatcher = new Dispatchers(actorContext.system().dispatchers()).getDispatcherPath(
                     Dispatchers.DispatcherType.Notification);
-            notifierActor = actorContext.actorOf(ShardDataTreeNotificationPublisherActor.props(actorName)
-                    .withDispatcher(dispatcher).withMailbox(
-                            org.opendaylight.controller.cluster.datastore.utils.ActorContext.BOUNDED_MAILBOX), actorName);
+            notifierActor = actorContext.actorOf(props().withDispatcher(dispatcher).withMailbox(
+                    org.opendaylight.controller.cluster.datastore.utils.ActorContext.BOUNDED_MAILBOX), actorName);
         }
 
         return notifierActor;