Codota Logo
com.oath.cyclops.async
Code IndexAdd Codota to your IDE (free)

How to use com.oath.cyclops.async

Best Java code snippets using com.oath.cyclops.async (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Charset c =
  • Codota IconString charsetName;Charset.forName(charsetName)
  • Codota IconCharset.defaultCharset()
  • Codota IconContentType contentType;contentType.getCharset()
  • Smart code suggestions by Codota
}
origin: aol/cyclops

/**
 * Construct a Topic using the Queue provided
 * @param q Queue to back this Topic with
 */
public Topic(final Queue<T> q) {
  factory = QueueFactories.unboundedQueue();
  distributor.addQueue(q);
}
public Topic(final Queue<T> q,QueueFactory<T> factory) {
origin: aol/cyclops

/**
 * Construct a new Topic
 */
public Topic() {
  final Queue<T> q = new Queue<T>();
  factory = QueueFactories.unboundedQueue();
  distributor.addQueue(q);
}
origin: aol/cyclops

public ReactiveSeq<T> changes(){
    com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue()
        .build();
    Spliterator<T> copy = copy();
    Continuation[] contRef ={null};
    Signal<T> signal = new Signal<T>(null, queue);
    AtomicBoolean wip = new AtomicBoolean(false);
    Continuation cont = new Continuation(()->{
      if(wip.compareAndSet(false,true)) {
        if(!copy.tryAdvance(signal::set)){
          signal.close();
          return Continuation.empty();
        }
        wip.set(false);
      }
      return contRef[0];
    });
    contRef[0]= cont;
    queue.addContinuation(cont);
    return signal.getDiscrete().stream();
}
origin: aol/cyclops

@Override
public Stream<T> unwrapStream() {
  if (async == Type.NO_BACKPRESSURE) {
    Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue()
                    .build();
    AtomicBoolean wip = new AtomicBoolean(false);
    Continuation cont = new Continuation(() -> {
      if (wip.compareAndSet(false, true)) {
        this.source.subscribeAll(queue::offer, i -> {
          queue.close();
        }, () -> queue.close());
      }
      return Continuation.empty();
    });
    queue.addContinuation(cont);
    return queue.stream();
  }
  return StreamSupport.stream(new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).spliterator(), false);
}
origin: aol/cyclops

@Test
public void mergeAdapterTest() {
  for (int k = 0; k < ITERATIONS; k++) {
    Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10)
        .build();
    Thread t = new Thread(() -> {
      queue.add(1);
      queue.add(2);
      queue.add(3);
      try {
        System.out.println("Sleeping!");
        Thread.sleep(10);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.out.println("Waking!");
      System.out.println("Closing! " + queue.size());
      queue.close();
    });
    t.start();
    assertThat(this.<Integer>of().peek(i -> System.out.println("publishing " + i))
        .merge(queue).collect(Collectors.toList()), equalTo(Arrays.asList(1, 2, 3)));
    t = null;
    System.gc();
  }
}
origin: aol/cyclops

default <R> R foldParallel(Function<? super Stream<T>,? extends R> fn){
  Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue().build().withTimeout(1);
  AtomicReference<Continuation> ref = new AtomicReference<>(null);
  Continuation cont =
      new Continuation(()->{
        if(ref.get()==null && ref.compareAndSet(null,Continuation.empty())){
          try {
            //use the first consuming thread to tell this Stream onto the Queue
            this.spliterator().forEachRemaining(queue::offer);
          }finally {
            queue.close();
          }
        }
          return Continuation.empty();
        });
  ;
  queue.addContinuation(cont);
  return fn.apply(queue.jdkStream().parallel());
}
default <R> R foldParallel(ForkJoinPool fj,Function<? super Stream<T>,? extends R> fn){
origin: aol/cyclops

@Override
public Topic<T> broadcast() {
  if (async == Type.NO_BACKPRESSURE) {
    Queue<T> queue = QueueFactories.<T>boundedNonBlockingQueue(1000)
                    .build()
                    .withTimeout(1);
    Topic<T> topic = new Topic<>(queue, QueueFactories.<T>boundedNonBlockingQueue(1000));
    AtomicBoolean wip = new AtomicBoolean(false);
              source.subscribeAll(topic::offer, e -> topic.close(), () -> topic.close());
            } finally {
              wip.set(false);
    queue.addContinuation(cont);
    return topic;
  Queue<T> queue = QueueFactories.<T>boundedNonBlockingQueue(1000)
                  .build()
                  .withTimeout(1);
  Topic<T> topic = new Topic<>(queue, QueueFactories.<T>boundedNonBlockingQueue(1000));
  AtomicBoolean wip = new AtomicBoolean(false);
  Subscription s = source.subscribe(topic::offer, e -> topic.close(), () -> topic.close());
  Continuation contRef[] = {null};
  Continuation cont =
            s.request(1000-queue.size());
          }finally {
            wip.set(false);
origin: aol/cyclops

@Test
public void publishToAndMerge(){
  com.oath.cyclops.async.adapters.Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10)
      .build();
  Thread t=  new Thread( ()-> {
    while(true) {
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.out.println("Closing!");
      queue.close();
    }
  });
  t.start();
  assertThat(Spouts.of(1,2,3)
      .publishTo(queue)
      .peek(System.out::println)
      .merge(queue)
      .toList(), Matchers.equalTo(Arrays.asList(1,1,2,2,3,3)));
}
@Test
origin: aol/cyclops

default Topic<T> broadcast(){
  Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue()
                        .build()
                        .withTimeout(1);
  Topic<T> topic = new Topic<T>(queue,QueueFactories.<T>unboundedNonBlockingQueue());
  AtomicBoolean wip = new AtomicBoolean(false);
  Spliterator<T> split = this.spliterator();
  Continuation ref[] = {null};
  Continuation cont =
      new Continuation(()->{
        if(wip.compareAndSet(false,true)){
          try {
            //use the first consuming thread to tell this Stream onto the Queue
            if(!split.tryAdvance(topic::offer)){
              topic.close();
              return Continuation.empty();
            }
          }finally {
            wip.set(false);
          }
        }
        return ref[0];
      });
  ref[0]=cont;
  queue.addContinuation(cont);
  return topic;
}
origin: aol/cyclops

@Test
public void adapter(){
  Adapter<Integer> adapter = QueueFactories.<Integer>unboundedQueue()
                            .build();
    String result =   Eithers.adapter(adapter)
                     .fold(queue->"we have a queue", topic->"we have a topic");
    assertThat(result,equalTo("we have a queue"));
}
origin: com.oath.cyclops/cyclops-futurestream

<T> Queue<T> createQueue() {
  Queue q;
  if (!backPressureOn)
    q = QueueFactories.unboundedNonBlockingQueue()
             .build();
  else
    q = QueueFactories.boundedQueue(backPressureAfter)
             .build();
  return q;
}
origin: com.oath.cyclops/cyclops-futurestream

/**
 * This is the default setting, internal queues are backed by a ConcurrentLinkedQueue
 * This operator will return the next stage to using this Queue type if it has been changed
 *
 * @return FutureStream backed by a ConcurrentLinkedQueue
 */
default FutureStream<U> unboundedWaitFree() {
  return this.withQueueFactory(QueueFactories.unboundedNonBlockingQueue());
}
origin: aol/cyclops

@Override
public Iterator<T> iterator() {
  if (async == Type.NO_BACKPRESSURE) {
    Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue()
        .build();
    AtomicBoolean wip = new AtomicBoolean(false);
    Subscription[] sub = {null};
    Continuation cont = new Continuation(() -> {
      if (wip.compareAndSet(false, true)) {
        this.source.subscribeAll(queue::offer,
            i -> queue.close(),
            () -> queue.close());
      }
      return Continuation.empty();
    });
    queue.addContinuation(cont);
    return queue.stream().iterator();
  }
  return new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).iterator();
}
origin: aol/cyclops

@Test
public void mergeAdapterTest1() {
  for (int k = 0; k < ITERATIONS; k++) {
    System.out.println("Test iteration " + k);
    Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10)
        .build();
    Thread t = new Thread(() -> {
      queue.add(1);
      queue.add(2);
      queue.add(3);
      try {
        //    System.out.println("Sleeping!");
        Thread.sleep(10);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      //   System.out.println("Closing! " + queue.size());
      queue.close();
    });
    t.start();
    assertThat(this.<Integer>of(10).peek(i -> System.out.println("publishing " + i))
        .merge(queue).collect(Collectors.toList()), hasItems(10, 1, 2, 3));
    t = null;
    System.gc();
  }
}
origin: aol/cyclops

@Override
public ReactiveSeq<T> changes() {
  if (async == Type.NO_BACKPRESSURE) {
    Queue<T> discrete = QueueFactories.<T>unboundedNonBlockingQueue()
        .build()
        .withTimeout(1);
    Signal<T> signal = new Signal<T>(null, discrete);
    publishTo(signal).forEach(e -> {
    }, e -> {
    }, () -> signal.close());
    return signal.getDiscrete().stream();
  } else {
    Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue()
        .build();
    Signal<T> signal = new Signal<T>(null, queue);
    Subscription sub = source.subscribe(signal::set, i -> {
      signal.close();
      signal.close();
    });
    queue.addContinuation(cont);
    return signal.getDiscrete().stream();
origin: aol/cyclops

@Test
public void publishToAndMerge(){
  com.oath.cyclops.async.adapters.Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10)
                    .build();
  Thread t=  new Thread( ()-> {
    while(true) {
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
        System.out.println("Closing!");
        queue.close();
    }
  });
  t.start();
  assertThat(ReactiveSeq.of(1,2,3)
             .publishTo(queue)
             .peek(System.out::println)
             .merge(queue)
             .toList(),equalTo(Arrays.asList(1,1,2,2,3,3)));
}
origin: aol/cyclops

default <R> ReactiveSeq<R> parallel(ForkJoinPool fj,Function<? super Stream<T>,? extends Stream<? extends R>> fn){
  Queue<R> queue = QueueFactories.<R>unboundedNonBlockingQueue()
      .build();
        try {
          if (!local.hasNext()) {
            queue.close();
            queue.offer(local.next());
          queue.close();
          throw ExceptionSoftener.throwSoftenedException(t);
  queue.addContinuation(cont);
  return queue.stream();
origin: aol/cyclops

@Test
public void publishTest() {
  for (int k = 0; k < ITERATIONS; k++) {
    Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10)
        .build();
    Thread t = new Thread(() -> {
      try {
        System.out.println("Sleeping!");
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.out.println("Waking!");
      System.out.println("Closing! " + queue.size());
      queue.close();
    });
    t.start();
    of(1, 2, 3).peek(i -> System.out.println("publishing " + i))
        .publishTo(queue)
        .forEach(System.out::println);
    assertThat(queue.stream().collect(Collectors.toList()), equalTo(Arrays.asList(1, 2, 3)));
    t = null;
    System.gc();
  }
}
origin: aol/cyclops

default <R> ReactiveSeq<R> parallel(Function<? super Stream<T>,? extends Stream<? extends R>> fn){
  Queue<R> queue = QueueFactories.<R>unboundedNonBlockingQueue()
                               .build();
        try {
          if (!local.hasNext()) {
            queue.close();
            return Continuation.empty();
          } else {
            queue.offer(local.next());
          queue.close();
          throw ExceptionSoftener.throwSoftenedException(t);
  queue.addContinuation(cont);
  return queue.stream();
origin: aol/cyclops

@Test
public void publishToAndMerge() {
  for (int k = 0; k < ITERATIONS; k++) {
    System.out.println("Publish toNested and zip iteration " + k);
    com.oath.cyclops.async.adapters.Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10)
        .build();
    Thread t = new Thread(() -> {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.out.println("Closing! " + queue.size());
      queue.close();
    });
    t.start();
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicBoolean start = new AtomicBoolean(false);
    List<Integer> list = of(1, 2, 3)
        .publishTo(queue)
        .peek(System.out::println)
        .merge(queue)
        .toList();
    assertThat(list, hasItems(1, 2, 3));
    assertThat(list.size(), equalTo(6));
    System.gc();
  }
}
com.oath.cyclops.async

Most used classes

  • Queue
    Inspired by scalaz-streams async.Queue (functionally similar, but wraps a JDK Queue - wait-free or B
  • QueueFactories
    Methods for generating QueueFactories for plumbing Streams together Queue transferQueue = QueueFact
  • QueueFactory
    Interface for Factories of async.Queues QueueFactories Queue transferQueue = QueueFactories.bounded
  • Topic
    A class that can accept input streams and generate emitted streams where data sent in the Topic is g
  • Adapter
    Interface for an Adapter that inputs data from 1 or more input Streams and sends it to 1 or more emi
  • Queue$QueueReader,
  • AdaptersModule$ClosingSpliterator,
  • AdaptersModule$QueueToBlockingQueueWrapper,
  • AdaptersModule$SingleContinuation,
  • AdaptersModule$StreamOfContinuations,
  • ContinuationStrategy,
  • Queue$QueueTimeoutException,
  • Signal,
  • Topic$DistributingCollection,
  • DirectWaitStrategy,
  • ExponentialBackofWaitStrategy,
  • NoWaitRetry,
  • SpinWait,
  • WaitStrategy$Offerable
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now