Remove ListenerRegistration protobuff messages
[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) throws Exception {
34         if (message instanceof CloseDataChangeListenerRegistration) {
35             closeListenerRegistration();
36         }
37     }
38
39     public static Props props(
40         final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>> registration) {
41         return Props.create(new DataChangeListenerRegistrationCreator(registration));
42     }
43
44     private void closeListenerRegistration() {
45         registration.close();
46         getSender().tell(CloseDataChangeListenerRegistrationReply.INSTANCE, getSelf());
47         getSelf().tell(PoisonPill.getInstance(), getSelf());
48     }
49
50     private static class DataChangeListenerRegistrationCreator
51                                             implements Creator<DataChangeListenerRegistrationActor> {
52         private static final long serialVersionUID = 1L;
53         final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
54                                                            NormalizedNode<?, ?>>> registration;
55
56         DataChangeListenerRegistrationCreator(
57                 ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
58                                                              NormalizedNode<?, ?>>> registration) {
59             this.registration = registration;
60         }
61
62         @Override
63         public DataChangeListenerRegistrationActor create() throws Exception {
64             return new DataChangeListenerRegistrationActor(registration);
65         }
66     }
67 }

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