Merge "BUG-1041 cli proposal #1"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataChangeListenerRegistrationProxy.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.ActorSelection;
12 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 /**
19  * ListenerRegistrationProxy acts as a proxy for a ListenerRegistration that was done on a remote shard
20  * <p>
21  * Registering a DataChangeListener on the Data Store creates a new instance of the ListenerRegistrationProxy
22  * The ListenerRegistrationProxy talks to a remote ListenerRegistration actor.
23  * </p>
24  */
25 public class DataChangeListenerRegistrationProxy implements ListenerRegistration {
26     private final ActorSelection listenerRegistrationActor;
27     private final AsyncDataChangeListener listener;
28
29     public <L extends AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>>
30     DataChangeListenerRegistrationProxy(
31         ActorSelection listenerRegistrationActor,
32         L listener) {
33         this.listenerRegistrationActor = listenerRegistrationActor;
34         this.listener = listener;
35     }
36
37     @Override
38     public Object getInstance() {
39         return listener;
40     }
41
42     @Override
43     public void close() {
44         listenerRegistrationActor.tell(new CloseDataChangeListenerRegistration(), null);
45     }
46 }