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 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;
20 * Abstract base class for a ShardDataTreeNotificationPublisher that offloads the generation and publication
21 * of data tree notifications to an actor.
23 * @author Thomas Pantelis
26 abstract class AbstractShardDataTreeNotificationPublisherActorProxy implements ShardDataTreeNotificationPublisher {
27 private static final Logger LOG = LoggerFactory.getLogger(
28 AbstractShardDataTreeNotificationPublisherActorProxy.class);
30 private final ActorContext actorContext;
31 private final String actorName;
32 private final String logContext;
33 private ActorRef notifierActor;
35 protected AbstractShardDataTreeNotificationPublisherActorProxy(ActorContext actorContext, String actorName,
37 this.actorContext = actorContext;
38 this.actorName = actorName;
39 this.logContext = logContext;
42 protected abstract Props props();
44 protected final String actorName() {
48 protected final String logContext() {
53 public void publishChanges(DataTreeCandidate candidate, String logContext) {
54 notifierActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(candidate),
58 protected final ActorRef notifierActor() {
59 if (notifierActor == null) {
60 LOG.debug("Creating actor {}", actorName);
62 String dispatcher = new Dispatchers(actorContext.system().dispatchers()).getDispatcherPath(
63 Dispatchers.DispatcherType.Notification);
64 notifierActor = actorContext.actorOf(props().withDispatcher(dispatcher).withMailbox(
65 org.opendaylight.controller.cluster.datastore.utils.ActorContext.BOUNDED_MAILBOX), actorName);