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


Java Publisher.subscribe方法代码示例

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


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

示例1: reducePub

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
private static <T,R> Publisher<R> reducePub(Publisher<T> pub, R init, BiFunction<R, T, R> bf) {
    return new Publisher<R>() {
        @Override
        public void subscribe(Subscriber<? super R> sub) {
            pub.subscribe(new DelegateSub<T, R>(sub) {
                R result = init;

                @Override
                public void onNext(T t) {
                    result = bf.apply(result, t);
                }

                @Override
                public void onComplete() {
                    sub.onNext(result);
                    sub.onComplete();
                }
            });
        }
    };
}
 
开发者ID:sejoung,项目名称:ReactiveTest,代码行数:22,代码来源:PubSub2.java

示例2: sumPub

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
private static Publisher<Integer> sumPub(Publisher<Integer> pub) {
    return new Publisher<Integer>() {
        @Override
        public void subscribe(Subscriber sub) {
            pub.subscribe(new DelegateSub<Integer, Integer>(sub) {

                int sum = 0;

                @Override
                public void onNext(Integer t) {
                    sum += t;
                }

                @Override
                public void onComplete() {
                    sub.onNext(sum);
                    sub.onComplete();
                }
            });
        }
    };
}
 
开发者ID:sejoung,项目名称:ReactiveTest,代码行数:23,代码来源:PubSub2.java

示例3: 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

示例4: onHeaders

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
@Override
public void onHeaders(Response response) {
    if (logger.isDebugEnabled()) {
        logger.debug("received response headers {}", response);
    }
    Publisher<T> publisher = contentFn.apply(request.getReactiveResponse(), content);
    publisher.subscribe(this);
}
 
开发者ID:jetty-project,项目名称:jetty-reactive-httpclient,代码行数:9,代码来源:ResponseListenerPublisher.java

示例5: executeAsync

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
public RFuture<BatchResult<?>> executeAsync(int syncSlaves, long syncTimeout, boolean skipResult, long responseTimeout, int retryAttempts, long retryInterval) {
    for (Publisher<?> publisher : publishers) {
        publisher.subscribe(new DefaultSubscriber<Object>() {
            @Override
            public void onSubscribe(Subscription s) {
                s.request(1);
            }
        });
    }

    return batchService.executeAsync(syncSlaves, syncTimeout, skipResult, responseTimeout, retryAttempts, retryInterval);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:13,代码来源:CommandReactiveBatchService.java

示例6: record

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
public void record(Publisher<?> publisher, String filter) {
    ChronicleQueue queue = reactiveJournal.createQueue();
    ExcerptAppender appender = queue.acquireAppender();

    TriConsumer<ExcerptAppender, String, Object> onNextConsumer = getOnNextConsumerRecorder();
    BiConsumer<ExcerptAppender, String> onCompleteConsumer = getOnCompleteRecorder();
    TriConsumer<ExcerptAppender, String, Throwable> onErrorConsumer = getOnErrorRecorder();

    publisher.subscribe(new Subscriber<Object>() {
        @Override
        public void onSubscribe(Subscription subscription) {
            subscription.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(Object o) {
            onNextConsumer.accept(appender, filter, o);
        }

        @Override
        public void onError(Throwable throwable) {
            onErrorConsumer.accept(appender, filter, throwable);
        }

        @Override
        public void onComplete() {
            onCompleteConsumer.accept(appender, filter);
        }
    });
}
 
开发者ID:danielshaya,项目名称:reactivejournal,代码行数:31,代码来源:ReactiveRecorder.java

示例7: main

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
public static void main(String[] args) {
    //Operators
    // Publisher -> Data1 -> Operator1 -> Data2 -> Operator2 -> Data3 -> Subscriber
    // map (d1 -> d2)

    Publisher<Integer> pub = iterPub(Stream.iterate(1, a -> a + 1).limit(10).collect(Collectors.toList()));
   // Publisher<String> mapPub = mapPub(pub, s -> "[" + s + "]");
    /// Publisher<Integer> sumPub = sumPub(pub);
    Publisher<StringBuilder> reducePub = reducePub(pub, new StringBuilder(), (a, b)->a.append(b+","));

    reducePub.subscribe(logSub());

    abc:{
        System.out.println("1");
        if(2==1)
        break abc;
        System.out.println("2");

    }

    if (2 ==1){

    }else for (int i=0 ; i<10 ; i++){

        System.out.println(i);
    }

}
 
开发者ID:sejoung,项目名称:ReactiveTest,代码行数:29,代码来源:PubSub2.java

示例8: mapPub

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
private static <T, R> Publisher<R> mapPub(Publisher<T> pub, Function<T, R> f) {
    return new Publisher<R>() {
        @Override
        public void subscribe(Subscriber<? super R> sub) {
            pub.subscribe(new DelegateSub<T, R>(sub) {
                @Override
                public void onNext(T t) {
                    sub.onNext(f.apply(t));
                }
            });
        }
    };
}
 
开发者ID:sejoung,项目名称:ReactiveTest,代码行数:14,代码来源:PubSub2.java

示例9: assertResult

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
public static <T> void assertResult(Publisher<T> source, T... array) {
    TestSubscriber<T> ts = new TestSubscriber<T>();

    source.subscribe(ts);

    ts.assertValues(array)
    .assertNoErrors()
    .assertComplete();
}
 
开发者ID:akaita,项目名称:RxJava2Debug,代码行数:10,代码来源:BaseTest.java

示例10: onStream

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
@Override
public void onStream(Publisher<ByteBuffer> publisher) {
    publisher.subscribe(new SimpleSubscriber(byteBuffer -> {
        byte[] b = new byte[byteBuffer.remaining()];
        byteBuffer.duplicate().get(b);
        bodyParts.append(new String(b, StandardCharsets.UTF_8));
    }));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:9,代码来源:RecordingResponseHandler.java

示例11: onStream

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
@Override
public void onStream(Publisher<ByteBuffer> publisher) {
    baos = new ByteArrayOutputStream();
    publisher.subscribe(new SimpleSubscriber(b -> {
        try {
            baos.write(BinaryUtils.copyBytesFrom(b));
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:12,代码来源:SyncResponseHandlerAdapter.java

示例12: PublisherContent

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
public PublisherContent(Publisher<ContentChunk> publisher, String contentType) {
    this.contentType = Objects.requireNonNull(contentType);
    publisher.subscribe(this);
}
 
开发者ID:jetty-project,项目名称:jetty-reactive-httpclient,代码行数:5,代码来源:PublisherContent.java

示例13: main

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    //1. Create the reactiveRecorder and delete any previous content by clearing the cache
    ReactiveJournal reactiveJournal = new ReactiveJournal(tmpDir + File.separator + "HW");
    reactiveJournal.clearCache();

    //2. Create a HelloWorld Publisher
    Publisher<String> helloWorldFlowable = subscriber -> {
        subscriber.onNext("Hello World!");
        subscriber.onComplete();
    };

    //3. Pass the Publisher into the reactiveRecorder which will subscribe to it and record all events.
    ReactiveRecorder reactiveRecorder = reactiveJournal.createReactiveRecorder();
    reactiveRecorder.record(helloWorldFlowable, "");

    //4. Subscribe to ReactiveJournal and print out results
    Publisher recordedObservable = reactiveJournal.createReactivePlayer().play(new PlayOptions());

    recordedObservable.subscribe(new Subscriber() {
        @Override
        public void onSubscribe(Subscription subscription) {
            subscription.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(Object o) {
            System.out.println(o);
        }

        @Override
        public void onError(Throwable throwable) {
            System.err.println(throwable);
        }

        @Override
        public void onComplete() {
            System.out.println("Hello World Complete");
        }
    });

    //5. Sometimes useful to see the recording written to a file
    reactiveJournal.writeToFile(tmpDir + File.separator + "/hw.txt",true);
}
 
开发者ID:danielshaya,项目名称:reactivejournal,代码行数:44,代码来源:HelloWorld.java

示例14: onWebSocketText

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
@Override
public void onWebSocketText(String graphqlQuery) {
    log.info("Websocket said {}", graphqlQuery);

    QueryParameters parameters = QueryParameters.from(graphqlQuery);

    ExecutionInput executionInput = ExecutionInput.newExecutionInput()
            .query(parameters.getQuery())
            .variables(parameters.getVariables())
            .operationName(parameters.getOperationName())
            .build();

    Instrumentation instrumentation = new ChainedInstrumentation(
            singletonList(new TracingInstrumentation())
    );

    //
    // In order to have subscriptions in graphql-java you MUST use the
    // SubscriptionExecutionStrategy strategy.
    //
    GraphQL graphQL = GraphQL
            .newGraphQL(graphqlPublisher.getGraphQLSchema())
            .instrumentation(instrumentation)
            .build();

    ExecutionResult executionResult = graphQL.execute(executionInput);

    Publisher<ExecutionResult> stockPriceStream = executionResult.getData();

    stockPriceStream.subscribe(new Subscriber<ExecutionResult>() {

        @Override
        public void onSubscribe(Subscription s) {
            subscriptionRef.set(s);
            request(1);
        }

        @Override
        public void onNext(ExecutionResult er) {
            log.debug("Sending stick price update");
            try {
                Object stockPriceUpdate = er.getData();
                getRemote().sendString(JsonKit.toJsonString(stockPriceUpdate));
            } catch (IOException e) {
                e.printStackTrace();
            }
            request(1);
        }

        @Override
        public void onError(Throwable t) {
            log.error("Subscription threw an exception", t);
            getSession().close();
        }

        @Override
        public void onComplete() {
            log.info("Subscription complete");
            getSession().close();
        }
    });
}
 
开发者ID:graphql-java,项目名称:graphql-java-subscription-example,代码行数:63,代码来源:StockTickerWebSocket.java

示例15: subscribe

import org.reactivestreams.Publisher; //导入方法依赖的package包/类
void subscribe(Publisher<? extends T> source1, Publisher<? extends T> source2) {
    source1.subscribe(first);
    source2.subscribe(second);
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:5,代码来源:FlowableSequenceEqualSingle.java


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