当前位置: 首页>>代码示例>>Java>>正文


Java Publisher类代码示例

本文整理汇总了Java中org.reactivestreams.Publisher的典型用法代码示例。如果您正苦于以下问题:Java Publisher类的具体用法?Java Publisher怎么用?Java Publisher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Publisher类属于org.reactivestreams包,在下文中一共展示了Publisher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: activate

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Activate
public void activate(ComponentContext context) {
    Dictionary<String, Object> config = context.getProperties();
    this.topic = (String)config.get("topic");
    if (topic == null) {
        throw new IllegalArgumentException("Config property topic must be present.");
    }
    String eventTopics = (String)config.get(EventConstants.EVENT_TOPIC);
    Publisher<Event> fromEventAdmin = eventAdmin.from(eventTopics, Event.class);
    toKafka = kafka.to(topic, ProducerRecord.class);
    org.slf4j.MDC.put("inLogAppender", "true");
    Flux.from(fromEventAdmin)
        .doOnEach(event -> org.slf4j.MDC.put("inLogAppender", "true"))
        //.log()
        .map(event->toRecord(event))
        .doOnError(ex -> LOGGER.error(ex.getMessage(), ex))
        .subscribe(toKafka);
    LOGGER.info("Kafka appender started. Listening on topic " + topic);
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:20,代码来源:KafkaAppender.java

示例2: createPublisher

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Override
public Publisher<Long> createPublisher(final long elements) {
    return
        Flowable.generate(Functions.justCallable(0L),
        new BiFunction<Long, Emitter<Long>, Long>() {
            @Override
            public Long apply(Long s, Emitter<Long> e) throws Exception {
                e.onNext(s);
                if (++s == elements) {
                    e.onComplete();
                }
                return s;
            }
        }, Functions.<Long>emptyConsumer())
    ;
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:17,代码来源:GenerateTckTest.java

示例3: getSnapshot

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Override
default Publisher<SnapshotT> getSnapshot(Date maxTimestamp, AggregateT aggregate) {
    return toPublisher(defer(() -> {
        //noinspection unchecked
        List<SnapshotT> snapshots = (List<SnapshotT>) (maxTimestamp == null ?
                invokeStaticMethod(
                        getSnapshotClass(),
                        SNAPSHOTS_BY_AGGREGATE,
                        new Object[]{aggregate.getId(), LATEST_BY_TIMESTAMP}) :
                invokeStaticMethod(
                        getSnapshotClass(),
                        SNAPSHOTS_BY_TIMESTAMP,
                        new Object[]{aggregate.getId(), maxTimestamp, LATEST_BY_TIMESTAMP}));
        return DefaultGroovyMethods.asBoolean(snapshots) ?
                just(detachSnapshot(snapshots.get(0))) :
                empty();
    }));
}
 
开发者ID:rahulsom,项目名称:grooves,代码行数:19,代码来源:BlockingSnapshotSource.java

示例4: testStaticValues

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Test
public void testStaticValues() throws Exception {
    GraphQLSchema schema = newQuerySchema(it -> it
            .field(newStringField("a").dataFetcher(env -> "staticA"))
            .field(newStringField("b").dataFetcher(env -> "staticB"))
    );

    ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a, b }");

    Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber);

    subscriber
            .assertChanges(it -> it.containsExactly(
                    tuple("00:000", "", ImmutableMap.of("a", "staticA", "b", "staticB"))
            ))
            .assertComplete();
}
 
开发者ID:bsideup,项目名称:graphql-java-reactive,代码行数:18,代码来源:ReactiveExecutionStrategyTest.java

示例5: subscribeActual

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Override
protected void subscribeActual(Subscriber<? super R> s) {
    K key;
    Publisher<? extends R> source;

    try {
        key = caseSelector.call();
        source = mapOfCases.get(key);
    } catch (Throwable ex) {
        EmptySubscription.error(ex, s);
        return;
    }

    if (source == null) {
        source = defaultCase;
    }

    source.subscribe(s);
}
 
开发者ID:fengzhizi715,项目名称:RxConditions,代码行数:20,代码来源:FlowableSwitchCase.java

示例6: createPublisher

import org.reactivestreams.Publisher; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Publisher<Long> createPublisher(long elements) {
    return
        Flowable.combineLatest(Arrays.asList(
                Flowable.just(1L),
                Flowable.fromIterable(iterate(elements))
            ),
            new Function<Object[], Long>() {
                @Override
                public Long apply(Object[] a) throws Exception {
                    return (Long)a[0];
                }
            }
        )
    ;
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:18,代码来源:CombineLatestIterableTckTest.java

示例7: ParallelDeducer

import org.reactivestreams.Publisher; //导入依赖的package包/类
/**
 * Constructs a new ParallelDeducer with seven {@link Deducer deducers}.
 *
 * @param firstDeducer   The first {@link Deducer}.
 * @param secondDeducer  The second {@link Deducer}.
 * @param thirdDeducer   The third {@link Deducer}.
 * @param fourthDeducer  The fourth {@link Deducer}.
 * @param fifthDeducer   The fifth {@link Deducer}.
 * @param sixthDeducer   The sixth {@link Deducer}.
 * @param seventhDeducer The seventh {@link Deducer}.
 * @param combinator     A {@link Function7} which combines seven deductions.
 */
public ParallelDeducer(
    final Function<Publisher<I>, Publisher<? extends T1>> firstDeducer,
    final Function<Publisher<I>, Publisher<? extends T2>> secondDeducer,
    final Function<Publisher<I>, Publisher<? extends T3>> thirdDeducer,
    final Function<Publisher<I>, Publisher<? extends T4>> fourthDeducer,
    final Function<Publisher<I>, Publisher<? extends T5>> fifthDeducer,
    final Function<Publisher<I>, Publisher<? extends T6>> sixthDeducer,
    final Function<Publisher<I>, Publisher<? extends T7>> seventhDeducer,
    final Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends O> combinator
) {
  this.deducers = new Function[]{firstDeducer, secondDeducer, thirdDeducer, fourthDeducer,
      fifthDeducer, sixthDeducer, seventhDeducer};
  this.combinator = tuple -> combinator
      .apply((T1) tuple[0], (T2) tuple[1], (T3) tuple[2], (T4) tuple[3], (T5) tuple[4],
          (T6) tuple[5], (T7) tuple[6]);
}
 
开发者ID:delta-leonis,项目名称:zosma,代码行数:29,代码来源:ParallelDeducer.java

示例8: timed

import org.reactivestreams.Publisher; //导入依赖的package包/类
public static <T> Function<? super Publisher<T>, ? extends Publisher<T>> timed(MeterRegistry registry, String name, Iterable<Tag> tags) {
  Counter success = Counter.builder(name + ".request")
      .tags("status", "success")
      .tags(tags)
      .register(registry);
  Counter error = Counter.builder(name + ".request")
      .tags("status", "error")
      .tags(tags)
      .register(registry);
  Counter cancelled = Counter.builder(name + ".request")
      .tags("status", "cancelled")
      .tags(tags)
      .register(registry);
  Timer timer = Timer.builder(name + ".latency")
      .publishPercentileHistogram()
      .tags(tags)
      .register(registry);

  return Operators.lift((scannable, subscriber) ->
      new ProteusMetricsSubscriber<>(subscriber, success, error, cancelled, timer)
  );
}
 
开发者ID:netifi,项目名称:proteus-java,代码行数:23,代码来源:ProteusMetrics.java

示例9: flatMapIntPassthruSync

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Benchmark
public void flatMapIntPassthruSync(Input input) throws InterruptedException {
    input.observable.flatMap(new Function<Integer, Publisher<Integer>>() {
        @Override
        public Publisher<Integer> apply(Integer v) {
            return Flowable.just(v);
        }
    }).subscribe(input.newSubscriber());
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:10,代码来源:OperatorFlatMapPerf.java

示例10: applyFlowableAsysnc

import org.reactivestreams.Publisher; //导入依赖的package包/类
public <T> FlowableTransformer<T, T> applyFlowableAsysnc() {
    return new FlowableTransformer<T, T>() {
        @Override
        public Publisher<T> apply(Flowable<T> flowable) {
            return flowable.observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:RxSchedulers.java

示例11: registeringAStreamEmitsId

import org.reactivestreams.Publisher; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void registeringAStreamEmitsId() {
    StreamId<?> anyStreamId = mock(StreamId.class);
    TestSubscriber<StreamId<?>> subscriber = new TestSubscriber<>();
    Flowable.fromPublisher(newStreamHook()).take(1).subscribe(subscriber);

    provide(mock(Publisher.class)).as(anyStreamId);

    subscriber.awaitTerminalEvent(2, SECONDS);
    subscriber.assertValues(anyStreamId);
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:13,代码来源:LocalPoolHookTest.java

示例12: save

import org.reactivestreams.Publisher; //导入依赖的package包/类
private Publisher<DownloadStatus> save(final Response<ResponseBody> response) {
    return Flowable.create(new FlowableOnSubscribe<DownloadStatus>() {
        @Override
        public void subscribe(FlowableEmitter<DownloadStatus> e) throws Exception {
            record.save(e, response);
        }
    }, BackpressureStrategy.LATEST);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:DownloadType.java

示例13: testEqualityOfFlatMappedStreamIdOnNotEqualStreamSources

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Test
public void testEqualityOfFlatMappedStreamIdOnNotEqualStreamSources() {
    Function<Object, Publisher<Object>> conversion = o -> Flowable.empty();
    StreamId<Object> flatMappedStream1 = ComposedStreams.flatMappedStream(DUMMY_STREAM_ID_1, conversion);
    StreamId<Object> flatMappedStream2 = ComposedStreams.flatMappedStream(DUMMY_STREAM_ID_2, conversion);
    assertThat(flatMappedStream1).isNotEqualTo(flatMappedStream2);
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:8,代码来源:ComposedStreamsTest.java

示例14: clear

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Override
public Publisher<Void> clear(final long bitIndex) {
    return reactive(new Supplier<RFuture<Void>>() {
        @Override
        public RFuture<Void> get() {
            return instance.clearAsync(bitIndex);
        }
    });
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:10,代码来源:RedissonBitSetReactive.java

示例15: apply

import org.reactivestreams.Publisher; //导入依赖的package包/类
@Override
public Publisher<Referee> apply(
    final Publisher<org.robocup.ssl.RefereeOuterClass.Referee> refboxPublisher) {
  return Flux.from(refboxPublisher)
      .map(packet -> new Referee.State(
          packet.getPacketTimestamp(),
          Stage.valueOf(packet.getStage().name()),
          packet.getStageTimeLeft(),
          Command.valueOf(packet.getCommand().name()),
          ImmutableSet.of(
              this.createTeam(TeamColor.BLUE, packet.getBlue(), packet.getPacketTimestamp()),
              this.createTeam(TeamColor.YELLOW, packet.getYellow(), packet.getPacketTimestamp())),
          packet.getCommandTimestamp(),
          packet.getCommandCounter()));
}
 
开发者ID:delta-leonis,项目名称:subra,代码行数:16,代码来源:SSLRefboxDeducer.java


注:本文中的org.reactivestreams.Publisher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。