Refactor OSGi ModuleInfoSnapshot/BindingRuntimeContext
[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.model.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     @Reference
25     YangParserFactory parserFactory = null;
26     @Reference(target = "(component.factory=" + OSGiModuleInfoSnapshotImpl.FACTORY_NAME + ")")
27     ComponentFactory contextFactory = null;
28
29     private YangModuleInfoScanner bundleTracker = null;
30     private YangModuleInfoRegistry moduleRegistry = null;
31
32     @Activate
33     void activate(final BundleContext ctx) {
34         LOG.info("Model Runtime starting");
35         moduleRegistry = YangModuleInfoRegistry.create(ctx, contextFactory, parserFactory);
36         bundleTracker = new YangModuleInfoScanner(ctx, moduleRegistry);
37         bundleTracker.open();
38         moduleRegistry.enableScannerAndUpdate();
39         LOG.info("Model Runtime started");
40     }
41
42     @Deactivate
43     void deactivate() {
44         LOG.info("Model Runtime stopping");
45         moduleRegistry.close();
46         bundleTracker.close();
47         LOG.info("Model Runtime stopped");
48     }
49 }