Turn SchemaContextHandler into a component
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / handlers / SchemaContextHandler.java
index b8444132fd7503f51113a924fe9814868afb4300..2684032fc0487ef50ba52c88f5ba7b2b7e028c48 100644 (file)
@@ -17,7 +17,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
-import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -67,6 +66,10 @@ import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleLike;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -77,7 +80,8 @@ import org.slf4j.LoggerFactory;
 //        should live in MD-SAL and be a dynamic store fragment. As a first step we should be turning this into a
 //        completely standalone application.
 @Singleton
-public class SchemaContextHandler implements EffectiveModelContextListener, AutoCloseable {
+@Component(service = { })
+public final class SchemaContextHandler implements EffectiveModelContextListener, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(SchemaContextHandler.class);
 
     @VisibleForTesting
@@ -96,31 +100,25 @@ public class SchemaContextHandler implements EffectiveModelContextListener, Auto
     private static final NodeIdentifier MODULE_SCHEMA_NODEID =
         NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "schema").intern());
 
-    private final AtomicInteger moduleSetId = new AtomicInteger(0);
-
+    private final AtomicInteger moduleSetId = new AtomicInteger();
     private final DOMDataBroker domDataBroker;
-    private final DOMSchemaService domSchemaService;
-    private Registration listenerRegistration;
+    private final Registration listenerRegistration;
 
     private volatile EffectiveModelContext schemaContext;
 
     @Inject
-    public SchemaContextHandler(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService) {
+    @Activate
+    public SchemaContextHandler(@Reference final DOMDataBroker domDataBroker,
+            @Reference final DOMSchemaService domSchemaService) {
         this.domDataBroker = requireNonNull(domDataBroker);
-        this.domSchemaService = requireNonNull(domSchemaService);
-    }
-
-    @PostConstruct
-    public void init() {
         listenerRegistration = domSchemaService.registerSchemaContextListener(this);
     }
 
-    @Override
     @PreDestroy
+    @Deactivate
+    @Override
     public void close() {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-        }
+        listenerRegistration.close();
     }
 
     @Override