if (defs == null || defs.isEmpty()) {
return;
}
// Get the Descriptors for the provided Definitions
final DefinitionService definitionService = Aura.getDefinitionService();
final Set<DefDescriptor<?>> cached = Sets.newHashSet();
for (T def : defs) {
if (def != null) {
cached.add(def.getDescriptor());
}
}
// Wait for the change notifications to get processed. We expect listeners to get processed in the order in
// which they subscribe.
final CountDownLatch latch = new CountDownLatch(cached.size());
SourceListener listener = new SourceListener() {
private Set<DefDescriptor<?>> descriptors = Sets.newHashSet(cached);
@Override
public void onSourceChanged(DefDescriptor<?> source, SourceMonitorEvent event, String filePath) {
if (descriptors.remove(source)) {
latch.countDown();
}
if (descriptors.isEmpty()) {
definitionService.unsubscribeToChangeNotification(this);
}
}
};
definitionService.subscribeToChangeNotification(listener);
for (DefDescriptor<?> desc : cached) {
definitionService.onSourceChanged(desc, SourceMonitorEvent.CHANGED, null);
}
if (!latch.await(CACHE_CLEARING_TIMEOUT_SECS, TimeUnit.SECONDS)) {
throw new AuraRuntimeException(String.format(
"Timed out after %s seconds waiting for cached Aura definitions to clear: %s",
CACHE_CLEARING_TIMEOUT_SECS, defs));