public class QueueFactories
extends java.lang.Object
Queue<String> transferQueue = QueueFactories.<String>boundedQueue(4)
.build();
new LazyReact(Executors.newFixedThreadPool(4)).generate(()->"data")
.map(d->"produced on " + Thread.currentThread().getId())
.peek(System.out::println)
.peek(d->transferQueue.offer(d))
.run();
transferQueue.stream()
.map(e->"Consumed on " + Thread.currentThread().getId())
.futureOperations(Executors.newFixedThreadPool(1))
.forEach(System.out::println);
Constructor and Description |
---|
QueueFactories() |
Modifier and Type | Method and Description |
---|---|
static <T> QueueFactory<T> |
boundedNonBlockingQueue(int queueSize)
Creates an async.Queue backed by an Agrona ManyToOneConcurrentArrayQueue bounded by specified queueSize
Wait strategy used is NoWaitRetry by default for both Consumers and Producers
(both Consumers and Producers will repeatedly retry until successful).
|
static <T> QueueFactory<T> |
boundedNonBlockingQueue(int queueSize,
WaitStrategy<T> strategy)
Generate QueueFactory for bounded non blocking queues.
|
static <T> QueueFactory<T> |
boundedQueue(int queueSize)
Create a QueueFactory for boundedQueues where bound is determined by the provided queueSize parameter
Generated Queues will be backed by a LinkedBlockingQueue
|
static <T> QueueFactory<T> |
singleWriterboundedNonBlockingQueue(int queueSize)
Creates an async.Queue backed by an Agrona OneToOneConcurrentArrayQueue bounded by specified queueSize
Wait strategy used is NoWaitRetry by default for both Consumers and Producers
(both Consumers and Producers will repeatedly retry until successful).
|
static <T> QueueFactory<T> |
singleWriterboundedNonBlockingQueue(int queueSize,
WaitStrategy<T> strategy)
Generate QueueFactory for bounded non blocking queues.
|
static <T> QueueFactory<T> |
synchronousQueue() |
static <T> QueueFactory<T> |
unboundedNonBlockingQueue()
Creates an async.Queue backed by a JDK Wait Free unbounded ConcurrentLinkedQueue
Wait strategy used is NoWaitRetry by default for both Consumers and Producers
(both Consumers and Producers will repeatedly retry until successful).
|
static <T> QueueFactory<T> |
unboundedNonBlockingQueue(WaitStrategy<T> strategy)
Creates an async.Queue backed by a JDK Wait Free unbounded ConcurrentLinkedQueue
The provided WaitStrategy is used to determine behaviour of both producers and consumers when the Queue is full (producer)
or empty (consumer).
|
static <T> QueueFactory<T> |
unboundedQueue()
ReactiveSeq.of(1,2,3)
.flatMapPublisher(i->ReactiveSeq.range(i,1500),1000,QueueFactories.unboundedQueue())
.toListX()
|
public static <T> QueueFactory<T> boundedQueue(int queueSize)
Queue<String> transferQueue = QueueFactories.<String>boundedQueue(4)
.build();
new LazyReact(Executors.newFixedThreadPool(4)).generate(()->"data")
.map(d->"produced on " + Thread.currentThread().getId())
.peek(System.out::println)
.peek(d->transferQueue.offer(d))
.run();
transferQueue.stream()
.map(e->"Consumed on " + Thread.currentThread().getId())
.futureOperations(Executors.newFixedThreadPool(1))
.forEach(System.out::println);
queueSize
- Max queue sizepublic static <T> QueueFactory<T> unboundedQueue()
ReactiveSeq.of(1,2,3)
.flatMapPublisher(i->ReactiveSeq.range(i,1500),1000,QueueFactories.unboundedQueue())
.toListX()
public static <T> QueueFactory<T> unboundedNonBlockingQueue()
queue.withConsumerWaitStrategy(new DirectWaitStrategy())
.withProducerWaitStrategy(new YieldWait());
public static <T> QueueFactory<T> unboundedNonBlockingQueue(WaitStrategy<T> strategy)
, @see WaitStrategy#exponentialBackOff() , @see WaitStrategy#noWaitRetry()
strategy
- Strategy to be employed by producers when Queue is full, or consumers when Queue is emptypublic static <T> QueueFactory<T> boundedNonBlockingQueue(int queueSize)
queue.withConsumerWaitStrategy(new DirectWaitStrategy())
.withProducerWaitStrategy(new YieldWait());
queueSize
- upper bound for Queuepublic static <T> QueueFactory<T> boundedNonBlockingQueue(int queueSize, WaitStrategy<T> strategy)
, @see WaitStrategy#exponentialBackOff() , @see WaitStrategy#noWaitRetry()
queueSize
- Max Queue sizestrategy
- Strategy to be employed by producers when Queue is full, or consumers when Queue is emptypublic static <T> QueueFactory<T> singleWriterboundedNonBlockingQueue(int queueSize)
queue.withConsumerWaitStrategy(new DirectWaitStrategy())
.withProducerWaitStrategy(new YieldWait());
queueSize
- public static <T> QueueFactory<T> singleWriterboundedNonBlockingQueue(int queueSize, WaitStrategy<T> strategy)
, @see WaitStrategy#exponentialBackOff() , @see WaitStrategy#noWaitRetry()
queueSize
- Max Queue sizestrategy
- Strategy to be employed by producers when Queue is full, or consumers when Queue is emptypublic static <T> QueueFactory<T> synchronousQueue()