當前位置: 首頁>>代碼示例>>Java>>正文


Java PublishProcessor.create方法代碼示例

本文整理匯總了Java中io.reactivex.processors.PublishProcessor.create方法的典型用法代碼示例。如果您正苦於以下問題:Java PublishProcessor.create方法的具體用法?Java PublishProcessor.create怎麽用?Java PublishProcessor.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.processors.PublishProcessor的用法示例。


在下文中一共展示了PublishProcessor.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCommand_callback_sync

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void testCommand_callback_sync() throws IOException, InterruptedException {
    processor.attach(session);

    int cnt = 100;
    List<Pair<TestObserver<Cmd.Result>, TestSubscriber<String>>> testSubscribers = new ArrayList<>();
    for (int j = 0; j < cnt; j++) {
        List<String> cmds = new ArrayList<>();
        for (int i = 0; i < 10; i++) cmds.add("echo " + i);
        cmds.add("echo " + j);

        PublishProcessor<String> outputListener = PublishProcessor.create();
        TestSubscriber<String> outputObserver = outputListener.doOnEach(stringNotification -> TestHelper.sleep(1)).test();
        final Cmd cmd = Cmd.builder(cmds).outputProcessor(outputListener).build();
        final TestObserver<Cmd.Result> resultObserver = processor.submit(cmd).subscribeOn(Schedulers.newThread()).test();
        testSubscribers.add(new Pair<>(resultObserver, outputObserver));
    }
    for (Pair<TestObserver<Cmd.Result>, TestSubscriber<String>> pair : testSubscribers) {
        pair.first.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertComplete();
        pair.second.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(11);
    }
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:23,代碼來源:CmdProcessorTest.java

示例2: testCommand_callback_async

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void testCommand_callback_async() throws IOException, InterruptedException {
    processor.attach(session);

    int cnt = 100;
    List<Pair<TestObserver<Cmd.Result>, TestSubscriber<String>>> testSubscribers = new ArrayList<>();
    for (int j = 0; j < cnt; j++) {
        List<String> cmds = new ArrayList<>();
        for (int i = 0; i < 10; i++) cmds.add("echo " + i);
        cmds.add("echo " + j);

        PublishProcessor<String> outputListener = PublishProcessor.create();
        TestSubscriber<String> outputObserver = outputListener.observeOn(Schedulers.newThread()).doOnEach(stringNotification -> TestHelper.sleep(1)).test();
        final Cmd cmd = Cmd.builder(cmds).outputProcessor(outputListener).build();
        final TestObserver<Cmd.Result> resultObserver = processor.submit(cmd).subscribeOn(Schedulers.newThread()).test();
        testSubscribers.add(new Pair<>(resultObserver, outputObserver));
    }
    for (Pair<TestObserver<Cmd.Result>, TestSubscriber<String>> pair : testSubscribers) {
        pair.first.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertComplete();
        pair.second.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(11);
    }
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:23,代碼來源:CmdProcessorTest.java

示例3: testBuild

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void testBuild() {
    final PublishProcessor<String> outputPub = PublishProcessor.create();
    final PublishProcessor<String> errorPub = PublishProcessor.create();
    Cmd cmd = Cmd.builder("cmd1")
            .outputBuffer(false)
            .errorBuffer(false)
            .timeout(1337)
            .outputProcessor(outputPub)
            .errorProcessor(errorPub)
            .build();
    assertThat(cmd.getCommands(), contains("cmd1"));
    assertThat(cmd.getOutputProcessor(), is(outputPub));
    assertThat(cmd.getErrorProcessor(), is(errorPub));
    assertThat(cmd.getTimeout(), is(1337L));
    assertThat(cmd.isOutputBufferEnabled(), is(false));
    assertThat(cmd.isErrorBufferEnabled(), is(false));
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:19,代碼來源:CmdBuilderTest.java

示例4: process

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
public Flowable<String> process(Flowable<Byte> observableInput){

        PublishProcessor<String> publishProcessor = PublishProcessor.create();

        StringBuilder sb = new StringBuilder();
        observableInput.subscribe(b->{
                if(b==32){ //send out a new word on a space
                    publishProcessor.onNext(sb.toString());
                    sb.setLength(0);
                }else{
                    sb.append((char)b.byteValue());
                }
            },
            e->LOG.error("Error in BytesToWordsProcessor [{}]", e),
            publishProcessor::onComplete
        );

        return publishProcessor;
    }
 
開發者ID:danielshaya,項目名稱:reactivejournal,代碼行數:20,代碼來源:BytesToWordsProcessor.java

示例5: test

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test public void test() {

        PublishProcessor<String> subject = PublishProcessor.create();
        Flowable<String> source = subject.hide();



        TestSubscriber testSubscriber = new TestSubscriber();
        CompositeDisposable composite = new CompositeDisposable();
        Disposable disposable = source
                .compose(DisposableAttach.<String>to(composite))
                .subscribeWith(testSubscriber);

        subject.onNext("Foo");
        testSubscriber.assertValue("Foo");
        assertTrue(composite.size() == 1);
        composite.dispose();
        assertTrue(composite.size() == 0);
        assertTrue(composite.isDisposed());
        assertTrue(disposable.isDisposed());
        assertTrue(testSubscriber.isDisposed());
    }
 
開發者ID:cp949,項目名稱:DisposableAttach,代碼行數:23,代碼來源:DisposableAttachFlowableTest.java

示例6: depthCompleteCancelRace

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void depthCompleteCancelRace() {
    for (int i = 0; i < 1000; i++) {

        final PublishProcessor<Integer> pp = PublishProcessor.create();

        final TestSubscriber<Integer> ts = Flowable.just(0)
        .compose(FlowableTransformers.<Integer>expand(Functions.justFunction(pp), ExpandStrategy.DEPTH_FIRST))
        .test(1);

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                pp.onComplete();
            }
        };
        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                ts.cancel();
            }
        };

        TestHelper.race(r1, r2, Schedulers.single());
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava2Extensions,代碼行數:27,代碼來源:FlowableExpandTest.java

示例7: flowableProcessorToFlowProcessor

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void flowableProcessorToFlowProcessor() {
    PublishProcessor<Integer> pp = PublishProcessor.create();

    Flow.Processor<Integer, Integer> fp = FlowInterop.toFlowProcessor(pp);

    FlowTestSubscriber<Integer> ts = new FlowTestSubscriber<>();
    fp.subscribe(ts);

    pp.onNext(1);
    pp.onNext(2);
    pp.onNext(3);
    pp.onNext(4);
    pp.onNext(5);
    pp.onComplete();

    ts.assertResult(1, 2, 3, 4, 5);
}
 
開發者ID:akarnokd,項目名稱:RxJava2Jdk9Interop,代碼行數:19,代碼來源:FlowInteropTest.java

示例8: valueMissedWhenNoSubscribers

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test public void valueMissedWhenNoSubscribers() {
  PublishProcessor<String> subject = PublishProcessor.create();
  Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance());

  TestSubscriber<String> subscriber1 = new TestSubscriber<>();
  flowable.subscribe(subscriber1);
  subscriber1.assertNoValues();
  subscriber1.dispose();

  subject.onNext("Foo");
  subscriber1.assertNoValues();

  TestSubscriber<String> subscriber2 = new TestSubscriber<>();
  flowable.subscribe(subscriber2);
  subscriber2.assertNoValues();
}
 
開發者ID:JakeWharton,項目名稱:RxReplayingShare,代碼行數:17,代碼來源:ReplayingShareFlowableTest.java

示例9: slowPathQueueUse

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void slowPathQueueUse() {
    final PublishProcessor<Integer> pp = PublishProcessor.create();

    TestSubscriber<List<Integer>> ts = new TestSubscriber<List<Integer>>() {
        @Override
        public void onNext(List<Integer> t) {
            super.onNext(t);
            if (t.get(0) == 1) {
                pp.onNext(100);
            }
        }
    };

    pp.compose(FlowableTransformers.coalesce(listSupplier, listAdd)).subscribe(ts);

    pp.onNext(1);
    pp.onComplete();

    ts.assertResult(Arrays.asList(1), Arrays.asList(100));
}
 
開發者ID:akarnokd,項目名稱:RxJava2Extensions,代碼行數:23,代碼來源:FlowableCoalesceTest.java

示例10: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  PublishProcessor<Integer> source = PublishProcessor.create();
  TestSubscriber<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  assertThat(source.hasSubscribers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:22,代碼來源:AutoDisposeSubscriberTest.java

示例11: onCreateView

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Override
public View onCreateView(
    LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View layout = inflater.inflate(R.layout.fragment_double_binding_textview, container, false);
  unbinder = ButterKnife.bind(this, layout);

  _resultEmitterSubject = PublishProcessor.create();

  _disposable =
      _resultEmitterSubject.subscribe(
          aFloat -> {
            _result.setText(String.valueOf(aFloat));
          });

  onNumberChanged();
  _number2.requestFocus();

  return layout;
}
 
開發者ID:kaushikgopal,項目名稱:RxJava-Android-Samples,代碼行數:20,代碼來源:DoubleBindingTextViewFragment.java

示例12: onStart

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Override
public void onStart() {
  super.onStart();

  publishProcessor = PublishProcessor.create();

  disposable =
      publishProcessor
          .startWith(getConnectivityStatus(getActivity()))
          .distinctUntilChanged()
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(
              online -> {
                if (online) {
                  log("You are online");
                } else {
                  log("You are offline");
                }
              });

  listenToNetworkConnectivity();
}
 
開發者ID:kaushikgopal,項目名稱:RxJava-Android-Samples,代碼行數:23,代碼來源:NetworkDetectorFragment.java

示例13: testUpstreamTerminated_output

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void testUpstreamTerminated_output() {
    publisher.onComplete();
    OutputHarvester.Crop crop = publisher.compose(harvesterFactory.forOutput(publisher, cmd)).test().assertComplete().assertValueCount(1).values().get(0);
    assertThat(crop.isComplete, is(false));

    publisher = PublishProcessor.create();
    publisher.onError(new InterruptedException());
    crop = publisher.compose(harvesterFactory.forOutput(publisher, cmd)).test().assertComplete().assertValueCount(1).values().get(0);
    assertThat(crop.isComplete, is(false));
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:12,代碼來源:HarvesterTest.java

示例14: testUpstreamTerminated_error

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Test
public void testUpstreamTerminated_error() {
    publisher.onComplete();
    ErrorHarvester.Crop crop = publisher.compose(harvesterFactory.forError(publisher, cmd)).test().assertComplete().assertValueCount(1).values().get(0);
    assertThat(crop.isComplete, is(false));

    publisher = PublishProcessor.create();
    publisher.onError(new InterruptedException());
    crop = publisher.compose(harvesterFactory.forError(publisher, cmd)).test().assertComplete().assertValueCount(1).values().get(0);
    assertThat(crop.isComplete, is(false));
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:12,代碼來源:HarvesterTest.java

示例15: onCreate

import io.reactivex.processors.PublishProcessor; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    resultPublisher = PublishProcessor.create();
    subscriber = resultPublisher.subscribe(aFloat -> {
        tvSum.setText("Sum = " + aFloat);
    });
    onNumberChanged();
}
 
開發者ID:shuza,項目名稱:RxAndroid-Examples,代碼行數:13,代碼來源:MainActivity.java


注:本文中的io.reactivex.processors.PublishProcessor.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。