2 * Copyright (c) 2017 Inocybe Technologies 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.Optional;
12 import com.google.common.base.Preconditions;
13 import java.util.function.Consumer;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
20 * Actor used to generate and publish DataTreeChange notifications.
22 * @author Thomas Pantelis
24 public class ShardDataTreeChangePublisherActor
25 extends ShardDataTreeNotificationPublisherActor<ShardDataTreeChangeListenerPublisher> {
27 private ShardDataTreeChangePublisherActor(final String name, final String logContext) {
28 super(new DefaultShardDataTreeChangeListenerPublisher(logContext), name, logContext);
32 protected void handleReceive(Object message) {
33 if (message instanceof RegisterListener) {
34 RegisterListener reg = (RegisterListener)message;
35 LOG.debug("{}: Received {}", logContext(), reg);
36 if (reg.initialState.isPresent()) {
37 DefaultShardDataTreeChangeListenerPublisher.notifySingleListener(reg.path, reg.listener,
38 reg.initialState.get(), logContext());
41 publisher().registerTreeChangeListener(reg.path, reg.listener, Optional.absent(), reg.onRegistration);
43 super.handleReceive(message);
47 static Props props(final String name, final String logContext) {
48 return Props.create(ShardDataTreeChangePublisherActor.class, name, logContext);
51 static class RegisterListener {
52 private final YangInstanceIdentifier path;
53 private final DOMDataTreeChangeListener listener;
54 private final Optional<DataTreeCandidate> initialState;
55 private final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration;
57 RegisterListener(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener,
58 final Optional<DataTreeCandidate> initialState,
59 final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
60 this.path = Preconditions.checkNotNull(path);
61 this.listener = Preconditions.checkNotNull(listener);
62 this.initialState = Preconditions.checkNotNull(initialState);
63 this.onRegistration = Preconditions.checkNotNull(onRegistration);
67 public String toString() {
68 return "RegisterListener [path=" + path + ", listener=" + listener + ", initialState present="
69 + initialState.isPresent() + "]";