fde1bf691484b35231608d552af56da88a557631
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataChangeListenerSupport.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
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;
18
19 final class DataChangeListenerSupport extends AbstractDataListenerSupport<
20         AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>, RegisterChangeListener> {
21
22     DataChangeListenerSupport(final Shard shard) {
23         super(shard);
24     }
25
26     @Override
27     void doRegistration(final RegisterChangeListener message, final ActorRef registrationActor) {
28         final ActorSelection listenerActor = processListenerRegistrationMessage(message);
29
30         AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener =
31                 new DataChangeListenerProxy(listenerActor);
32
33         log().debug("{}: Registering for path {}", persistenceId(), message.getPath());
34
35         final ShardDataTree shardDataTree = getShard().getDataStore();
36         shardDataTree.registerDataChangeListener(message.getPath(), listener, message.getScope(),
37                 shardDataTree.readCurrentData(), registration -> registrationActor.tell(
38                         new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () ->
39                             removeListenerActor(listenerActor)), ActorRef.noSender()));
40     }
41
42     @Override
43     protected Object newRegistrationReplyMessage(ActorRef registrationActor) {
44         return new RegisterChangeListenerReply(registrationActor);
45     }
46
47     @Override
48     protected String logName() {
49         return "registerDataChangeListener";
50     }
51 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.