Refactor Register*ListenerReply classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataTreeChangeListenerSupport.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.RegisterDataTreeChangeListener;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
15
16 final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport<DOMDataTreeChangeListener,
17         RegisterDataTreeChangeListener> {
18
19     DataTreeChangeListenerSupport(final Shard shard) {
20         super(shard);
21     }
22
23     @Override
24     void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) {
25         final ActorSelection listenerActor = processListenerRegistrationMessage(message);
26
27         DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor);
28
29         log().debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath());
30
31         final ShardDataTree shardDataTree = getShard().getDataStore();
32         shardDataTree.registerTreeChangeListener(message.getPath(),
33                 listener, shardDataTree.readCurrentData(), registration -> registrationActor.tell(
34                         new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () ->
35                             removeListenerActor(listenerActor)), ActorRef.noSender()));
36     }
37
38     @Override
39     protected String logName() {
40         return "registerTreeChangeListener";
41     }
42 }

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