本文整理汇总了Java中reactor.util.concurrent.Queues类的典型用法代码示例。如果您正苦于以下问题:Java Queues类的具体用法?Java Queues怎么用?Java Queues使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Queues类属于reactor.util.concurrent包,在下文中一共展示了Queues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: StatsdMeterRegistry
import reactor.util.concurrent.Queues; //导入依赖的package包/类
public StatsdMeterRegistry(StatsdConfig config, HierarchicalNameMapper nameMapper, Clock clock) {
super(clock);
this.statsdConfig = config;
this.nameMapper = ofNullable(nameMapper).orElse(HierarchicalNameMapper.DEFAULT);
switch (statsdConfig.flavor()) {
case Datadog:
config().namingConvention(NamingConvention.dot);
break;
case Telegraf:
config().namingConvention(NamingConvention.snakeCase);
break;
default:
config().namingConvention(NamingConvention.camelCase);
}
this.publisher = UnicastProcessor.create(Queues.<String>get(statsdConfig.queueSize()).get());
gauge("statsd.queue.size", this.publisher, UnicastProcessor::size);
gauge("statsd.queue.capacity", this.publisher, UnicastProcessor::getBufferSize);
if (config.enabled())
start();
}
示例2: write
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("{} Writing object {}", ctx.channel(), msg);
}
if (pendingWrites == null) {
this.pendingWrites = Queues.unbounded()
.get();
this.pendingWriteOffer = (BiPredicate<ChannelFuture, Object>) pendingWrites;
}
if (!pendingWriteOffer.test(promise, msg)) {
promise.setFailure(new IllegalStateException("Send Queue full?!"));
}
}
示例3: scanMainSubscriberError
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void scanMainSubscriberError() {
LambdaSubscriber<Integer> subscriber = new LambdaSubscriber<>(null, e -> { }, null,
s -> s.request(2));
MergeSequentialMain<Integer>
test = new MergeSequentialMain<>(subscriber, 4, 123, Queues.small());
subscriber.onSubscribe(test);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
test.onError(new IllegalStateException("boom"));
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
}
示例4: scanMain
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void scanMain() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxSampleTimeout.SampleTimeoutMain<Integer, Integer> test =
new FluxSampleTimeout.SampleTimeoutMain<>(actual, i -> Flux.just(i),
Queues.<SampleTimeoutOther<Integer, Integer>>one().get());
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
test.requested = 35;
Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35L);
test.queue.add(new FluxSampleTimeout.SampleTimeoutOther<Integer, Integer>(test, 1, 0));
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.error = new IllegalStateException("boom");
Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
test.onComplete();
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例5: assertProcessor
import reactor.util.concurrent.Queues; //导入依赖的package包/类
private void assertProcessor(WorkQueueProcessor<Integer> processor,
boolean shared,
@Nullable String name,
@Nullable Integer bufferSize,
@Nullable WaitStrategy waitStrategy,
@Nullable Boolean autoCancel,
@Nullable ExecutorService executor,
@Nullable ExecutorService requestTaskExecutor) {
String expectedName = name != null ? name : WorkQueueProcessor.class.getSimpleName();
int expectedBufferSize = bufferSize != null ? bufferSize : Queues.SMALL_BUFFER_SIZE;
boolean expectedAutoCancel = autoCancel != null ? autoCancel : true;
WaitStrategy expectedWaitStrategy = waitStrategy != null ? waitStrategy : WaitStrategy.liteBlocking();
Class<?> sequencerClass = shared ? MultiProducerRingBuffer.class : SingleProducerSequencer.class;
assertEquals(expectedName, processor.name);
assertEquals(expectedBufferSize, processor.getBufferSize());
assertEquals(expectedAutoCancel, processor.autoCancel);
assertEquals(expectedWaitStrategy.getClass(), processor.ringBuffer.getSequencer().waitStrategy.getClass());
assertEquals(sequencerClass, processor.ringBuffer.getSequencer().getClass());
if (executor != null)
assertEquals(executor, processor.executor);
if (requestTaskExecutor != null)
assertEquals(requestTaskExecutor, processor.requestTaskExecutor);
}
示例6: mainErrorUntilIsPropagatedToBothWindowAndMain
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void mainErrorUntilIsPropagatedToBothWindowAndMain() {
DirectProcessor<Integer> sp1 = DirectProcessor.create();
FluxWindowPredicate<Integer> windowUntil = new FluxWindowPredicate<>(
sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
i -> i % 3 == 0, Mode.UNTIL);
StepVerifier.create(windowUntil.flatMap(Flux::materialize))
.expectSubscription()
.then(() -> sp1.onNext(1))
.expectNext(Signal.next(1))
.then(() -> sp1.onNext(2))
.expectNext(Signal.next(2))
.then(() -> sp1.onNext(3))
.expectNext(Signal.next(3), Signal.complete())
.then(() -> sp1.onNext(4))
.expectNext(Signal.next(4))
.then(() -> sp1.onError(new RuntimeException("forced failure")))
//this is the error in the window:
.expectNextMatches(signalErrorMessage("forced failure"))
//this is the error in the main:
.expectErrorMessage("forced failure")
.verify();
assertThat(sp1.hasDownstreams()).isFalse();
}
示例7: BackpressureBufferSubscriber
import reactor.util.concurrent.Queues; //导入依赖的package包/类
BackpressureBufferSubscriber(CoreSubscriber<? super T> actual,
int bufferSize,
boolean unbounded,
boolean delayError,
@Nullable Consumer<? super T> onOverflow) {
this.actual = actual;
this.delayError = delayError;
this.onOverflow = onOverflow;
Queue<T> q;
if (unbounded) {
q = Queues.<T>unbounded(bufferSize).get();
}
else {
q = Queues.<T>get(bufferSize).get();
}
this.queue = q;
}
示例8: testMaxConcurrent5
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void testMaxConcurrent5() {
final List<Long> requests = new ArrayList<>();
Flux.range(1, 100).doOnRequest(requests::add)
.flatMapSequential(toJust, 5, Queues.SMALL_BUFFER_SIZE)
.subscribe(ts);
ts.assertNoError();
ts.assertValueCount(100);
ts.assertComplete();
Assert.assertEquals(5, (long) requests.get(0));
Assert.assertEquals(1, (long) requests.get(1));
Assert.assertEquals(1, (long) requests.get(2));
Assert.assertEquals(1, (long) requests.get(3));
Assert.assertEquals(1, (long) requests.get(4));
Assert.assertEquals(1, (long) requests.get(5));
}
示例9: combineLatest
import reactor.util.concurrent.Queues; //导入依赖的package包/类
/**
* Build a {@link Flux} whose data are generated by the combination of the most recently published value from each
* of the {@link Publisher} sources.
* <p>
* <img class="marble" src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.3.RELEASE/src/docs/marble/combinelatest.png"
* alt="">
*
* @param sources The {@link Publisher} sources to combine values from
* @param prefetch The demand sent to each combined source {@link Publisher}
* @param combinator The aggregate function that will receive the latest value from each upstream and return the value
* to signal downstream
* @param <T> type of the value from sources
* @param <V> The produced output after transformation by the given combinator
*
* @return a {@link Flux} based on the produced combinations
*/
@SafeVarargs
public static <T, V> Flux<V> combineLatest(Function<Object[], V> combinator, int prefetch,
Publisher<? extends T>... sources) {
if (sources.length == 0) {
return empty();
}
if (sources.length == 1) {
Publisher<? extends T> source = sources[0];
if (source instanceof Fuseable) {
return onAssembly(new FluxMapFuseable<>(from(source),
v -> combinator.apply(new Object[]{v})));
}
return onAssembly(new FluxMap<>(from(source),
v -> combinator.apply(new Object[]{v})));
}
return onAssembly(new FluxCombineLatest<>(sources,
combinator, Queues.get(prefetch), prefetch));
}
示例10: scanOverlapSubscriberSmallBuffered
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void scanOverlapSubscriberSmallBuffered() {
@SuppressWarnings("unchecked")
Queue<UnicastProcessor<Integer>> mockQueue = Mockito.mock(Queue.class);
CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxWindow.WindowOverlapSubscriber<Integer> test = new FluxWindow.WindowOverlapSubscriber<Integer>(actual,
3,3, Queues.unbounded(), mockQueue);
when(mockQueue.size()).thenReturn(Integer.MAX_VALUE - 2);
//size() is 1
test.offer(UnicastProcessor.create());
assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(Integer.MAX_VALUE - 1);
assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(Integer.MAX_VALUE - 1L);
}
示例11: scanConcatMapImmediateError
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void scanConcatMapImmediateError() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxConcatMap.ConcatMapImmediate<String, Integer> test = new FluxConcatMap.ConcatMapImmediate<>(
actual, s -> Mono.just(s.length()), Queues.one(), 123);
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isFalse();
//note that most of the time, the error will be hidden by TERMINATED as soon as it has been propagated downstream :(
test.error = new IllegalStateException("boom");
assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onError(new IllegalStateException("boom2"));
assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(Exceptions.TERMINATED);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
示例12: threadBoundaryPreventsInvalidFusionFilter
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void threadBoundaryPreventsInvalidFusionFilter() {
UnicastProcessor<Integer> up =
UnicastProcessor.create(Queues.<Integer>get(2).get());
String s = Thread.currentThread()
.getName();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
up.filter(v -> s.equals(Thread.currentThread()
.getName()))
.publishOn(Schedulers.fromExecutorService(exec))
.subscribe(ts);
up.onNext(1);
up.onComplete();
ts.await(Duration.ofSeconds(5));
ts.assertValues(1)
.assertNoError()
.assertComplete();
}
示例13: scanUnicastGroupedFlux
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void scanUnicastGroupedFlux() {
CoreSubscriber<GroupedFlux<Integer, String>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxGroupBy.GroupByMain<Integer, Integer, String> main = new FluxGroupBy.GroupByMain<>(actual,
Queues.<GroupedFlux<Integer, String>>one().get(), Queues.one(), 123, i -> i % 5, i -> String.valueOf(i));
FluxGroupBy.UnicastGroupedFlux<Integer, String> test = new FluxGroupBy.UnicastGroupedFlux<Integer, String>(1,
Queues.<String>one().get(), main, 123);
CoreSubscriber<String> sub = new LambdaSubscriber<>(null, e -> {}, null, null);
test.subscribe(sub);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(sub);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(main);
assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(Long.MAX_VALUE);
assertThat(test.scan(Scannable.Attr.BUFFERED)).isSameAs(0);
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
test.error = new IllegalStateException("boom");
assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(test.error);
}
示例14: scanInner
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void scanInner() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxZip.ZipCoordinator<Integer, Integer> main = new FluxZip.ZipCoordinator<Integer, Integer>(actual,
i -> 5, 123, Queues.unbounded(), 345);
FluxZip.ZipInner<Integer> test = new FluxZip.ZipInner<>(main, 234, 1, Queues.unbounded());
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
Assertions.assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(234);
test.queue = new ConcurrentLinkedQueue<>();
test.queue.offer(67);
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.queue.clear();
test.onComplete();
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例15: mainErrorUntilCutBeforeIsPropagatedToBothWindowAndMain
import reactor.util.concurrent.Queues; //导入依赖的package包/类
@Test
public void mainErrorUntilCutBeforeIsPropagatedToBothWindowAndMain() {
DirectProcessor<Integer> sp1 = DirectProcessor.create();
FluxWindowPredicate<Integer> windowUntilCutBefore =
new FluxWindowPredicate<>(sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
i -> i % 3 == 0, Mode.UNTIL_CUT_BEFORE);
StepVerifier.create(windowUntilCutBefore.flatMap(Flux::materialize))
.expectSubscription()
.then(() -> sp1.onNext(1))
.expectNext(Signal.next(1))
.then(() -> sp1.onNext(2))
.expectNext(Signal.next(2))
.then(() -> sp1.onNext(3))
.expectNext(Signal.complete())
.expectNext(Signal.next(3))
.then(() -> sp1.onNext(4))
.expectNext(Signal.next(4))
.then(() -> sp1.onError(new RuntimeException("forced failure")))
//this is the error in the window:
.expectNextMatches(signalErrorMessage("forced failure"))
//this is the error in the main:
.expectErrorMessage("forced failure")
.verify();
assertThat(sp1.hasDownstreams()).isFalse();
}