Add more debug logging for DTCL registration/notification code paths
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / AbstractShardDataTreeNotificationPublisherActorProxy.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
10 import akka.actor.ActorContext;
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import javax.annotation.concurrent.NotThreadSafe;
14 import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Abstract base class for a ShardDataTreeNotificationPublisher that offloads the generation and publication
21  * of data tree notifications to an actor.
22  *
23  * @author Thomas Pantelis
24  */
25 @NotThreadSafe
26 abstract class AbstractShardDataTreeNotificationPublisherActorProxy implements ShardDataTreeNotificationPublisher {
27     protected final Logger log = LoggerFactory.getLogger(getClass());
28
29     private final ActorContext actorContext;
30     private final String actorName;
31     private final String logContext;
32     private ActorRef publisherActor;
33
34     protected AbstractShardDataTreeNotificationPublisherActorProxy(ActorContext actorContext, String actorName,
35             String logContext) {
36         this.actorContext = actorContext;
37         this.actorName = actorName;
38         this.logContext = logContext;
39     }
40
41     protected abstract Props props();
42
43     protected final String actorName() {
44         return actorName;
45     }
46
47     protected final String logContext() {
48         return logContext;
49     }
50
51     @Override
52     public void publishChanges(DataTreeCandidate candidate) {
53         publisherActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(candidate),
54                 ActorRef.noSender());
55     }
56
57     protected final ActorRef publisherActor() {
58         if (publisherActor == null) {
59             String dispatcher = new Dispatchers(actorContext.system().dispatchers()).getDispatcherPath(
60                     Dispatchers.DispatcherType.Notification);
61             publisherActor = actorContext.actorOf(props().withDispatcher(dispatcher).withMailbox(
62                     org.opendaylight.controller.cluster.datastore.utils.ActorContext.BOUNDED_MAILBOX), actorName);
63
64             log.debug("{}: Created publisher actor {} with name {}", logContext, publisherActor, actorName);
65         }
66
67         return publisherActor;
68     }
69 }