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 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;
19 * Abstract base class for a ShardDataTreeNotificationPublisher that offloads the generation and publication
20 * of data tree notifications to an actor.
22 * @author Thomas Pantelis
25 abstract class AbstractShardDataTreeNotificationPublisherActorProxy implements ShardDataTreeNotificationPublisher {
26 private static final Logger LOG = LoggerFactory.getLogger(AbstractShardDataTreeNotificationPublisherActorProxy.class);
28 private final ActorContext actorContext;
29 private final String actorName;
30 private ActorRef notifierActor;
32 protected AbstractShardDataTreeNotificationPublisherActorProxy(ActorContext actorContext, String actorName) {
33 this.actorContext = actorContext;
34 this.actorName = actorName;
37 protected AbstractShardDataTreeNotificationPublisherActorProxy(
38 AbstractShardDataTreeNotificationPublisherActorProxy other) {
39 this.actorContext = null;
40 this.actorName = null;
41 this.notifierActor = other.getNotifierActor();
44 protected abstract ShardDataTreeNotificationPublisher getDelegatePublisher();
47 public void publishChanges(DataTreeCandidate candidate, String logContext) {
48 getNotifierActor().tell(new ShardDataTreeNotificationPublisherActor.PublishNotifications(
49 getDelegatePublisher(), candidate, logContext), ActorRef.noSender());
52 private ActorRef getNotifierActor() {
53 if(notifierActor == null) {
54 LOG.debug("Creating actor {}", actorName);
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);