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.RegisterDataTreeChangeListener;
14 import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
17 final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport<DOMDataTreeChangeListener,
18 RegisterDataTreeChangeListener, DelayedDataTreeListenerRegistration> {
20 DataTreeChangeListenerSupport(final Shard shard) {
25 void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) {
26 final ActorSelection listenerActor = processListenerRegistrationMessage(message);
28 DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor);
30 log().debug("{}: Registering for path {}", persistenceId(), message.getPath());
32 final ShardDataTree shardDataTree = getShard().getDataStore();
33 shardDataTree.registerTreeChangeListener(message.getPath(),
34 listener, shardDataTree.readCurrentData(), registration -> registrationActor.tell(
35 new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () ->
36 removeListenerActor(listenerActor)), ActorRef.noSender()));
40 protected DelayedDataTreeListenerRegistration newDelayedListenerRegistration(
41 RegisterDataTreeChangeListener message, ActorRef registrationActor) {
42 return new DelayedDataTreeListenerRegistration(message, registrationActor);
46 protected Object newRegistrationReplyMessage(ActorRef registrationActor) {
47 return new RegisterDataTreeChangeListenerReply(registrationActor);
51 protected String logName() {
52 return "registerTreeChangeListener";