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(), name, logContext);
32 protected void handleReceive(Object message) {
33 if (message instanceof RegisterListener) {
34 RegisterListener reg = (RegisterListener)message;
35 if (reg.initialState.isPresent()) {
36 DefaultShardDataTreeChangeListenerPublisher.notifySingleListener(reg.path, reg.listener,
37 reg.initialState.get());
40 publisher().registerTreeChangeListener(reg.path, reg.listener, Optional.absent(), reg.onRegistration);
42 super.handleReceive(message);
46 static Props props(final String name, final String logContext) {
47 return Props.create(ShardDataTreeChangePublisherActor.class, name, logContext);
50 static class RegisterListener {
51 private final YangInstanceIdentifier path;
52 private final DOMDataTreeChangeListener listener;
53 private final Optional<DataTreeCandidate> initialState;
54 private final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration;
56 RegisterListener(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener,
57 final Optional<DataTreeCandidate> initialState,
58 final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
59 this.path = Preconditions.checkNotNull(path);
60 this.listener = Preconditions.checkNotNull(listener);
61 this.initialState = Preconditions.checkNotNull(initialState);
62 this.onRegistration = Preconditions.checkNotNull(onRegistration);