- public static void getAllGraphs(Collection<GraphBundle> collection) throws IOException {
- for (Bundle bundle : getBundles()) {
- GraphBundle entry = getGraph(bundle);
- if (entry!=null) collection.add(entry);
- }
- }
+ public static Collection<GraphBundle> getAllGraphs() throws IOException {
+ CompletableFuture<Object> f = new CompletableFuture<>();
+ Bundle[] bundles = getBundles();
+ Collection<GraphBundle> gbundles = Arrays.stream(bundles).map(t -> { // this could be done in parallel in the future?
+ if (f.isCompletedExceptionally())
+ return null;
+ try {
+ return PlatformUtil.getGraph(t);
+ } catch (IOException e) {
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("Could not get graph {}", t, e);
+ f.completeExceptionally(e);
+ return null;
+ }
+ }).filter(Objects::nonNull).collect(Collectors.toList());
+ if (f.isCompletedExceptionally()) {
+ try {
+ f.get();
+ } catch (ExecutionException | InterruptedException e) {
+ throw (IOException) e.getCause();
+ }
+ }
+ return gbundles;
+ }