當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。