本文整理汇总了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);
}
示例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())
;
}
示例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();
}));
}
示例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();
}
示例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);
}
示例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];
}
}
)
;
}
示例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]);
}
示例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)
);
}
示例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());
}
示例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());
}
};
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
});
}
示例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()));
}