2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore;
10 import akka.actor.ActorContext;
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import org.opendaylight.controller.cluster.common.actor.Dispatchers;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Abstract base class for a ShardDataTreeNotificationPublisher that offloads the generation and publication
21 * of data tree notifications to an actor. This class is NOT thread-safe.
23 * @author Thomas Pantelis
25 abstract class AbstractShardDataTreeNotificationPublisherActorProxy implements ShardDataTreeNotificationPublisher {
26 @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE")
27 protected final Logger log = LoggerFactory.getLogger(getClass());
29 private final ActorContext actorContext;
30 private final String actorName;
31 private final String logContext;
32 private ActorRef publisherActor;
34 protected AbstractShardDataTreeNotificationPublisherActorProxy(final ActorContext actorContext,
35 final String actorName, final String logContext) {
36 this.actorContext = actorContext;
37 this.actorName = actorName;
38 this.logContext = logContext;
41 protected abstract Props props();
43 protected final String actorName() {
47 protected final String logContext() {
52 public void publishChanges(final DataTreeCandidate candidate) {
53 publisherActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(candidate),
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), actorName);
63 log.debug("{}: Created publisher actor {} with name {}", logContext, publisherActor, actorName);
66 return publisherActor;