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


Java PublishSubject类代码示例

本文整理汇总了Java中io.reactivex.subjects.PublishSubject的典型用法代码示例。如果您正苦于以下问题:Java PublishSubject类的具体用法?Java PublishSubject怎么用?Java PublishSubject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: downloadProducts

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
@Override
public void downloadProducts(DownloadProductsRequest request, StreamObserver<Product> responseObserver) {
  PublishSubject<Product> productPublishSubject = PublishSubject.create();
  productPublishSubject
      .doOnNext(product -> {
        responseObserver.onNext(product);
        counter.labels("downloadProducts", "success");
      })
      .doOnComplete(() -> responseObserver.onCompleted())
      .doOnError(t -> {
        responseObserver.onError(t);
        counter.labels("downloadProducts", "failed");
      })
      .subscribe();
  productDao.downloadProducts(request, productPublishSubject);
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:17,代码来源:ProductReadService.java

示例2: showNameInputDialog

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
private Observable<String> showNameInputDialog(String prefix, MaterialDialog.InputCallback textWatcher) {
    final PublishSubject<String> input = PublishSubject.create();
    DialogUtils.showDialog(new ThemeColorMaterialDialogBuilder(mContext).title(R.string.text_name)
            .inputType(InputType.TYPE_CLASS_TEXT)
            .alwaysCallInputCallback()
            .input(getString(R.string.text_please_input_name), prefix, false, textWatcher)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    input.onNext(dialog.getInputEditText().getText().toString());
                    input.onComplete();
                }
            })
            .build());
    return input;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:17,代码来源:ScriptOperations.java

示例3: doSomeWork

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
/**
 * PublishSubject只会把在订阅发生的时间点之后来自原始Observable的数据发射给观察者。
 * 需要注意的是,PublishSubject可能会一创建完成就立刻开始发射数据(除非你可以阻止它发生),
 * 因此这里有一个风险:在Subject被创建后到有观察者订阅它之前这个时间段内,一个或多个数据可能会丢失。
 * 如果要确保来自原始Observable的所有数据都被分发:
 * 1.使用Create创建那个Observable以便手动给它引入"冷"Observable的行为(当所有观察者都已经订阅时才开始发射数据)
 * 2.改用ReplaySubject。
 *
 * 如果原始的Observable因为发生了一个错误而终止,PublishSubject将不会发射任何数据,只是简单的向前传递这个错误通知。
 */
private void doSomeWork() {

    PublishSubject<Integer> source = PublishSubject.create();

    source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete

    source.onNext(1);
    source.onNext(2);
    source.onNext(3);

    /*
     * it will emit 4 and onComplete for second observer also.
     */
    source.subscribe(getSecondObserver());

    source.onNext(4);
    source.onComplete();
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:29,代码来源:PublishSubjectExampleActivity.java

示例4: onRequestPermissionsResult

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        Log.i("","onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
开发者ID:ChangWeiBa,项目名称:AesExoPlayer,代码行数:17,代码来源:RxPermissionsFragment.java

示例5: monitor

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
private void monitor(InputStream input, PublishSubject<String> subject) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding));
    final int BUFFERSIZE = 4096;
    char[] buffer = new char[BUFFERSIZE];
    while (true) {
        try {
            if (Thread.interrupted()) {
                subject.onComplete();
                return;
            }
            int read = reader.read(buffer, 0, BUFFERSIZE);
            if (read == -1) {
                subject.onComplete();
                return;
            }

            subject.onNext(new String(buffer, 0, read));
        } catch (IOException e) {
            subject.onError(e);
            return;
        }
    }
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:24,代码来源:ProcessConsole.java

示例6: initView

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
private void initView() {
        subject = PublishSubject.create();
        subject.debounce(0, TimeUnit.MILLISECONDS)
//                .filter(new Predicate<Float>() {
//                    @Override
//                    public boolean test(Float brightness) throws Exception {
//                        return true;
//                    }
//                })
                .distinctUntilChanged()
                .switchMap(new Function<Float, ObservableSource<ColorMatrixColorFilter>>() {
                    @Override
                    public ObservableSource<ColorMatrixColorFilter> apply(Float value) throws Exception {
                        return postBrightness(value);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ColorMatrixColorFilter>() {
                    @Override
                    public void accept(ColorMatrixColorFilter colorMatrixColorFilter) throws Exception {
                        setColorFilter(colorMatrixColorFilter);
                    }
                });
    }
 
开发者ID:hoanganhtuan95ptit,项目名称:EditPhoto,代码行数:26,代码来源:BrightnessView.java

示例7: TranscodingServiceImpl

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
@Inject
TranscodingServiceImpl(ExternalProcessService externalProcessService,
                       TranscoderSettings transcoderSettings,
                       MediaScanSettings mediaScanSettings,
                       OutputParser parser) {
    this.externalProcessService = externalProcessService;
    this.transcoderSettings = transcoderSettings;
    this.mediaScanSettings = mediaScanSettings;

    this.parser = parser;

    this.publisher = PublishSubject.create().toSerialized();

    publisher.ofType(TranscodeTask.class)
             .skipWhile(o -> isActive())
             .observeOn(Schedulers.computation())
             .subscribeOn(Schedulers.io())
             .subscribe(this::prepareTranscode);
}
 
开发者ID:ccremer,项目名称:clustercode,代码行数:20,代码来源:TranscodingServiceImpl.java

示例8: onCreateView

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_two_way_data_biding, container, false);
    unbinder = ButterKnife.bind(this, view);

    publishSubject = PublishSubject.create();

    publishSubject.subscribe(new Consumer<String>() {
        @Override
        public void accept(String s) throws Exception {
            mTvAddResult.setText(s);
        }
    });

    onNumChanged();

    mEtAddLeft.requestFocus();

    return view;
}
 
开发者ID:jiangkang,项目名称:KTools,代码行数:23,代码来源:TwoWayDataBidingFragment.java

示例9: onUserQueryEvent_emptyQueryString_shouldDoNothingWithView

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
@Test
public void onUserQueryEvent_emptyQueryString_shouldDoNothingWithView() {
  // given
  PublishSubject<UserQueryEvent> userQuery$ = PublishSubject.create();
  UserListPresenter presenter = new UserListPresenter(
      userQuery$,
      userService,
      () -> mock(UserView.class),
      () -> mock(UserPresenter.class),
      DEFAULT_PAGE_SIZE,
      DEFAULT_USER_SEARCH_LIMIT
  );
  presenter.start(view);
  UserQueryEvent event = new UserQueryEvent(" "); // empty string

  // when
  userQuery$.onNext(event);

  // then
  verifyNoMoreInteractions(view, userService);
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:22,代码来源:UserListPresenterTest.java

示例10: onRequestPermissionsResult

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = (grantResults[i] == PackageManager.PERMISSION_GRANTED) && (PermissionChecker.checkSelfPermission(getContext(), permissions[i]) == PermissionChecker.PERMISSION_GRANTED);
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
开发者ID:CodyyAndroid,项目名称:RxPermissions,代码行数:17,代码来源:RxPermissionsFragment.java

示例11: registerNoThread

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
/**
 * 接受消息
 *
 * @param tag      标志
 * @param callBack 回调
 */
public <T> DisposableObserver registerNoThread(@NonNull final Object tag,
                                               @NonNull final RxBusCallBack<T> callBack) {
    RxBusEvent rxBusEvent = rxBusEventArrayMap.get(tag);
    if (RxUtils.isEmpty(rxBusEvent)) {
        rxBusEvent = new RxBusEvent();
        rxBusEvent.subject = PublishSubject.create().toSerialized();
        rxBusEvent.disposable =
                rxBusEvent.subject
                        .ofType(callBack.busOfType())
                        .subscribeWith(new RxBusObserver<T>() {
                            @Override
                            public void onError(@io.reactivex.annotations.NonNull Throwable e) {
                                super.onError(e);
                                callBack.onBusError(e);
                            }

                            @Override
                            public void onNext(@io.reactivex.annotations.NonNull T t) {
                                super.onNext(t);
                            }
                        });
        rxBusEventArrayMap.put(tag, rxBusEvent);
    }
    return rxBusEvent.disposable;
}
 
开发者ID:7449,项目名称:RxNetWork,代码行数:32,代码来源:RxBus.java

示例12: onUserSelected_view_shouldPostUserSelectedEvent

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
@Test
public void onUserSelected_view_shouldPostUserSelectedEvent() {
  // given
  TestObserver<UserSelectedEvent> userSelected$ = TestObserver.create();
  User user = mock(User.class);
  given(user.getLogin()).willReturn("foo");
  PublishSubject<Trigger> userSelectionIntent = PublishSubject.create();
  given(view.userSelection$()).willReturn(userSelectionIntent);

  UserPresenter presenter = new UserPresenter(Sink.of(userSelected$));
  presenter.start(user, view);

  // when
  fire(userSelectionIntent);

  // then
  userSelected$.assertValueCount(1);
  UserSelectedEvent event = userSelected$.values().get(0);
  assertThat(event.getUser().getLogin()).isEqualTo("foo");
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:21,代码来源:UserPresenterTest.java

示例13: refreshOnlineStatus

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
public Observable<Boolean> refreshOnlineStatus() {
    PublishSubject<Boolean> online = PublishSubject.create();
    mRetrofit.create(UserApi.class)
            .me()
            .subscribeOn(Schedulers.io())
            .subscribe(user -> {
                setUser(user);
                online.onNext(true);
                online.onComplete();
            }, error -> {
                setUser(null);
                online.onNext(false);
                online.onComplete();
            });
    return online;
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:17,代码来源:UserService.java

示例14: testGetStderrUpdatesEchoesUpdatesFromExecutorObservers

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
@Test
public void testGetStderrUpdatesEchoesUpdatesFromExecutorObservers() throws InterruptedException, ExecutionException, TimeoutException {
    final CancelablePromise<JobExecutionResult> executorPromise = new SimpleCancelablePromise<>();
    final Subject<byte[]> stderrSubject = PublishSubject.create();
    final JobExecutor executor =
            MockJobExecutor.thatUses(executorPromise, Observable.just(TestHelpers.generateRandomBytes()), stderrSubject);
    final JobManager jobManager = createManagerWith(executor);

    final Pair<JobId, CancelablePromise<FinalizedJob>> ret =
            jobManager.submit(STANDARD_VALID_REQUEST);

    final Observable<byte[]> stderrObservable =
            jobManager.stderrUpdates(ret.getLeft()).get();

    final AtomicReference<byte[]> bytesFromObservable = new AtomicReference<>();
    stderrObservable.subscribe(bytesFromObservable::set);

    final byte[] bytesExpected = TestHelpers.generateRandomBytes();
    stderrSubject.onNext(bytesExpected);

    executorPromise.complete(new JobExecutionResult(FINISHED));

    ret.getRight().get(DEFAULT_TIMEOUT, MILLISECONDS);

    assertThat(bytesFromObservable.get()).isEqualTo(bytesExpected);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:27,代码来源:JobManagerTest.java

示例15: initView

import io.reactivex.subjects.PublishSubject; //导入依赖的package包/类
private void initView() {
        subject = PublishSubject.create();
        subject.debounce(0, TimeUnit.MILLISECONDS)
//                .filter(new Predicate<Float>() {
//                    @Override
//                    public boolean test(Float contrast) throws Exception {
//                        return true;
//                    }
//                })
                .distinctUntilChanged()
                .switchMap(new Function<Float, ObservableSource<ColorMatrixColorFilter>>() {
                    @Override
                    public ObservableSource<ColorMatrixColorFilter> apply(Float value) throws Exception {
                        return postContrast(value);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ColorMatrixColorFilter>() {
                    @Override
                    public void accept(ColorMatrixColorFilter colorMatrixColorFilter) throws Exception {
                        setColorFilter(colorMatrixColorFilter);
                    }
                });
    }
 
开发者ID:hoanganhtuan95ptit,项目名称:EditPhoto,代码行数:26,代码来源:ContrastView.java


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