}
@Override
- public Object addingBundle(Bundle bundle, BundleEvent event) {
+ public synchronized Object addingBundle(Bundle bundle, BundleEvent event) {
// Ignore system bundle:
// system bundle might have config-api on classpath &&
return bundle;
}
- private void onSnapshotFailure(Bundle bundle, List<URL> addedURLs, Exception failureReason) {
+ private synchronized void onSnapshotFailure(Bundle bundle, List<URL> addedURLs, Exception failureReason) {
// inconsistent state
inconsistentBundlesToYangURLs.putAll(bundle, addedURLs);
consistentBundlesToYangURLs, inconsistentBundlesToYangURLs, failureReason);
logger.warn("Yang store is falling back on last consistent state containing {} files, inconsistent yang files size is {}, reason {}",
consistentBundlesToYangURLs.size(), inconsistentBundlesToYangURLs.size(), failureReason.toString());
+ cache.setInconsistentURLsForReporting(inconsistentBundlesToYangURLs.values());
}
- private void onSnapshotSuccess(Multimap<Bundle, URL> proposedNewState, YangStoreSnapshotImpl snapshot) {
+ private synchronized void onSnapshotSuccess(Multimap<Bundle, URL> proposedNewState, YangStoreSnapshotImpl snapshot) {
// consistent state
// merge into
consistentBundlesToYangURLs.clear();
inconsistentBundlesToYangURLs.clear();
updateCache(snapshot);
-
+ cache.setInconsistentURLsForReporting(Collections.<URL> emptySet());
logger.info("Yang store updated to new consistent state containing {} yang files", consistentBundlesToYangURLs.size());
logger.debug("Yang store updated to new consistent state containing {}", consistentBundlesToYangURLs);
}
- private void updateCache(YangStoreSnapshotImpl snapshot) {
+ private synchronized void updateCache(YangStoreSnapshotImpl snapshot) {
cache.cacheYangStore(consistentBundlesToYangURLs, snapshot);
}
}
class YangStoreCache {
+ private static final Logger logger = LoggerFactory.getLogger(YangStoreCache.class);
@GuardedBy("this")
private Set<URL> cachedUrls = null;
@GuardedBy("this")
private Optional<YangStoreSnapshot> cachedYangStoreSnapshot = getInitialSnapshot();
+ @GuardedBy("this")
+ private Collection<URL> inconsistentURLsForReporting = Collections.emptySet();
synchronized Optional<YangStoreSnapshot> getSnapshotIfPossible(Multimap<Bundle, URL> bundlesToYangURLs) {
Set<URL> urls = setFromMultimapValues(bundlesToYangURLs);
if (cachedUrls==null || cachedUrls.equals(urls)) {
Preconditions.checkState(cachedYangStoreSnapshot.isPresent());
YangStoreSnapshot freshSnapshot = new YangStoreSnapshotImpl(cachedYangStoreSnapshot.get());
+ if (inconsistentURLsForReporting.size() > 0){
+ logger.warn("Some yang URLs are ignored: {}", inconsistentURLsForReporting);
+ }
return Optional.of(freshSnapshot);
}
}
synchronized void cacheYangStore(Multimap<Bundle, URL> urls,
- YangStoreSnapshot yangStoreSnapshot) {
+ YangStoreSnapshot yangStoreSnapshot) {
this.cachedUrls = setFromMultimapValues(urls);
this.cachedYangStoreSnapshot = Optional.of(yangStoreSnapshot);
}
}
}
+ public synchronized void setInconsistentURLsForReporting(Collection<URL> urls){
+ inconsistentURLsForReporting = urls;
+ }
+
private Optional<YangStoreSnapshot> getInitialSnapshot() {
YangStoreSnapshot initialSnapshot = new YangStoreSnapshot() {
@Override