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 com.google.common.base.Stopwatch;
11 import java.util.concurrent.TimeUnit;
12 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
16 * Actor used to generate and publish data tree notifications. This is used to offload the potentially
17 * expensive notification generation from the Shard actor.
19 * @author Thomas Pantelis
21 public class ShardDataTreeNotificationPublisherActor<T extends ShardDataTreeNotificationPublisher>
22 extends AbstractUntypedActor {
23 private final T publisher;
24 private final Stopwatch timer = Stopwatch.createUnstarted();
25 private final String name;
26 private final String logContext;
28 protected ShardDataTreeNotificationPublisherActor(final T publisher, final String name, final String logContext) {
29 this.publisher = publisher;
31 this.logContext = logContext;
34 protected T publisher() {
38 protected String logContext() {
43 protected void handleReceive(Object message) {
44 if (message instanceof PublishNotifications) {
45 PublishNotifications toPublish = (PublishNotifications)message;
49 publisher.publishChanges(toPublish.candidate, logContext);
51 long elapsedTime = timer.elapsed(TimeUnit.MILLISECONDS);
53 if (elapsedTime >= ShardDataTreeNotificationPublisher.PUBLISH_DELAY_THRESHOLD_IN_MS) {
54 LOG.warn("{}: Generation of change events for {} took longer than expected. Elapsed time: {}",
55 logContext, name, timer);
57 LOG.debug("{}: Elapsed time for generation of change events for {}: {}", logContext, name, timer);
65 static class PublishNotifications {
66 private final DataTreeCandidate candidate;
68 PublishNotifications(DataTreeCandidate candidate) {
69 this.candidate = candidate;