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


Java Flowable.subscribe方法代码示例

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


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

示例1: bodyRespectsBackpressure

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test public void bodyRespectsBackpressure() {
  server.enqueue(new MockResponse().setBody("Hi"));

  RecordingSubscriber<String> subscriber = subscriberRule.createWithInitialRequest(0);
  Flowable<String> o = service.body();

  o.subscribe(subscriber);
  assertThat(server.getRequestCount()).isEqualTo(1);
  subscriber.assertNoEvents();

  subscriber.request(1);
  subscriber.assertAnyValue().assertComplete();

  subscriber.request(Long.MAX_VALUE); // Subsequent requests do not trigger HTTP or notifications.
  assertThat(server.getRequestCount()).isEqualTo(1);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:FlowableTest.java

示例2: responseRespectsBackpressure

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test public void responseRespectsBackpressure() {
  server.enqueue(new MockResponse().setBody("Hi"));

  RecordingSubscriber<Response<String>> subscriber = subscriberRule.createWithInitialRequest(0);
  Flowable<Response<String>> o = service.response();

  o.subscribe(subscriber);
  assertThat(server.getRequestCount()).isEqualTo(1);
  subscriber.assertNoEvents();

  subscriber.request(1);
  subscriber.assertAnyValue().assertComplete();

  subscriber.request(Long.MAX_VALUE); // Subsequent requests do not trigger HTTP or notifications.
  assertThat(server.getRequestCount()).isEqualTo(1);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:FlowableTest.java

示例3: resultRespectsBackpressure

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test public void resultRespectsBackpressure() {
  server.enqueue(new MockResponse().setBody("Hi"));

  RecordingSubscriber<Result<String>> subscriber = subscriberRule.createWithInitialRequest(0);
  Flowable<Result<String>> o = service.result();

  o.subscribe(subscriber);
  assertThat(server.getRequestCount()).isEqualTo(1);
  subscriber.assertNoEvents();

  subscriber.request(1);
  subscriber.assertAnyValue().assertComplete();

  subscriber.request(Long.MAX_VALUE); // Subsequent requests do not trigger HTTP or notifications.
  assertThat(server.getRequestCount()).isEqualTo(1);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:FlowableTest.java

示例4: main

import io.reactivex.Flowable; //导入方法依赖的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 an RxJava Hello World Flowable
    Flowable<String> helloWorldFlowable = Flowable.just("Hello World!!");
    //3. Pass the flowable into the reactiveRecorder which will subscribe to it and record all events.
    ReactiveRecorder reactiveRecorder = reactiveJournal.createReactiveRecorder();
    reactiveRecorder.record(helloWorldFlowable, "");

    //4. Use the utility class RxJavaPlayer to subscribe to the journal
    RxJavaPlayer rxPlayer = new RxJavaPlayer(reactiveJournal);
    Flowable recordedObservable = rxPlayer.play(new PlayOptions());

    //5. Print out what we get as a callback to onNext().
    recordedObservable.subscribe(System.out::println);

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

示例5: wrongGenericClassThrows

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
@UiThreadTest
public void wrongGenericClassThrows() {
    realm.beginTransaction();
    final AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();

    Flowable<CyclicType> obs = obj.asFlowable();
    @SuppressWarnings("unused")
    Disposable subscription = obs.subscribe(new Consumer<CyclicType>() {
        @Override
        public void accept(CyclicType cyclicType) throws Exception {
            fail();
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(Throwable ignored) throws Exception {
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RxJavaTests.java

示例6: test_just_Flowable

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test_just_Flowable() {

	Flowable<String> observable = Flowable.just("mango", "papaya", "guava");
	TestSubscriber<String> testSubscriber = new TestSubscriber<>();

	observable.subscribe(testSubscriber);

	List<String> items = testSubscriber.values();
	testSubscriber.assertComplete();
	testSubscriber.assertSubscribed();
	testSubscriber.assertNoErrors();
	testSubscriber.assertValueCount(3);
	testSubscriber.assertValues("mango", "papaya", "guava");

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:17,代码来源:Modern_Testing.java

示例7: realmObject_closeInDoOnUnsubscribe

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
@UiThreadTest
public void realmObject_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class);
    realm.commitTransaction();

    Flowable<AllTypes> flowable = realm.where(AllTypes.class).findFirst().<AllTypes>asFlowable()
            .doOnCancel(new Action() {
                @Override
                public void run() throws Exception {
                    realm.close();
                }
            });

    subscription = flowable.subscribe(new Consumer<AllTypes>() {
        @Override
        public void accept(AllTypes ignored) throws Exception {
        }
    });

    subscription.dispose();
    assertTrue(realm.isClosed());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RxJavaTests.java

示例8: requestPressure

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Single<NumberProto.Number> requestPressure(Flowable<NumberProto.Number> request) {
    if (explicitCancel.get()) {
        // Process a very long sequence
        Disposable subscription = request.subscribe(n -> System.out.println("S: " + n.getNumber(0)));
        return Single
                .just(protoNum(-1))
                .delay(250, TimeUnit.MILLISECONDS)
                // Explicitly cancel by disposing the subscription
                .doOnSuccess(x -> subscription.dispose());
    } else {
        // Process some of a very long sequence and cancel implicitly with a take(10)
        return request.map(req -> req.getNumber(0))
                .doOnNext(System.out::println)
                .take(10)
                .last(-1)
                .map(CancellationPropagationIntegrationTest::protoNum);
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:20,代码来源:CancellationPropagationIntegrationTest.java

示例9: to

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Sink<T> to(Sink<T> sink) {

  // TODO Error management
  Flowable<Data<Void>> flowable = flow
    .flatMapCompletable(sink::dispatch)
    .doOnError(Throwable::printStackTrace)
    .toFlowable();

  DataStreamImpl<T, Void> last = new DataStreamImpl<>(
    this,
    flowable
  );

  this.setDownstreams(last);

  flowable.subscribe();
  return sink;
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:20,代码来源:DataStreamImpl.java

示例10: testOrganization

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testOrganization() {
    ServiceLocator.put(OkHttpClient.class, OkHttpClientUtil.getOkHttpClient(null, MockBehavior.MOCK));
    Flowable<Organization> flowable = ServiceInjector.resolve(RxEndpoints.class).getOrg("bottlerocketstudios");
    TestSubscriber<Organization> testSubscriber = new TestSubscriber<>();
    flowable.subscribe(testSubscriber);
    testSubscriber.assertComplete();
    List<Organization> orgList = testSubscriber.values();
    assertEquals(orgList.size(), 1);
    assertEquals(orgList.get(0).getName(), "Bottle Rocket Studios");
}
 
开发者ID:politedog,项目名称:mock-interceptor,代码行数:12,代码来源:OrganizationTest.java

示例11: main

import io.reactivex.Flowable; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

        //Create the reactiveRecorder and delete any previous content by clearing the cache
        ReactiveJournal reactiveJournal = new ReactiveJournal(FILE_NAME);
        reactiveJournal.clearCache();

        //Pass the input stream into the reactiveRecorder which will subscribe to it and record all events.
        //The subscription will not be activated on a new thread which will allow this program to continue.
        ReactiveRecorder reactiveRecorder = reactiveJournal.createReactiveRecorder();
        reactiveRecorder.recordAsync(observableInput, INPUT_FILTER);

        BytesToWordsProcessor bytesToWords = new BytesToWordsProcessor();

        //Retrieve a stream of
        RxJavaPlayer rxPlayer = new RxJavaPlayer(reactiveJournal);
        PlayOptions options = new PlayOptions().filter(INPUT_FILTER).playFromNow(true);
        ConnectableFlowable recordedObservable = rxPlayer.play(options).publish();
        //Pass the input Byte stream into the BytesToWordsProcessor class which subscribes to the stream and returns
        //a stream of words.
        Flowable<String> flowableOutput = bytesToWords.process(recordedObservable);

        //Pass the output stream (of words) into the reactiveRecorder which will subscribe to it and record all events.
        reactiveRecorder.record(flowableOutput, OUTPUT_FILTER);
        flowableOutput.subscribe(s -> LOG.info("HelloWorldHot->" + s),
                throwable -> LOG.error("", throwable),
                ()->LOG.info("HelloWorldHot Complete"));
        //Only start the recording now because we want to make sure that the BytesToWordsProcessor and the reactiveRecorder
        //are both setup up to receive subscriptions.
        recordedObservable.connect();
        //Sometimes useful to see the recording written to a file
        reactiveJournal.writeToFile("/tmp/Demo/demo.txt",true);
    }
 
开发者ID:danielshaya,项目名称:reactivejournal,代码行数:33,代码来源:HelloWorldApp_JournalPlayThrough.java

示例12: testEmptyAnd

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testEmptyAnd()
{
    Flowable<Boolean> joined = BooleanFlowables.and();

    TestSubscriber<Boolean> results = new TestSubscriber<>();

    joined.subscribe(results);

    results.assertValues(false);
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:12,代码来源:BooleanFlowablesTest.java

示例13: oneToMany

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * Implements a unary -> stream call as {@link Single} -> {@link Flowable}, where the server responds with a
 * stream of messages.
 */
public static <TRequest, TResponse> void oneToMany(
        TRequest request, StreamObserver<TResponse> responseObserver,
        Function<Single<TRequest>, Flowable<TResponse>> delegate) {
    try {
        Single<TRequest> rxRequest = Single.just(request);

        Flowable<TResponse> rxResponse = Preconditions.checkNotNull(delegate.apply(rxRequest));
        rxResponse.subscribe(new ReactivePublisherBackpressureOnReadyHandler<TResponse>(
                (ServerCallStreamObserver<TResponse>) responseObserver));
    } catch (Throwable throwable) {
        responseObserver.onError(prepareError(throwable));
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:18,代码来源:ServerCalls.java

示例14: doRxJavaWork

import io.reactivex.Flowable; //导入方法依赖的package包/类
private void doRxJavaWork() {
    Flowable<String> flowable = Flowable.create(new FlowableOnSubscribe<String>() {
        @Override
        public void subscribe(FlowableEmitter<String> e) throws Exception {
            e.onNext("事件1");
            e.onNext("事件2");
            e.onNext("事件3");
            e.onNext("事件4");
            e.onComplete();
        }
    }, BackpressureStrategy.BUFFER);

    Subscriber<String> subscriber = new Subscriber<String>() {
        @Override
        public void onSubscribe(Subscription s) {
            Log.d(TAG, "onSubscribe: ");
            s.request(Long.MAX_VALUE);

        }

        @Override
        public void onNext(String string) {
            Log.d(TAG, "onNext: " + string);
        }

        @Override
        public void onError(Throwable t) {
            Log.d(TAG, "onError: " + t.toString());
        }

        @Override
        public void onComplete() {
            Log.d(TAG, "onComplete: ");

        }
    };

    flowable.subscribe(subscriber);
}
 
开发者ID:RyanHuen,项目名称:GetStartRxJava2.0,代码行数:40,代码来源:BaseFlowableActivity.java

示例15: testSubjectMapTransform

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testSubjectMapTransform()
{
    TestSubscriber<Update<Flowable<String>>> testSubscriber = new TestSubscriber<>();

    TestSubscriber<String> subscriber0 = new TestSubscriber<>();
    TestSubscriber<String> subscriber1 = new TestSubscriber<>();
    TestSubscriber<String> subscriber2 = new TestSubscriber<>();

    SubjectMap<Integer, String> subjectMap = new SubjectMap<>();
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>(Arrays.asList(1, 2, 3));
    FlowableList<Flowable<String>> transformedList = list.map(subjectMap);

    transformedList.updates().subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);

    List<Update<Flowable<String>>> onNextEvents = testSubscriber.values();
    Update<Flowable<String>> update = onNextEvents.get(0);

    Flowable<String> value0 = update.list.get(0);
    Flowable<String> value1 = update.list.get(1);
    Flowable<String> value2 = update.list.get(2);

    value0.subscribe(subscriber0);
    value1.subscribe(subscriber1);
    value2.subscribe(subscriber2);

    subjectMap.onNext(1, "A");
    subjectMap.onNext(2, "B");
    subjectMap.onNext(3, "C");

    assertEquals(Arrays.asList(Change.reloaded()), update.changes);
    assertEquals("A", subscriber0.values().get(0));
    assertEquals("B", subscriber1.values().get(0));
    assertEquals("C", subscriber2.values().get(0));
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:38,代码来源:TransformFlowableListTest.java


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