Implement DataChangeListener
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DistributedDataStore.java
index f64c6f1a8669888726f30bfe4099aa628365ccbb..58b22a9970cb452dd51f44e84b8b189f3f97e341 100644 (file)
@@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
 /**
  *
  */
-public class DistributedDataStore implements DOMStore, SchemaContextListener {
+public class DistributedDataStore implements DOMStore, SchemaContextListener, AutoCloseable {
 
     private static final Logger
         LOG = LoggerFactory.getLogger(DistributedDataStore.class);
@@ -56,15 +56,17 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener {
         InstanceIdentifier path, L listener,
         AsyncDataBroker.DataChangeScope scope) {
 
-        ActorRef dataChangeListenerActor = actorContext.getActorSystem().actorOf(DataChangeListener.props());
+        ActorRef dataChangeListenerActor = actorContext.getActorSystem().actorOf(
+            DataChangeListener.props(listener));
 
         Object result = actorContext.executeShardOperation(Shard.DEFAULT_NAME,
             new RegisterChangeListener(path, dataChangeListenerActor.path(),
                 AsyncDataBroker.DataChangeScope.BASE),
-            ActorContext.ASK_DURATION);
+            ActorContext.ASK_DURATION
+        );
 
         RegisterChangeListenerReply reply = (RegisterChangeListenerReply) result;
-        return new ListenerRegistrationProxy(reply.getListenerRegistrationPath());
+        return new DataChangeListenerRegistrationProxy(actorContext.actorSelection(reply.getListenerRegistrationPath()), listener);
     }
 
 
@@ -90,6 +92,12 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener {
     }
 
     @Override public void onGlobalContextUpdated(SchemaContext schemaContext) {
-        actorContext.getShardManager().tell(new UpdateSchemaContext(schemaContext), null);
+        actorContext.getShardManager().tell(
+            new UpdateSchemaContext(schemaContext), null);
+    }
+
+    @Override public void close() throws Exception {
+        actorContext.shutdown();
+
     }
 }