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.Props;
11 import com.google.common.base.Stopwatch;
12 import java.util.concurrent.TimeUnit;
13 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
17 * Actor used to generate and publish data tree notifications. This is used to offload the potentially
18 * expensive notification generation from the Shard actor.
20 * @author Thomas Pantelis
22 public class ShardDataTreeNotificationPublisherActor extends AbstractUntypedActor {
23 private final Stopwatch timer = Stopwatch.createUnstarted();
24 private final String name;
26 private ShardDataTreeNotificationPublisherActor(String name) {
31 protected void handleReceive(Object message) {
32 if (message instanceof PublishNotifications) {
33 PublishNotifications publisher = (PublishNotifications)message;
39 long elapsedTime = timer.elapsed(TimeUnit.MILLISECONDS);
41 if (elapsedTime >= ShardDataTreeNotificationPublisher.PUBLISH_DELAY_THRESHOLD_IN_MS) {
42 LOG.warn("{}: Generation of change events for {} took longer than expected. Elapsed time: {}",
43 publisher.logContext, name, timer);
45 LOG.debug("{}: Elapsed time for generation of change events for {}: {}", publisher.logContext,
54 static Props props(String notificationType) {
55 return Props.create(ShardDataTreeNotificationPublisherActor.class, notificationType);
58 static class PublishNotifications {
59 private final ShardDataTreeNotificationPublisher publisher;
60 private final DataTreeCandidate candidate;
61 private final String logContext;
63 PublishNotifications(ShardDataTreeNotificationPublisher publisher, DataTreeCandidate candidate,
65 this.publisher = publisher;
66 this.candidate = candidate;
67 this.logContext = logContext;
70 private void publish() {
71 publisher.publishChanges(candidate, logContext);