29e4a1a9fcfb20ae33091ca0ebc9e90264a676d0
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataChangeListenerRegistrationActor.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.controller.cluster.datastore;
10
11 import akka.actor.PoisonPill;
12 import akka.actor.Props;
13 import akka.japi.Creator;
14 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
15 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration;
16 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistrationReply;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21
22 public class DataChangeListenerRegistrationActor extends AbstractUntypedActor {
23
24     private final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>>
25         registration;
26
27     public DataChangeListenerRegistrationActor(
28         ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>> registration) {
29         this.registration = registration;
30     }
31
32     @Override
33     public void handleReceive(Object message) {
34         if (message instanceof CloseDataChangeListenerRegistration) {
35             closeListenerRegistration();
36         } else {
37             unknownMessage(message);
38         }
39     }
40
41     public static Props props(
42         final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>> registration) {
43         return Props.create(new DataChangeListenerRegistrationCreator(registration));
44     }
45
46     private void closeListenerRegistration() {
47         registration.close();
48
49         if(isValidSender(getSender())) {
50             getSender().tell(CloseDataChangeListenerRegistrationReply.INSTANCE, getSelf());
51         }
52
53         getSelf().tell(PoisonPill.getInstance(), getSelf());
54     }
55
56     private static class DataChangeListenerRegistrationCreator
57                                             implements Creator<DataChangeListenerRegistrationActor> {
58         private static final long serialVersionUID = 1L;
59         final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
60                                                            NormalizedNode<?, ?>>> registration;
61
62         DataChangeListenerRegistrationCreator(
63                 ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
64                                                              NormalizedNode<?, ?>>> registration) {
65             this.registration = registration;
66         }
67
68         @Override
69         public DataChangeListenerRegistrationActor create() throws Exception {
70             return new DataChangeListenerRegistrationActor(registration);
71         }
72     }
73 }

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