Do not use ListenerRegistration
[mdsal.git] / dom / mdsal-dom-schema-osgi / src / main / java / org / opendaylight / mdsal / dom / schema / osgi / impl / OSGiModelRuntime.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 package org.opendaylight.mdsal.dom.schema.osgi.impl;
9
10 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
11 import org.osgi.framework.BundleContext;
12 import org.osgi.service.component.ComponentFactory;
13 import org.osgi.service.component.annotations.Activate;
14 import org.osgi.service.component.annotations.Component;
15 import org.osgi.service.component.annotations.Deactivate;
16 import org.osgi.service.component.annotations.Reference;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 @Component(immediate = true)
21 public final class OSGiModelRuntime {
22     private static final Logger LOG = LoggerFactory.getLogger(OSGiModelRuntime.class);
23
24     private final YangModuleInfoRegistry moduleRegistry;
25     private final YangModuleInfoScanner bundleTracker;
26
27     @Activate
28     public OSGiModelRuntime(@Reference final YangParserFactory parserFactory,
29             @Reference(target = "(component.factory=" + OSGiModuleInfoSnapshotImpl.FACTORY_NAME + ")")
30             final ComponentFactory<OSGiModuleInfoSnapshotImpl> contextFactory,
31             final BundleContext ctx) {
32         LOG.info("Model Runtime starting");
33         moduleRegistry = YangModuleInfoRegistry.create(ctx, contextFactory, parserFactory);
34         bundleTracker = new YangModuleInfoScanner(ctx, moduleRegistry);
35         bundleTracker.open();
36         moduleRegistry.enableScannerAndUpdate();
37         LOG.info("Model Runtime started");
38     }
39
40     @Deactivate
41     void deactivate() {
42         LOG.info("Model Runtime stopping");
43         moduleRegistry.close();
44         bundleTracker.close();
45         LOG.info("Model Runtime stopped");
46     }
47 }