Skip to content

Commit

Permalink
Supress log output on shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
  • Loading branch information
andrewfg committed Dec 10, 2023
1 parent 070de55 commit 14e3349
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.openhab.core.config.discovery.addon.AddonFinderService;
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;
Expand All @@ -33,31 +34,45 @@ public class KarafAddonFinderService implements AddonFinderService {
private final Logger logger = LoggerFactory.getLogger(KarafAddonFinderService.class);

private final FeaturesService featuresService;
private boolean deactivated;

@Activate
public KarafAddonFinderService(final @Reference FeaturesService featuresService) {
this.featuresService = featuresService;
}

@Deactivate
protected void deactivate() {
deactivated = true;
}

@Override
public void install(String id) {
try {
if (!featuresService.isInstalled(featuresService.getFeature(id))) {
featuresService.installFeature(id);
if (!deactivated) {
try {
if (!featuresService.isInstalled(featuresService.getFeature(id))) {
featuresService.installFeature(id);
}
} catch (Exception e) {
if (!deactivated) {
logger.error("Failed to install add-on suggestion finder {}", id, e);
}
}
} catch (Exception e) {
logger.error("Failed to install add-on suggestion finder {}", id, e);
}
}

@Override
public void uninstall(String id) {
try {
if (featuresService.isInstalled(featuresService.getFeature(id))) {
featuresService.uninstallFeature(id);
if (!deactivated) {
try {
if (featuresService.isInstalled(featuresService.getFeature(id))) {
featuresService.uninstallFeature(id);
}
} catch (Exception e) {
if (!deactivated) {
logger.error("Failed to uninstall add-on suggestion finder {}", id, e);
}
}
} catch (Exception e) {
logger.error("Failed to uninstall add-on suggestion finder {}", id, e);
}
}
}

0 comments on commit 14e3349

Please sign in to comment.