Merge "Migrate toaster samples to config-subsystem"
[controller.git] / opendaylight / md-sal / sal-restconf-broker / src / main / java / org / opendaylight / controller / sal / restconf / broker / impl / DataBrokerServiceImpl.java
index e6659c226520f2cd7cf7c9de03716d333d9de7f5..003ad9853a32a20d7df06262a6c2490e7f6dfe0d 100644 (file)
@@ -7,14 +7,13 @@
  */
 package org.opendaylight.controller.sal.restconf.broker.impl;
 
-import com.google.common.base.Optional;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+
 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;
 import org.opendaylight.controller.sal.restconf.broker.listeners.RemoteDataChangeNotificationListener;
 import org.opendaylight.controller.sal.restconf.broker.tools.RemoteStreamTools;
 import org.opendaylight.controller.sal.restconf.broker.transactions.RemoteDataModificationTransaction;
@@ -22,66 +21,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.SalRemoteService;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
 import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo;
 import org.opendaylight.yangtools.restconf.client.api.event.ListenableEventStreamContext;
 import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.DataRoot;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Optional;
+
 public class DataBrokerServiceImpl implements DataBrokerService  {
 
     private static final Logger logger = LoggerFactory.getLogger(DataBrokerServiceImpl.class.toString());
-    private RestconfClientContext restconfClientContext;
-    private SalRemoteService salRemoteService;
+    private final RestconfClientContext restconfClientContext;
+    private final SalRemoteService salRemoteService;
 
     public DataBrokerServiceImpl(RestconfClientContext restconfClientContext) {
         this.restconfClientContext = restconfClientContext;
         this.salRemoteService =  this.restconfClientContext.getRpcServiceContext(SalRemoteService.class).getRpcService();
     }
-    @Override
-    public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public DataObject getData(InstanceIdentifier<? extends DataObject> data) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public DataObject getConfigurationData(InstanceIdentifier<?> data) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
 
     @Override
     public DataModificationTransaction beginTransaction() {
@@ -91,16 +53,6 @@ public class DataBrokerServiceImpl implements DataBrokerService  {
         return remoteDataModificationTransaction;
     }
 
-    @Override
-    public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
     @Override
     public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
         try {
@@ -147,22 +99,12 @@ public class DataBrokerServiceImpl implements DataBrokerService  {
         final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext,streamName);
         ListenableEventStreamContext restConfListenableEventStreamContext = restconfClientContext.getEventStreamContext(desiredEventStream.get(streamName));
         RemoteDataChangeNotificationListener remoteDataChangeNotificationListener = new RemoteDataChangeNotificationListener(listener);
-        restConfListenableEventStreamContext.registerNotificationListener(remoteDataChangeNotificationListener);
-        return new SalRemoteDataListenerRegistration(listener);
-    }
-
-    private class SalRemoteDataListenerRegistration implements ListenerRegistration<DataChangeListener> {
-        private DataChangeListener dataChangeListener;
-        public SalRemoteDataListenerRegistration(DataChangeListener dataChangeListener){
-            this.dataChangeListener = dataChangeListener;
-        }
-        @Override
-        public DataChangeListener getInstance() {
-            return this.dataChangeListener;
-        }
-        @Override
-        public void close() throws Exception {
-            //noop
-        }
+        final ListenerRegistration<?> reg = restConfListenableEventStreamContext.registerNotificationListener(remoteDataChangeNotificationListener);
+        return new AbstractListenerRegistration<DataChangeListener>(listener) {
+            @Override
+            protected void removeRegistration() {
+                reg.close();
+            }
+        };
     }
 }