@Override public <R> PushStream<R> window(Supplier<Duration> time, IntSupplier maxEvents, BiFunction<Long,Collection<T>,R> f) { return window(time, maxEvents, promiseFactory.executor(), f); }
@Override public <R> PushStream<R> window(Duration time, Function<Collection<T>,R> f) { return window(time, promiseFactory.executor(), f); }
@Override public <R> PushStream<R> window(Supplier<Duration> time, IntSupplier maxEvents, BiFunction<Long,Collection<T>,R> f) { return window(time, maxEvents, promiseFactory.executor(), f); }
@Override public <R> PushStream<R> window(Duration time, Function<Collection<T>,R> f) { return window(time, promiseFactory.executor(), f); }
@Override public <R> PushStream<R> window(Supplier<Duration> time, IntSupplier maxEvents, BiFunction<Long,Collection<T>,R> f) { return window(time, maxEvents, promiseFactory.executor(), f); }
@Override public <R> PushStream<R> window(Duration time, Function<Collection<T>,R> f) { return window(time, promiseFactory.executor(), f); }
@Override protected boolean begin() { if (super.begin()) { Iterator<T> it = items.iterator(); promiseFactory.executor().execute(() -> pushData(it)); return true; } return false; }
@Override protected boolean begin() { if (super.begin()) { Iterator<T> it = items.iterator(); promiseFactory.executor().execute(() -> pushData(it)); return true; } return false; }
@Override protected boolean begin() { if (super.begin()) { Iterator<T> it = items.iterator(); promiseFactory.executor().execute(() -> pushData(it)); return true; } return false; }
/** * Call any registered callbacks if this Promise is resolved. */ void notifyCallbacks() { if (!isDone()) { return; // return if not resolved } /* * Note: multiple threads can be in this method removing callbacks from * the queue and executing them, so the order in which callbacks are * executed cannot be specified. */ for (Runnable callback = callbacks.poll(); callback != null; callback = callbacks.poll()) { try { try { factory.executor().execute(callback); } catch (RejectedExecutionException e) { callback.run(); } } catch (Throwable t) { uncaughtException(t); } } }
/** * Call any registered callbacks if this Promise is resolved. */ void notifyCallbacks() { if (!isDone()) { return; // return if not resolved } /* * Note: multiple threads can be in this method removing callbacks from * the queue and executing them, so the order in which callbacks are * executed cannot be specified. */ for (Runnable callback = callbacks.poll(); callback != null; callback = callbacks.poll()) { try { try { factory.executor().execute(callback); } catch (RejectedExecutionException e) { callback.run(); } } catch (Throwable t) { uncaughtException(t); } } }
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(); }
private void doSend(PushEventConsumer< ? super T> pec, PushEvent<T> event) { try { promiseFactory.executor().execute(() -> safePush(pec, event)); } catch (RejectedExecutionException ree) { // TODO log? if (!event.isTerminal()) { close(PushEvent.error(ree)); } else { safePush(pec, event); } } }
private void doSend(PushEventConsumer< ? super T> pec, PushEvent<T> event) { try { promiseFactory.executor().execute(() -> safePush(pec, event)); } catch (RejectedExecutionException ree) { // TODO log? if (!event.isTerminal()) { close(PushEvent.error(ree)); } else { safePush(pec, event); } } }
private void doSend(PushEventConsumer< ? super T> pec, PushEvent<T> event) { try { promiseFactory.executor().execute(() -> safePush(pec, event)); } catch (RejectedExecutionException ree) { // TODO log? if (!event.isTerminal()) { close(PushEvent.error(ree)); } else { safePush(pec, event); } } }
private Promise<Long> doSendWithBackPressure( PushEventConsumer< ? super T> pec, PushEvent<T> event) { Deferred<Long> d = sameThread.deferred(); try { promiseFactory.executor().execute( () -> d.resolve(Long.valueOf( System.nanoTime() + safePush(pec, event)))); } catch (RejectedExecutionException ree) { // TODO log? if (!event.isTerminal()) { close(PushEvent.error(ree)); d.resolve(Long.valueOf(System.nanoTime())); } else { d.resolve( Long.valueOf(System.nanoTime() + safePush(pec, event))); } } return d.getPromise(); }
private Promise<Long> doSendWithBackPressure( PushEventConsumer< ? super T> pec, PushEvent<T> event) { Deferred<Long> d = sameThread.deferred(); try { promiseFactory.executor().execute( () -> d.resolve(Long.valueOf( System.nanoTime() + safePush(pec, event)))); } catch (RejectedExecutionException ree) { // TODO log? if (!event.isTerminal()) { close(PushEvent.error(ree)); d.resolve(Long.valueOf(System.nanoTime())); } else { d.resolve( Long.valueOf(System.nanoTime() + safePush(pec, event))); } } return d.getPromise(); }
private Promise<Long> doSendWithBackPressure( PushEventConsumer< ? super T> pec, PushEvent<T> event) { Deferred<Long> d = sameThread.deferred(); try { promiseFactory.executor().execute( () -> d.resolve(Long.valueOf( System.nanoTime() + safePush(pec, event)))); } catch (RejectedExecutionException ree) { // TODO log? if (!event.isTerminal()) { close(PushEvent.error(ree)); d.resolve(Long.valueOf(System.nanoTime())); } else { d.resolve( Long.valueOf(System.nanoTime() + safePush(pec, event))); } } return d.getPromise(); }
/** * Returns a new Promise that will hold the result of the specified task. * <p> * The returned Promise uses the callback executor and scheduled executor of * this PromiseFactory object * <p> * The specified task will be executed on the {@link #executor() callback * executor}. * * @param <T> The value type associated with the returned Promise. * @param task The task whose result will be available from the returned * Promise. * @return A new Promise that will hold the result of the specified task. */ public <T> Promise<T> submit(Callable< ? extends T> task) { DeferredPromiseImpl<T> promise = new DeferredPromiseImpl<>(this); Runnable submit = promise.new Submit(task); try { executor().execute(submit); } catch (Exception t) { promise.tryResolve(null, t); } return promise.orDone(); }
/** * Returns a new Promise that will hold the result of the specified task. * <p> * The returned Promise uses the callback executor and scheduled executor of * this PromiseFactory object. * <p> * The specified task will be executed on the {@link #executor() callback * executor}. * * @param <T> The value type associated with the returned Promise. * @param task The task whose result will be available from the returned * Promise. * @return A new Promise that will hold the result of the specified task. */ public <T> Promise<T> submit(Callable< ? extends T> task) { DeferredPromiseImpl<T> promise = new DeferredPromiseImpl<>(this); Runnable submit = promise.new Submit(task); try { executor().execute(submit); } catch (Exception t) { promise.tryResolve(null, t); } return promise.orDone(); }