2 * Copyright (c) 2015 Cisco 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.ActorRef;
11 import akka.actor.ActorSelection;
12 import org.opendaylight.controller.cluster.datastore.actors.DataTreeNotificationListenerRegistrationActor;
13 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
14 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 final class DataChangeListenerSupport extends AbstractDataListenerSupport<
20 AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>, RegisterChangeListener,
21 DelayedDataChangeListenerRegistration> {
23 DataChangeListenerSupport(final Shard shard) {
28 void doRegistration(final RegisterChangeListener message, final ActorRef registrationActor) {
29 final ActorSelection listenerActor = processListenerRegistrationMessage(message);
31 AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener =
32 new DataChangeListenerProxy(listenerActor);
34 log().debug("{}: Registering for path {}", persistenceId(), message.getPath());
36 final ShardDataTree shardDataTree = getShard().getDataStore();
37 shardDataTree.registerDataChangeListener(message.getPath(), listener, message.getScope(),
38 shardDataTree.readCurrentData(), registration -> registrationActor.tell(
39 new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () ->
40 removeListenerActor(listenerActor)), ActorRef.noSender()));
44 protected DelayedDataChangeListenerRegistration newDelayedListenerRegistration(RegisterChangeListener message,
45 ActorRef registrationActor) {
46 return new DelayedDataChangeListenerRegistration(message, registrationActor);
50 protected Object newRegistrationReplyMessage(ActorRef registrationActor) {
51 return new RegisterChangeListenerReply(registrationActor);
55 protected String logName() {
56 return "registerDataChangeListener";