Ejemplo n.º 1
0
 /**
  * @return new eager SimpleReact builder configured with standard parallel executor By default
  *     this is the ForkJoinPool common instance but is configurable in the ThreadPools class
  * @see ThreadPools#getStandard() see RetryBuilder#getDefaultInstance()
  */
 public static SimpleReact parallelCommonBuilder() {
   return SimpleReact.builder()
       .executor(ThreadPools.getStandard())
       .async(true)
       .retrier(
           RetryBuilder.getDefaultInstance().withScheduler(ThreadPools.getCommonFreeThreadRetry()))
       .build();
 }
Ejemplo n.º 2
0
 /**
  * @return new eager SimpleReact builder configured to run on a separate thread (non-blocking
  *     current thread), sequentially Common free thread Executor from
  */
 public static SimpleReact sequentialCommonBuilder() {
   return SimpleReact.builder()
       .async(false)
       .executor(ThreadPools.getCommonFreeThread())
       .retrier(
           RetryBuilder.getDefaultInstance().withScheduler(ThreadPools.getCommonFreeThreadRetry()))
       .build();
 }
Ejemplo n.º 3
0
  /** Wrap a Stream into a SimpleReactStream. */
  static <T> SimpleReactStream<T> of(Stream<T> stream) {

    if (stream instanceof FutureStream)
      stream = ((FutureStream) stream).toQueue().stream(((FutureStream) stream).getSubscription());

    SimpleReact sr =
        new SimpleReact(
            ThreadPools.getSequential(),
            RetryBuilder.getDefaultInstance().withScheduler(ThreadPools.getSequentialRetry()),
            false);
    return new SimpleReactStreamImpl<T>(sr, stream.map(CompletableFuture::completedFuture), null);
  }
 @Test
 public void shouldZipInfiniteWithFiniteSeq() throws Exception {
   ThreadPools.setUseCommon(false);
   final LazyFutureStream<Integer> units =
       LazyFutureStream.iterate(
           1,
           n ->
               n
                   + 1); // <-- MEMORY LEAK!- no auto-closing yet, so writes infinetely to it's
                         // async queue
   final Seq<Integer> hundreds = LazyFutureStream.iterate(100, n -> n + 100).limit(5);
   final Seq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p);
   assertThat(
       zipped.limit(5).join(),
       equalTo(LazyFutureStream.of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join()));
   ThreadPools.setUseCommon(true);
 }
Ejemplo n.º 5
0
 /** Trigger a lazy stream */
 default void run() {
   // FIXME this should use an elastic pool of executors try {  } finally { }
   runOn(ThreadPools.getLazyExecutor());
 }