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


Java BehaviorSubject.onNext方法代码示例

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


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

示例1: behaviourSubject

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
public static void behaviourSubject() {
    BehaviorSubject<Integer> subject = BehaviorSubject.create();
    subject.onNext(5);

    Action1<Integer> action1 = integer -> Log.i("From action1", String.valueOf(integer));
    Subscription subscription1 = subject.subscribe(action1);
    subject.onNext(10);

    Action1<Integer> action2 = integer -> Log.i("From action2", String.valueOf(integer));
    Subscription subscription2 = subject.subscribe(action2);
    subject.onNext(20);

    subscription1.unsubscribe();
    subject.onNext(40);

    subscription2.unsubscribe();
    subject.onNext(80);
}
 
开发者ID:ArturVasilov,项目名称:RxSamplesPractice,代码行数:19,代码来源:Samples.java

示例2: shouldEmitErrorAfterViewIsAttached

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void shouldEmitErrorAfterViewIsAttached() {
    TestScheduler testScheduler = Schedulers.test();
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewReplayTransformer<Object> transformer = new WaitViewReplayTransformer<>(
            view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
    TestSubscriber<Object> testSubscriber = new TestSubscriber<>();
    Observable.error(new RuntimeException())
            .compose(transformer)
            .subscribe(testSubscriber);
    testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertError(RuntimeException.class);
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:16,代码来源:WaitViewReplayTransformerTest.java

示例3: shouldEmitValueAfterViewIsAttached

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void shouldEmitValueAfterViewIsAttached() {
    TestScheduler testScheduler = Schedulers.test();
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewLatestTransformer<Integer> transformer =
            new WaitViewLatestTransformer<>(view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(0)
            .compose(transformer)
            .subscribe(testSubscriber);
    testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertValue(0);
    testSubscriber.assertCompleted();
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:17,代码来源:WaitViewLatestTransformerTest.java

示例4: testExceptionSubjectAction

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
public void testExceptionSubjectAction() {
    // test the behavior of surfacing exceptions from a subject


    BehaviorSubject<Integer> subject = BehaviorSubject.create();

    final List<Notification<Integer>> notifications = new ArrayList<Notification<Integer>>(4);

    Subscription s = subject.subscribe(new Action1<Integer>() {
        @Override
        public void call(Integer t) {
            notifications.add(Notification.createOnNext(t));
            throw new RuntimeException("call " + t);
        }
    });

    try {
        subject.onNext(0);
        // (unreachable) expect an exception to be thrown
        fail();
    } catch (RuntimeException e) {
        assertEquals("call 0", e.getMessage());
    }
}
 
开发者ID:nextopio,项目名称:nextop-client,代码行数:25,代码来源:RxExceptionTest.java

示例5: getUpdates

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
private BehaviorSubject<ParseChange<P>> getUpdates(I unit) {
    final FileObject resource = unit.source();
    final FileName name = resource.getName();

    // THREADING: it is possible that two different threads asking for a subject may do the parsing twice here, as
    // this is not an atomic operation. However, the chance is very low and it does not break anything (only
    // duplicates some work), so it is acceptable.
    BehaviorSubject<ParseChange<P>> updates = updatesPerResource.get(name);
    if(updates == null) {
        updates = BehaviorSubject.create();
        updatesPerResource.put(name, updates);
        try {
            logger.trace("Parsing for {}", resource);
            final P result = syntaxService.parse(unit);
            updates.onNext(ParseChange.update(result));
        } catch(ParseException e) {
            final String message = String.format("Parsing for %s failed", name);
            logger.error(message, e);
            updates.onNext(ParseChange.<P>error(e));
        }
    }
    return updates;
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:24,代码来源:ParseResultProcessor.java

示例6: testPagingCapabilities

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void testPagingCapabilities() {
    PublishSubject<Object> view = PublishSubject.create();
    BehaviorSubject<Integer> nextPageRequests = BehaviorSubject.create();
    final TestObserver<Delivery<Object, String>> testObserver = new TestObserver<>();

    nextPageRequests
        .concatMap(new Func1<Integer, Observable<Integer>>() {
            @Override
            public Observable<Integer> call(Integer targetPage) {
                return targetPage <= requestedPageCount ?
                    Observable.<Integer>never() :
                    Observable.range(requestedPageCount, targetPage - requestedPageCount);
            }
        })
        .doOnNext(new Action1<Integer>() {
            @Override
            public void call(Integer it) {
                requestedPageCount = it + 1;
            }
        })
        .startWith(Observable.range(0, requestedPageCount))
        .concatMap(new Func1<Integer, Observable<String>>() {
            @Override
            public Observable<String> call(final Integer page) {
                return requestPage(page, PAGE_SIZE);
            }
        })
        .compose(new DeliverReplay<Object, String>(view))
        .subscribe(testObserver);

    ArrayList<Delivery<Object, String>> onNext = new ArrayList<>();

    testObserver.assertReceivedOnNext(onNext);

    view.onNext(999);
    addOnNext(onNext, 999, 0, 1, 2);

    testObserver.assertReceivedOnNext(onNext);

    nextPageRequests.onNext(2);
    addOnNext(onNext, 999, 3, 4, 5);

    testObserver.assertReceivedOnNext(onNext);

    view.onNext(null);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);

    nextPageRequests.onNext(3);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);

    view.onNext(9999);
    addOnNext(onNext, 9999, 0, 1, 2, 3, 4, 5, 6, 7, 8);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:62,代码来源:DeliverReplayTest.java

示例7: findAll

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
protected  Observable<ParseObject<T>> findAll(ParseQuery.Builder<DefaultParseColumn> queryBuilder) {
    ParseRestApi api = ParseRestClientFactory.masterClient();

    BehaviorSubject<Date> relay = BehaviorSubject.create();
    relay.onNext(new Date());
    return relay.flatMap(date -> {
        ParseQuery<DefaultParseColumn> queryOlders = queryBuilder.olderThan(DefaultParseColumn.createdAt, date).build();
        Observable<Response<QueryResults>> response = api.query(className, queryOlders.params);
        return response;
    }).flatMap((r) -> flatMapResponse(r, relay));

}
 
开发者ID:jmfayard,项目名称:restinparse,代码行数:13,代码来源:ParseTableInternal.java

示例8: flatMapResponse

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
protected Observable<ParseObject<T>> flatMapResponse(Response<QueryResults> r, @Nullable BehaviorSubject<Date> relay) {
    if (!r.isSuccessful()) {
        if (relay!= null) { relay.onCompleted();}
        throw errorFrom(r);
    }
    List<ParseObject<T>> objects = new ArrayList<>();
    List<ParseMap> found = r.body().results;
    if (found == null) {
        found = Collections.emptyList();
    }
    for (ParseMap parseMap : found) {
        ParseObject<T> o = new ParseObject<T>(parseMap);
        objects.add(o);
    }
    if (relay != null) {
        if (found.size() == QUERY_ALL_LIMIT) {
            ParseObject<DefaultParseColumn> object = new ParseObject<>(found.get(QUERY_ALL_LIMIT - 1));
            Date createdAt = object.createdAt();
            relay.onNext(createdAt);
        } else {
            relay.onCompleted();
        }
    }
    return Observable.from(objects);
}
 
开发者ID:jmfayard,项目名称:restinparse,代码行数:26,代码来源:ParseTableInternal.java

示例9: behaviourSubject

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
void behaviourSubject(){
    Action1<Integer> onNextFuc= new Action1<Integer>() {
        @Override
        public void call(Integer integer) {
            Log.i(TAG, "New Event received on behaviourSubject: " + integer);
        }
    };
    BehaviorSubject<Integer> behaviorSubject = BehaviorSubject.create();
    behaviorSubject.onNext(1);
    behaviorSubject.onNext(2);
    Subscription subscription = behaviorSubject.doOnSubscribe(new Action0() {
        @Override
        public void call() {
            Log.i(TAG, "Observer subscribed to behaviorSubject");
        }
    }).doOnUnsubscribe(new Action0() {
        @Override
        public void call() {
            Log.i(TAG, "Observer subscribed to behaviorSubject");
        }
    }).subscribe(onNextFuc);
    behaviorSubject.onNext(3);
    behaviorSubject.onNext(4);
    subscription.unsubscribe();
    behaviorSubject.onNext(5);
    behaviorSubject.onCompleted();
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:28,代码来源:SubjectActivity.java

示例10: shouldSucceedHasValuesAndClear

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void shouldSucceedHasValuesAndClear() throws Exception {
    BehaviorSubject<String> subject = BehaviorSubject.create("first item");
    RxTestWrapper<String> assertion = assertThat(subject)
          .hasValuesAndClear("first item");
    subject.onNext("second value");
    assertion.hasValueCount(1);
}
 
开发者ID:MyDogTom,项目名称:RxTestWrapper,代码行数:9,代码来源:RxTestWrapperTest.java

示例11: addToPlaylist

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Override
public void addToPlaylist(Playlist playlist, Song song) {
    MediaStoreUtil.appendToPlaylist(mContext, playlist, song);

    if (mPlaylistContents.containsKey(playlist)) {
        BehaviorSubject<List<Song>> observableContents = mPlaylistContents.get(playlist);
        List<Song> updatedContents = new ArrayList<>(observableContents.getValue());
        updatedContents.add(song);
        observableContents.onNext(updatedContents);
    }
}
 
开发者ID:marverenic,项目名称:Jockey,代码行数:12,代码来源:LocalPlaylistStore.java

示例12: EurekaServiceImpl

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
/**
 * Register the application with Eureka2
 * TODO: Remove this logic from the constructor
 */
public EurekaServiceImpl() {
    writeServerHostname = DynamicPropertyFactory.getInstance().getStringProperty("triathlon.writeServerHostname", "localhost").get();
    writeServerRegistrationPort = DynamicPropertyFactory.getInstance().getIntProperty("triathlon.writeServerRegistrationPort", 12102).get();
    writeServerInterestPort = DynamicPropertyFactory.getInstance().getIntProperty("triathlon.writeServerInterestPort", 12103).get();
    readServerVip = DynamicPropertyFactory.getInstance().getStringProperty("triathlon.readServerVip", "eureka-read-cluster").get();

    registrationClient = Eurekas.newRegistrationClientBuilder()
            .withServerResolver(fromHostname(writeServerHostname).withPort(writeServerRegistrationPort))
            .build();

    BehaviorSubject<InstanceInfo> infoSubject = BehaviorSubject.create();
    subscription = registrationClient.register(infoSubject).subscribe();

    LOGGER.info("Registering application");
    infoSubject.onNext(TRIATHLON);

    ServerResolver interestClientResolver =
            fromEureka(
                    fromHostname(writeServerHostname).withPort(writeServerInterestPort)
            ).forInterest(forVips(readServerVip));

    interestClient = Eurekas.newInterestClientBuilder()
            .withServerResolver(interestClientResolver)
            .build();
}
 
开发者ID:schibsted,项目名称:triathlon,代码行数:30,代码来源:EurekaServiceImpl.java

示例13: shouldEmitValueWhenViewIsAttached

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void shouldEmitValueWhenViewIsAttached() {
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewReplayTransformer<Integer> transformer = new WaitViewReplayTransformer<>(view);
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(0)
            .compose(transformer)
            .subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertValue(0);
    testSubscriber.assertCompleted();
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:14,代码来源:WaitViewReplayTransformerTest.java

示例14: shouldEmitValueAfterViewIsAttached

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void shouldEmitValueAfterViewIsAttached() {
    TestScheduler testScheduler = Schedulers.test();
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewReplayTransformer<Integer> transformer =
            new WaitViewReplayTransformer<>(view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(0)
            .compose(transformer)
            .subscribe(testSubscriber);
    testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertValue(0);
    testSubscriber.assertCompleted();
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:17,代码来源:WaitViewReplayTransformerTest.java

示例15: shouldReplayAllValuesAfterViewIsAttached

import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void shouldReplayAllValuesAfterViewIsAttached() {
    TestScheduler testScheduler = Schedulers.test();
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewReplayTransformer<Integer> transformer =
            new WaitViewReplayTransformer<>(view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(0, 1, 2)
            .compose(transformer)
            .subscribe(testSubscriber);
    testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertValues(0, 1, 2);
    testSubscriber.assertCompleted();
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:17,代码来源:WaitViewReplayTransformerTest.java


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