Source:
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) { if (!settingsService.getModuleSettings().isRestartModuleAfterTimeout()) { return; } String symbolicName = event.getBundle().getSymbolicName(); if (event instanceof OsgiBundleContextFailedEvent) { if (!restartedBundles.contains(symbolicName)) { OsgiBundleContextFailedEvent failedEvent = (OsgiBundleContextFailedEvent) event; final String failureCauseMsg = failedEvent.getFailureCause().getMessage(); Bundle bundle = failedEvent.getBundle(); if (!failureCauseMsg.startsWith(String.format(TIMEOUT_EXCEPTION_MESSAGE, symbolicName))) { return; } LOGGER.error("Received context failed event from {}", event, symbolicName); LOGGER.error("{} failed to start due to {}", symbolicName, failureCauseMsg); logFailReport(symbolicName, failureCauseMsg, BundleRestartStatus.IN_PROGRESS); restartedBundles.add(symbolicName); LOGGER.info("Trying to restart bundle", symbolicName); try { bundle.stop(); bundle.start(); } catch (BundleException e) { LOGGER.error("Cannot restart bundle due to {}", symbolicName, e); } } else { OsgiBundleContextFailedEvent failedEvent = (OsgiBundleContextFailedEvent) event; LOGGER.error("Cannot restart bundle due to {}", symbolicName, failedEvent.getFailureCause().getMessage()); sendMessage("CRITICAL", String.format(CRITICAL_MESSAGE, symbolicName)); updateReportStatus(symbolicName, BundleRestartStatus.ERROR); } } else if (event instanceof OsgiBundleContextRefreshedEvent && restartedBundles.contains(symbolicName) ) { sendMessage("WARN", String.format(WARN_MESSAGE, symbolicName)); updateReportStatus(symbolicName, BundleRestartStatus.SUCCESS); restartedBundles.remove(symbolicName); } }

Target:
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) { if (!settingsService.getModuleSettings().isRestartModuleAfterTimeout()) { return; } String symbolicName = event.getBundle().getSymbolicName(); if (event instanceof OsgiBundleContextFailedEvent) { if (!restartedBundles.contains(symbolicName)) { OsgiBundleContextFailedEvent failedEvent = (OsgiBundleContextFailedEvent) event; final String failureCauseMsg = failedEvent.getFailureCause().getMessage(); Bundle bundle = failedEvent.getBundle(); if (!failureCauseMsg.startsWith(String.format(TIMEOUT_EXCEPTION_MESSAGE, symbolicName))) { return; } LOGGER.error("Received context failed event from {}", event, symbolicName); LOGGER.error("{} failed to start due to {}", symbolicName, failureCauseMsg); logFailReport(symbolicName, failureCauseMsg, BundleRestartStatus.IN_PROGRESS); restartedBundles.add(symbolicName); LOGGER.info("Trying to restart bundle", symbolicName); try { bundle.stop(); bundle.start(); } catch (BundleException e) { LOGGER.error("Cannot restart bundle due to {}", symbolicName, e); } } else { LOGGER.error("cannot restart bundle since it we already attempted it.", symbolicName); sendMessage("CRITICAL", String.format(RESTART_FAILURE_CRIT_MSG, symbolicName)); updateReportStatus(symbolicName, BundleRestartStatus.ERROR); } } else if (event instanceof OsgiBundleContextRefreshedEvent && restartedBundles.contains(symbolicName) ) { sendMessage("WARN", String.format(RESTART_SUCCESS_WARN_MSG, symbolicName)); updateReportStatus(symbolicName, BundleRestartStatus.SUCCESS); restartedBundles.remove(symbolicName); } }