/** This implementation caches the previous results */ @Override public Optional<ModelCoordinate> suggest(final ProjectCoordinate pc, final String modelType) { if (!isRunning()) { log(INFO_SERVICE_NOT_RUNNING); return absent(); } Pair<ProjectCoordinate, String> key = Pair.newPair(pc, modelType); try { return cache.get( key, new Callable<Optional<ModelCoordinate>>() { @Override public Optional<ModelCoordinate> call() { for (String remote : prefs.remotes) { Pair<File, IModelIndex> pair = openDelegates.get(remote); if (pair == null) { continue; // Index not (yet) available; try next remote repository } IModelIndex index = pair.getSecond(); Optional<ModelCoordinate> suggest = index.suggest(pc, modelType); if (suggest.isPresent()) { return of(createCopyWithRepositoryUrlHint(suggest.get(), remote)); } } return absent(); } }); } catch (ExecutionException e) { Logs.log(LogMessages.ERROR_FAILED_TO_ACCESS_MODEL_COORDINATES_CACHE, e); return absent(); } }
private void openDelegate(String remoteUrl, File indexLocation) throws IOException { IModelIndex modelIndex = createModelIndex(indexLocation); modelIndex.open(); storeDelegate(remoteUrl, Pair.newPair(indexLocation, modelIndex)); bus.post(new ModelIndexOpenedEvent()); }