Refactor Register*ListenerReply classes
[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.md.sal.common.api.data.AsyncDataChangeListener;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 final class DataChangeListenerSupport extends AbstractDataListenerSupport<
19         AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>, RegisterChangeListener> {
20
21     DataChangeListenerSupport(final Shard shard) {
22         super(shard);
23     }
24
25     @Override
26     void doRegistration(final RegisterChangeListener message, final ActorRef registrationActor) {
27         final ActorSelection listenerActor = processListenerRegistrationMessage(message);
28
29         AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener =
30                 new DataChangeListenerProxy(listenerActor);
31
32         log().debug("{}: Registering for path {}", persistenceId(), message.getPath());
33
34         final ShardDataTree shardDataTree = getShard().getDataStore();
35         shardDataTree.registerDataChangeListener(message.getPath(), listener, message.getScope(),
36                 shardDataTree.readCurrentData(), registration -> registrationActor.tell(
37                         new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () ->
38                             removeListenerActor(listenerActor)), ActorRef.noSender()));
39     }
40
41     @Override
42     protected String logName() {
43         return "registerDataChangeListener";
44     }
45 }

©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.