return defaultFactory.all(promises);
@Override public <R> PushStream<R> window(Duration time, Function<Collection<T>,R> f) { return window(time, promiseFactory.executor(), f); }
/** * Returns a new Promise that has been resolved with the specified failure. * * @param <T> The value type associated with the returned Promise. * @param failure The failure of the resolved Promise. Must not be * {@code null}. * @return A new Promise which uses the default callback executor and * default scheduled executor that has been resolved with the * specified failure. * @see PromiseFactory#failed(Throwable) */ public static <T> Promise<T> failed(Throwable failure) { return defaultFactory.failed(failure); }
public FileSetRepository(String name, Collection<File> files) throws Exception { this.name = name; this.files = files; promiseFactory = new PromiseFactory(PromiseFactory.inlineExecutor()); repository = promiseFactory.deferred(); }
public SimplePushEventSourceImpl(PromiseFactory promiseFactory, QueuePolicy<T,U> queuePolicy, U queue, int parallelism, Runnable onClose) { this.promiseFactory = promiseFactory; this.sameThread = new PromiseFactory( PromiseFactory.inlineExecutor(), promiseFactory.scheduledExecutor()); this.queuePolicy = queuePolicy; this.queue = queue; this.parallelism = parallelism; this.semaphore = new Semaphore(parallelism); this.onClose = onClose; this.closed = false; this.connectPromise = null; }
/** * Returns a new Promise that has been resolved with the specified value. * * @param <T> The value type associated with the returned Promise. * @param value The value of the resolved Promise. * @return A new Promise which uses the default callback executor and * default scheduled executor that has been resolved with the * specified value. * @see PromiseFactory#resolved(Object) */ public static <T> Promise<T> resolved(T value) { return defaultFactory.resolved(value); }
private Promise<List<Artifact>> getArtifacts(Set<URI> cycles, final Collection<URI> uris) { Deferred<List<Artifact>> deferred = promiseFactory.deferred(); promiseFactory.executor() .execute(() -> { try { deferred.resolveWith(uris.stream() .map(uri -> getArtifacts(cycles, base.resolve(uri)).recover(failed -> { if (!defaults.contains(uri)) { logger.info("Failed to get artifacts for %s", uri, failed.getFailure()); } return Collections.emptyList(); })) .collect(toPromise(promiseFactory)) .map(ll -> ll.stream() .flatMap(List::stream) .collect(toList()))); } catch (Throwable e) { deferred.fail(e); } }); return deferred.getPromise(); }
@Override protected void beginning() { lastTime.set(System.nanoTime()); promiseFactory.scheduledExecutor().schedule( () -> check(lastTime, timeout), timeout, NANOSECONDS); } };
private Promise<List<Artifact>> getArtifacts(Set<URI> cycles, URI uri) { if (!cycles.add(uri)) { return promiseFactory.resolved(Collections.emptyList()); } try { String type = uri.getPath(); logger.info("getArtifacts type={}", uri); if (type.endsWith("/compositeArtifacts.xml")) { return parseCompositeArtifacts(cycles, hideAndSeek(uri), uri); } else if (type.endsWith("/artifacts.xml.xz")) { return parseArtifacts(hideAndSeek(uri), uri); } else if (type.endsWith("/artifacts.xml")) { return parseArtifacts(hideAndSeek(uri), uri); } else if (type.endsWith("/p2.index")) { return parseIndexArtifacts(cycles, uri); } uri = normalize(uri).resolve("p2.index"); defaults.add(uri); return parseIndexArtifacts(cycles, uri); } catch (Exception e) { logger.error("getArtifacts", e); return promiseFactory.failed(e); } }
@Override public Promise<Void> connectPromise() { synchronized (lock) { if (closed) { return closedConnectPromise(); } if (connected.isEmpty()) { if (connectPromise == null) { connectPromise = promiseFactory.deferred(); } return connectPromise.getPromise(); } else { return promiseFactory.resolved(null); } } }
@Override public PushStream<T> fork(int n, int delay, Executor ex) { AbstractPushStreamImpl<T> eventStream = new IntermediatePushStreamImpl<>( psp, new PromiseFactory(Objects.requireNonNull(ex), promiseFactory.scheduledExecutor()), this); Semaphore s = new Semaphore(n);
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()); }
public MavenRepository(File base, String id, List<MavenBackingRepository> release, List<MavenBackingRepository> snapshot, Executor executor, Reporter reporter) throws Exception { this.base = base; this.id = id; if (release != null) this.release.addAll(release); if (snapshot != null) this.snapshot.addAll(snapshot); this.promiseFactory = new PromiseFactory(Objects.requireNonNull(executor)); this.localOnly = this.release.isEmpty() && this.snapshot.isEmpty(); IO.mkdirs(base); }
/** * {@inheritDoc} */ @Override public Promise<T> onResolve(Runnable callback) { requireNonNull(callback); if (factory.allowCurrentThread() && isDone()) { try { callback.run(); } catch (Throwable t) { uncaughtException(t); } } else { callbacks.offer(callback); notifyCallbacks(); // call any registered callbacks } return this; }
Traverser(MavenRepository repo, HttpClient client, boolean transitive) { this.repo = repo; this.client = client; this.promiseFactory = client.promiseFactory(); this.deferred = promiseFactory.deferred(); this.transitive = transitive; this.revisions = new ArrayList<>(); this.uris = new ArrayList<>(); }
/** * Returns a new Promise that has been resolved with the specified value. * * @param <T> The value type associated with the returned Promise. * @param value The value of the resolved Promise. * @return A new Promise which uses the default callback executor and * default scheduled executor that has been resolved with the * specified value. * @see PromiseFactory#resolved(Object) */ public static <T> Promise<T> resolved(T value) { return defaultFactory.resolved(value); }
private Promise<List<Artifact>> getArtifacts(Set<URI> cycles, final Collection<URI> uris) { Deferred<List<Artifact>> deferred = promiseFactory.deferred(); promiseFactory.executor() .execute(() -> { try { deferred.resolveWith(uris.stream() .map(uri -> getArtifacts(cycles, base.resolve(uri)).recover(failed -> { if (!defaults.contains(uri)) { logger.info("Failed to get artifacts for %s", uri, failed.getFailure()); } return Collections.emptyList(); })) .collect(toPromise(promiseFactory)) .map(ll -> ll.stream() .flatMap(List::stream) .collect(toList()))); } catch (Throwable e) { deferred.fail(e); } }); return deferred.getPromise(); }
public SimplePushEventSourceImpl(PromiseFactory promiseFactory, QueuePolicy<T,U> queuePolicy, U queue, int parallelism, Runnable onClose) { this.promiseFactory = promiseFactory; this.sameThread = new PromiseFactory( PromiseFactory.inlineExecutor(), promiseFactory.scheduledExecutor()); this.queuePolicy = queuePolicy; this.queue = queue; this.parallelism = parallelism; this.semaphore = new Semaphore(parallelism); this.onClose = onClose; this.closed = false; this.connectPromise = null; }
@Override protected void beginning() { lastTime.set(System.nanoTime()); promiseFactory.scheduledExecutor().schedule( () -> check(lastTime, timeout), timeout, NANOSECONDS); } };