use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class BatchingCollector method accept.
/* (non-Javadoc)
* @see java.util.function.Consumer#accept(java.lang.Object)
*/
@Override
public void accept(final FastFuture<T> t) {
active.add(t);
if (active.size() > maxActive.getMaxActive()) {
while (active.size() > maxActive.getReduceTo()) {
final List<FastFuture<T>> toRemove = active.stream().filter(cf -> cf.isDone()).collect(Collectors.toList());
active.removeAll(toRemove);
results.addAll(toRemove);
if (active.size() > maxActive.getReduceTo()) {
final CompletableFuture promise = new CompletableFuture();
FastFuture.xOf(active.size() - maxActive.getReduceTo(), () -> {
promise.complete(true);
}, active.toArray(new FastFuture[0]));
promise.join();
}
}
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class EmptyCollector method accept.
/*
* @param t Result type
* @see java.util.function.Consumer#accept(java.lang.Object)
*/
@Override
public void accept(final FastFuture<T> t) {
active.add(t);
if (active.size() > maxActive.getMaxActive()) {
while (active.size() > maxActive.getReduceTo()) {
final List<FastFuture> toRemove = active.stream().filter(cf -> cf.isDone()).peek(this::handleExceptions).collect(Collectors.toList());
active.removeAll(toRemove);
if (active.size() > maxActive.getReduceTo()) {
final CompletableFuture promise = new CompletableFuture();
FastFuture.xOf(active.size() - maxActive.getReduceTo(), () -> promise.complete(true), active.toArray(new FastFuture[0]));
promise.join();
}
}
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class LazyStreamWrapper method injectFutures.
public Stream<FastFuture> injectFutures() {
final FastFuture f = pipeline.build();
final Function<Object, FastFuture> factory = v -> {
final FastFuture next = pool != null ? pool.next(() -> new FastFuture<>(f.getPipeline(), fut -> pool.done(fut))) : new FastFuture<>(f.getPipeline(), 0);
next.set(v);
return next;
};
if (react.isStreamOfFutures())
return convertCompletableFutures(f.getPipeline());
final Stream<FastFuture> result = values.get().map(factory);
return result;
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class EmptyCollectorTest method testAcceptMock495.
@Test
public void testAcceptMock495() {
collector = new EmptyCollector<>(new MaxActive(500, 5), cf -> cf.join());
FastFuture cf = Mockito.mock(FastFuture.class);
BDDMockito.given(cf.isDone()).willReturn(true);
for (int i = 0; i < 1000; i++) {
collector.accept(cf);
}
Mockito.verify(cf, Mockito.times(501)).isDone();
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method firstRecover.
@Test
public void firstRecover() {
FastFuture f = future.exceptionally(e -> "hello world").thenApply(v -> {
throw new RuntimeException();
}).build();
f.set("boo!");
assertThat(f.join(), equalTo("hello world"));
}
Aggregations