本文整理汇总了Java中io.reactivex.subjects.PublishSubject.onNext方法的典型用法代码示例。如果您正苦于以下问题:Java PublishSubject.onNext方法的具体用法?Java PublishSubject.onNext怎么用?Java PublishSubject.onNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.subjects.PublishSubject
的用法示例。
在下文中一共展示了PublishSubject.onNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
}
}
示例3: eventOutOfLifecycle
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void eventOutOfLifecycle() {
PublishSubject<String> stream = PublishSubject.create();
PublishSubject<String> lifecycle = PublishSubject.create();
TestObserver<String> testObserver = stream
.compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
.test();
// Event is out of lifecycle, but this just results in completing the stream
lifecycle.onNext("destroy");
stream.onNext("1");
testObserver.assertNoValues();
testObserver.assertComplete();
}
示例4: doSomeWork
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
private void doSomeWork() {
PublishSubject<Integer> source = PublishSubject.create();
ConnectableObservable<Integer> connectableObservable = source.replay(3); // bufferSize = 3 to retain 3 values to replay
connectableObservable.connect(); // connecting the connectableObservable
connectableObservable.subscribe(getFirstObserver());
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onNext(4);
source.onComplete();
/*
* it will emit 2, 3, 4 as (count = 3), retains the 3 values for replay
*/
connectableObservable.subscribe(getSecondObserver());
}
示例5: 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();
}
}
示例6: 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;
subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
subject.onComplete();
}
}
示例7: 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();
}
示例8: onUserQuery_2subsequentQueriesProvided_shouldPost2EventsWithQueryString
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void onUserQuery_2subsequentQueriesProvided_shouldPost2EventsWithQueryString() {
// given
TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
PublishSubject<String> userQueryIntents = PublishSubject.create();
given(view.queryInput$()).willReturn(userQueryIntents);
UserQueryPresenter presenter = new UserQueryPresenter(Sink.of(userQuery$));
presenter.start(view);
// when
userQueryIntents.onNext("foo");
userQueryIntents.onNext("bar");
// then
userQuery$.assertValueCount(2);
List<UserQueryEvent> events = userQuery$.values();
assertThat(events)
.extracting(UserQueryEvent::getQuery)
.containsExactly("foo", "bar");
}
示例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);
}
示例10: rxActivity_delaySubscription_shouldIgnoreOtherEvents
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void rxActivity_delaySubscription_shouldIgnoreOtherEvents() {
ActivityController<EmptyActivity> activityController = buildActivity(EmptyActivity.class);
final RibActivity activity = activityController.get();
final PublishSubject<Object> subject = PublishSubject.create();
AndroidRecordingRx2Observer<Object> o = new AndroidRecordingRx2Observer<>();
subject
.hide()
.delaySubscription(
activity
.lifecycle()
.filter(
new Predicate<ActivityLifecycleEvent>() {
@Override
public boolean test(ActivityLifecycleEvent activityEvent) throws Exception {
return activityEvent.getType() == ActivityLifecycleEvent.Type.RESUME;
}
}))
.subscribe(o);
subject.onNext(new Object());
activityController.create();
subject.onNext(new Object());
o.assertNoMoreEvents();
activityController.start();
subject.onNext(new Object());
o.assertNoMoreEvents();
activityController.postCreate(null);
subject.onNext(new Object());
o.assertNoMoreEvents();
activityController.resume();
subject.onNext(new Object());
assertThat(o.takeNext()).isNotNull();
o.assertNoMoreEvents();
}
示例11: eventThrowsBadException
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void eventThrowsBadException() {
PublishSubject<String> stream = PublishSubject.create();
PublishSubject<String> lifecycle = PublishSubject.create();
TestObserver<String> testObserver = stream
.compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
.test();
// We get an error from the function for this lifecycle event
lifecycle.onNext("ick");
stream.onNext("1");
testObserver.assertNoValues();
// We only want to check for our IllegalArgumentException, but may have
// to wade through a CompositeException to get at it.
testObserver.assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable throwable) throws Exception {
if (throwable instanceof CompositeException) {
CompositeException ce = (CompositeException) throwable;
for (Throwable t : ce.getExceptions()) {
if (t instanceof IllegalArgumentException) {
return true;
}
}
}
return false;
}
});
}
示例12: main
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Observer<Long> observer=new Observer<Long>() {
@Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("It's Done");
}
@Override
public void onError(Throwable throwable) {
// TODO Auto-generated method stub
throwable.printStackTrace();
}
@Override
public void onNext(Long value) {
// TODO Auto-generated method stub
System.out.println(":"+value);
}
@Override
public void onSubscribe(Disposable disposable) {
// TODO Auto-generated method stub
System.out.println("onSubscribe");
}
};
PublishSubject< Long> publishSubject=PublishSubject.create();
publishSubject.onNext(1L);
publishSubject.onNext(2l);
publishSubject.subscribe(observer);
publishSubject.onNext(10l);
publishSubject.onNext(20l);
publishSubject.onComplete();
}
示例13: test_PublishSubject
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void test_PublishSubject() {
PublishSubject<Long> publishSubject = PublishSubject.create();
publishSubject.onNext(1L);
publishSubject.onNext(2l);
Assert.assertFalse(publishSubject.hasObservers());
TestObserver<Long> testObserver = publishSubject.test(true);
Assert.assertFalse(publishSubject.hasObservers());
}
示例14: demo4
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
private void demo4() {
PublishSubject<Integer> observable = PublishSubject.create();
observable.toFlowable(BackpressureStrategy.MISSING)
.buffer(10)
.observeOn(Schedulers.computation())
.subscribe(v -> log("s", v.toString()), this::log);
for (int i = 0; i < 1000000; i++) {
observable.onNext(i);
}
}
示例15: onCall_observablePublishesEvent_shouldExecuteSubscriberCall
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void onCall_observablePublishesEvent_shouldExecuteSubscriberCall() throws Exception {
// given
PublishSubject<String> subject = PublishSubject.create();
TestPresenter presenter = new TestPresenter();
presenter.on(subject).call(subscriber);
// when
subject.onNext("foo");
// then
verify(subscriber).accept("foo");
verifyNoMoreInteractions(subscriber);
}