Remove use of {String,UUID}Identifier
[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 javax.annotation.concurrent.NotThreadSafe;
13 import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Abstract base class for a ShardDataTreeNotificationPublisher that offloads the generation and publication
20  * of data tree notifications to an actor.
21  *
22  * @author Thomas Pantelis
23  */
24 @NotThreadSafe
25 abstract class AbstractShardDataTreeNotificationPublisherActorProxy implements ShardDataTreeNotificationPublisher {
26     private static final Logger LOG = LoggerFactory.getLogger(AbstractShardDataTreeNotificationPublisherActorProxy.class);
27
28     private final ActorContext actorContext;
29     private final String actorName;
30     private ActorRef notifierActor;
31
32     protected AbstractShardDataTreeNotificationPublisherActorProxy(ActorContext actorContext, String actorName) {
33         this.actorContext = actorContext;
34         this.actorName = actorName;
35     }
36
37     protected AbstractShardDataTreeNotificationPublisherActorProxy(
38             AbstractShardDataTreeNotificationPublisherActorProxy other) {
39         this.actorContext = null;
40         this.actorName = null;
41         this.notifierActor = other.getNotifierActor();
42     }
43
44     protected abstract ShardDataTreeNotificationPublisher getDelegatePublisher();
45
46     @Override
47     public void publishChanges(DataTreeCandidate candidate, String logContext) {
48         getNotifierActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(
49                 getDelegatePublisher(), candidate, logContext), ActorRef.noSender());
50     }
51
52     private ActorRef getNotifierActor() {
53         if(notifierActor == null) {
54             LOG.debug("Creating actor {}", actorName);
55
56             String dispatcher = new Dispatchers(actorContext.system().dispatchers()).getDispatcherPath(
57                     Dispatchers.DispatcherType.Notification);
58             notifierActor = actorContext.actorOf(ShardDataTreeNotificationPublisherActor.props()
59                     .withDispatcher(dispatcher).withMailbox(
60                             org.opendaylight.controller.cluster.datastore.utils.ActorContext.BOUNDED_MAILBOX), actorName);
61         }
62
63         return notifierActor;
64     }
65 }