2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.schema.osgi.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.util.List;
13 import org.apache.karaf.features.DeploymentEvent;
14 import org.apache.karaf.features.DeploymentListener;
15 import org.apache.karaf.features.FeaturesService;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.concepts.Registration;
18 import org.opendaylight.yangtools.yang.binding.YangFeatureProvider;
19 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 final class KarafYangModuleInfoRegistry extends YangModuleInfoRegistry implements DeploymentListener {
24 private static final Logger LOG = LoggerFactory.getLogger(KarafYangModuleInfoRegistry.class);
26 private final RegularYangModuleInfoRegistry delegate;
28 private boolean scannerEnabled = false;
29 private boolean updatesEnabled = false;
31 private KarafYangModuleInfoRegistry(final RegularYangModuleInfoRegistry delegate) {
32 this.delegate = requireNonNull(delegate);
35 static @NonNull KarafYangModuleInfoRegistry create(final FeaturesService features,
36 final RegularYangModuleInfoRegistry delegate) {
37 final KarafYangModuleInfoRegistry ret = new KarafYangModuleInfoRegistry(delegate);
38 features.registerListener(ret);
43 public synchronized void deploymentEvent(final DeploymentEvent event) {
44 LOG.debug("Features service indicates {}", event);
46 case DEPLOYMENT_STARTED:
47 case BUNDLES_INSTALLED:
48 updatesEnabled = false;
49 LOG.debug("BindingRuntimeContext updates disabled");
51 case BUNDLES_RESOLVED:
52 case DEPLOYMENT_FINISHED:
54 updatesEnabled = true;
55 LOG.debug("BindingRuntimeContext updates enabled");
57 delegate.enableScannerAndUpdate();
63 synchronized void scannerUpdate() {
65 delegate.scannerUpdate();
70 synchronized void enableScannerAndUpdate() {
71 scannerEnabled = true;
73 delegate.enableScannerAndUpdate();
78 Registration registerBundle(final List<YangModuleInfo> moduleInfos,
79 final List<YangFeatureProvider<?>> featureProviders) {
80 return delegate.registerBundle(moduleInfos, featureProviders);
84 synchronized void close() {
89 synchronized void scannerShutdown() {
90 scannerEnabled = false;
91 delegate.scannerShutdown();