Introduce restconf.server.{api,spi,mdsal}
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / mdsal / streams / dtcl / DataTreeChangeSource.java
similarity index 80%
rename from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/DataTreeChangeSource.java
rename to restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/DataTreeChangeSource.java
index 3e3d37520afd103d25a359ca81c2930e859f7393..377d02f6fcdc36c1e13dbaf32de65af0198f7159 100644 (file)
@@ -5,10 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.restconf.nb.rfc8040.streams;
+package org.opendaylight.restconf.server.mdsal.streams.dtcl;
 
 import static java.util.Objects.requireNonNull;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.ImmutableMap;
 import java.time.Instant;
@@ -16,13 +17,13 @@ import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStream.EncodingName;
-import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStream.Sink;
-import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStream.Source;
+import org.opendaylight.restconf.server.spi.RestconfStream;
+import org.opendaylight.restconf.server.spi.RestconfStream.EncodingName;
+import org.opendaylight.restconf.server.spi.RestconfStream.Sink;
+import org.opendaylight.restconf.server.spi.RestconfStream.Source;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
@@ -30,6 +31,7 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
 /**
  * A {@link RestconfStream} reporting changes on a particular data tree.
  */
+@VisibleForTesting
 public final class DataTreeChangeSource extends Source<List<DataTreeCandidate>> {
     private static final ImmutableMap<EncodingName, DataTreeCandidateFormatterFactory> ENCODINGS = ImmutableMap.of(
         EncodingName.RFC8040_JSON, JSONDataTreeCandidateFormatter.FACTORY,
@@ -40,18 +42,13 @@ public final class DataTreeChangeSource extends Source<List<DataTreeCandidate>>
     private final @NonNull LogicalDatastoreType datastore;
     private final @NonNull YangInstanceIdentifier path;
 
-    DataTreeChangeSource(final DatabindProvider databindProvider, final DOMDataBroker dataBroker,
+    public DataTreeChangeSource(final DatabindProvider databindProvider, final DOMDataTreeChangeService changeService,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path) {
         super(ENCODINGS);
         this.databindProvider = requireNonNull(databindProvider);
+        this.changeService = requireNonNull(changeService);
         this.datastore = requireNonNull(datastore);
         this.path = requireNonNull(path);
-
-        final var dtcs = dataBroker.getExtensions().getInstance(DOMDataTreeChangeService.class);
-        if (dtcs == null) {
-            throw new UnsupportedOperationException("DOMDataBroker does not support the DOMDataTreeChangeService");
-        }
-        changeService = dtcs;
     }
 
     @Override