public <T> Promise<T> waitForService(final Class<T> class1, final long timeoutInMs) throws Exception { return promiseFactory.submit(() -> { ServiceTracker<T, T> tracker = new ServiceTracker<>(context, class1, null); tracker.open(); T s = tracker.waitForService(timeoutInMs); if (s == null) { tracker.close(); throw new Exception("No service object " + class1); } return s; }); }
public <T> Promise<T> waitForService(final Class<T> class1, final long timeoutInMs) throws Exception { return promiseFactory.submit(() -> { ServiceTracker<T, T> tracker = new ServiceTracker<>(context, class1, null); tracker.open(); T s = tracker.waitForService(timeoutInMs); if (s == null) { tracker.close(); throw new Exception("No service object " + class1); } return s; }); }
public Promise<T> async(URL url) { this.url = url; return client.promiseFactory() .submit(() -> (T) client.send(this)); }
public Promise<T> async(URL url) { this.url = url; return client.promiseFactory() .submit(() -> (T) client.send(this)); }
private Promise<List<Artifact>> parseArtifacts(InputStream in, URI uri) throws Exception { if (in == null) { logger.info("No content for {}", uri); return promiseFactory.resolved(Collections.emptyList()); } return promiseFactory.submit(() -> { try { ArtifactRepository ar = new ArtifactRepository(in, uri); return ar.getArtifacts(); } finally { IO.close(in); } }); }
private Promise<List<Artifact>> parseArtifacts(InputStream in, URI uri) throws Exception { if (in == null) { logger.info("No content for {}", uri); return promiseFactory.resolved(Collections.emptyList()); } return promiseFactory.submit(() -> { try { ArtifactRepository ar = new ArtifactRepository(in, uri); return ar.getArtifacts(); } finally { IO.close(in); } }); }
@Override public List<Artifact> getAllArtifacts() throws Exception { List<Promise<List<Artifact>>> promises = new ArrayList<>(); List<Location> locations = getLocationsFromTargetPlatformXML(base); if (locations.isEmpty()) { logger.debug("no locations for {}", base); } for (Location location : locations) { P2Impl p2 = new P2Impl(client, location.repository, promiseFactory); Promise<List<Artifact>> submit = promiseFactory.submit(() -> { List<Artifact> allArtifacts = p2.getAllArtifacts(); return filterArtifactsAgainstLocationUnits(location, p2.getAllArtifacts()); }); promises.add(submit); } return promiseFactory.all(promises) .getValue() .stream() .flatMap(l -> l.stream()) .collect(Collectors.toList()); }
@Override public List<Artifact> getAllArtifacts() throws Exception { List<Promise<List<Artifact>>> promises = new ArrayList<>(); List<Location> locations = getLocationsFromTargetPlatformXML(base); if (locations.isEmpty()) { logger.debug("no locations for {}", base); } for (Location location : locations) { P2Impl p2 = new P2Impl(client, location.repository, promiseFactory); Promise<List<Artifact>> submit = promiseFactory.submit(() -> { List<Artifact> allArtifacts = p2.getAllArtifacts(); return filterArtifactsAgainstLocationUnits(location, p2.getAllArtifacts()); }); promises.add(submit); } return promiseFactory.all(promises) .getValue() .stream() .flatMap(l -> l.stream()) .collect(Collectors.toList()); }
private Promise<File> get(Archive archive, boolean thrw) throws Exception { final File file = toLocalFile(archive); if (file.isFile() && !archive.isSnapshot()) { return promiseFactory.resolved(file); } if (localOnly || isFresh(file)) { return promiseFactory.resolved(file.isFile() ? file : null); } return promiseFactory.submit(() -> { File f = getFile(archive, file); if (thrw && f == null) { if (archive.isSnapshot()) throw new FileNotFoundException("For Maven artifact " + archive + " from " + snapshot); else throw new FileNotFoundException("For Maven artifact " + archive + " from " + release); } return f; }); }
private Promise<File> get(Archive archive, boolean thrw) throws Exception { final File file = toLocalFile(archive); if (file.isFile() && !archive.isSnapshot()) { return promiseFactory.resolved(file); } if (localOnly || isFresh(file)) { return promiseFactory.resolved(file.isFile() ? file : null); } return promiseFactory.submit(() -> { File f = getFile(archive, file); if (thrw && f == null) { if (archive.isSnapshot()) throw new FileNotFoundException("For Maven artifact " + archive + " from " + snapshot); else throw new FileNotFoundException("For Maven artifact " + archive + " from " + release); } return f; }); }
private Promise<Resource> parseFile(File file) { Promise<Resource> resource = promiseFactory.submit(() -> { if (!file.isFile()) { return null; } ResourceBuilder rb = new ResourceBuilder(); try (JarFile jar = new JarFile(file)) { Domain manifest = Domain.domain(jar.getManifest()); boolean hasIdentity = rb.addManifest(manifest); if (!hasIdentity) { return null; } } catch (Exception f) { return null; } logger.debug("{}: parsing {}", getName(), file); Attrs attrs = new Attrs(); attrs.put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, file.toURI() .toString()); attrs.putTyped(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, file.length()); attrs.put(ContentNamespace.CONTENT_NAMESPACE, SHA256.digest(file) .asHex()); rb.addCapability(CapReqBuilder.createCapReqBuilder(ContentNamespace.CONTENT_NAMESPACE, attrs)); return rb.build(); }); if (logger.isDebugEnabled()) { resource.onFailure(failure -> logger.debug("{}: failed to parse {}", getName(), file, failure)); } return resource; }
private Promise<Resource> parseFile(File file) { Promise<Resource> resource = promiseFactory.submit(() -> { if (!file.isFile()) { return null; } ResourceBuilder rb = new ResourceBuilder(); try (JarFile jar = new JarFile(file)) { Domain manifest = Domain.domain(jar.getManifest()); boolean hasIdentity = rb.addManifest(manifest); if (!hasIdentity) { return null; } } catch (Exception f) { return null; } logger.debug("{}: parsing {}", getName(), file); Attrs attrs = new Attrs(); attrs.put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, file.toURI() .toString()); attrs.putTyped(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, file.length()); attrs.put(ContentNamespace.CONTENT_NAMESPACE, SHA256.digest(file) .asHex()); rb.addCapability(CapReqBuilder.createCapReqBuilder(ContentNamespace.CONTENT_NAMESPACE, attrs)); return rb.build(); }); if (logger.isDebugEnabled()) { resource.onFailure(failure -> logger.debug("{}: failed to parse {}", getName(), file, failure)); } return resource; }