Codota Logo
QueueFactories
Code IndexAdd Codota to your IDE (free)

How to use
QueueFactories
in
com.oath.cyclops.async

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
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);
    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());
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

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: 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: 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

@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

/**
 * Construct a new Topic
 */
public Topic() {
  final Queue<T> q = new Queue<T>();
  factory = QueueFactories.unboundedQueue();
  distributor.addQueue(q);
}
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 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

@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: 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

@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: com.oath.cyclops/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

@Override
public ReactiveSeq<T> changes() {
  if (async == Type.NO_BACKPRESSURE) {
    Queue<T> discrete = QueueFactories.<T>unboundedNonBlockingQueue()
        .build()
        .withTimeout(1);
    Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue()
        .build();
    Signal<T> signal = new Signal<T>(null, queue);
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: com.oath.cyclops/cyclops-futurestream

public SimpleReactStreamImpl(final SimpleReact simpleReact, final Stream<CompletableFuture<U>> stream) {
  this.simpleReact = simpleReact;
  final Stream s = stream;
  this.errorHandler = Optional.empty();
  this.lastActive = new EagerStreamWrapper(
                       s, this.errorHandler);
  this.queueFactory = QueueFactories.unboundedQueue();
  this.subscription = new AlwaysContinue();
}
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 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();
  }
}
origin: com.oath.cyclops/cyclops

/**
 * Construct a new Topic
 */
public Topic() {
  final Queue<T> q = new Queue<T>();
  factory = QueueFactories.unboundedQueue();
  distributor.addQueue(q);
}
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();
com.oath.cyclops.asyncQueueFactories

Javadoc

Methods for generating QueueFactories for plumbing Streams together
 
Queue transferQueue = QueueFactories.boundedQueue(4)

Most used methods

  • boundedNonBlockingQueue
    Generate QueueFactory for bounded non blocking queues. Max queue size is determined by the input par
  • unboundedQueue
    ReactiveSeq.of(1,2,3)
  • unboundedNonBlockingQueue
    Creates an async.Queue backed by a JDK Wait Free unbounded ConcurrentLinkedQueue The provided WaitSt
  • boundedQueue
    Create a QueueFactory for boundedQueues where bound is determined by the provided queueSize paramete

Popular in Java

  • Reactive rest calls using spring rest template
  • notifyDataSetChanged (ArrayAdapter)
  • onCreateOptionsMenu (Activity)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • PriorityQueue (java.util)
    An unbounded priority Queue based on a priority heap. The elements of the priority queue are ordered
  • ResourceBundle (java.util)
    Resource bundles contain locale-specific objects. When your program needs a locale-specific resource
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
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