本文整理汇总了Java中rx.subjects.BehaviorSubject.create方法的典型用法代码示例。如果您正苦于以下问题:Java BehaviorSubject.create方法的具体用法?Java BehaviorSubject.create怎么用?Java BehaviorSubject.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.subjects.BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.create方法的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);
}
示例2: getAutoPlaylistSongs
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
private Observable<List<Song>> getAutoPlaylistSongs(AutoPlaylist playlist) {
BehaviorSubject<List<Song>> subject;
if (mPlaylistContents.containsKey(playlist)) {
subject = mPlaylistContents.get(playlist);
} else {
subject = BehaviorSubject.create();
mPlaylistContents.put(playlist, subject);
playlist.generatePlaylist(mMusicStore, this, mPlayCountStore)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subject::onNext, subject::onError);
subject.observeOn(Schedulers.io())
.subscribe(contents -> {
MediaStoreUtil.editPlaylist(mContext, playlist, contents);
}, throwable -> {
Timber.e(throwable, "Failed to save playlist contents");
});
}
return subject.asObservable();
}
示例3: 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());
}
}
示例4: 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;
}
示例5: 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);
}
示例6: onStartLoading
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Override
protected void onStartLoading() {
Log.d(getClass().getSimpleName(), "onStartLoading");
super.onStartLoading();
if (subject == null) {
subject = BehaviorSubject.create();
}
subscription = subject.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onResult, this::onError);
if (subjectSubscription == null) {
subjectSubscription = searchQuerySubject.flatMap(this::create)
.subscribeOn(Schedulers.io()).subscribe(subject);
}
}
示例7: AnalyseAppLibraryPermission
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Inject @SuppressWarnings("checkstyle:parameternumber")
public AnalyseAppLibraryPermission(DecompileApp decompileApp,
AnalyseLibraryMethodInvocations analyseLibraryMethodInvocations,
AnalysePermissionsFromMethodInvocations analysePermissionsFromMethodInvocations,
LibraryService libraryService,
PermissionService permissionService,
StorageProvider storageProvider,
FileUtils fileUtils,
AppService appService) {
this.decompileApp = decompileApp;
this.analyseLibraryMethodInvocations = analyseLibraryMethodInvocations;
this.analysePermissionsFromMethodInvocations = analysePermissionsFromMethodInvocations;
this.libraryService = libraryService;
this.permissionService = permissionService;
this.storageProvider = storageProvider;
this.fileUtils = fileUtils;
this.appService = appService;
this.progressSubject = BehaviorSubject.create();
}
示例8: initObservable
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Override
protected final void initObservable() {
subject = BehaviorSubject.create();
subject.onBackpressureBuffer()
.observeOn(EventThread.getScheduler(observeThread))
.subscribeOn(EventThread.getScheduler(subscribeThread))
.subscribe(event -> {
try {
if (valid) {
handleEvent(event);
}
} catch (InvocationTargetException e) {
throwRuntimeException("Could not dispatch event: " + event.getClass() + " to subscriber " + SubscriberBehaviorEvent.this, e);
}
});
}
示例9: testObserveChildren
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Test
public void testObserveChildren() throws Exception {
BehaviorSubject<FirebaseChildEvent<DataSnapshot>> events = BehaviorSubject.create();
observeChildren(reference)
.subscribe(events);
await(setValue(reference.child("foo"), "bar"));
FirebaseChildEvent<DataSnapshot> add = events.getValue();
assertThat(add.eventType, is(FirebaseChildEvent.TYPE_ADD));
assertThat(add.value.getValue(String.class), is("bar"));
assertThat(add.value.getKey(), is("foo"));
await(setValue(reference.child("foo"), "baz"));
FirebaseChildEvent<DataSnapshot> edit = events.getValue();
assertThat(edit.eventType, is(FirebaseChildEvent.TYPE_CHANGE));
assertThat(edit.value.getValue(String.class), is("baz"));
await(setValue(reference.child("foo"), null));
FirebaseChildEvent<DataSnapshot> remove = events.getValue();
assertThat(remove.eventType, is(FirebaseChildEvent.TYPE_REMOVE));
}
示例10: submit
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
public Observable submit(UUID id, CarbonMessage cMsg, CarbonCallback cCallback) {
RxContext rxContext = new RxContext(id.toString(), cMsg, cCallback);
BehaviorSubject<RxContext> behaviorSubject = BehaviorSubject.create();
Future f = WORKER_EXECUTOR_SERVICE.submit(() -> {
try {
log.debug("Thread using carbon message with UUID " + id);
mediators.getFirstMediator().receive(cMsg, cCallback);
log.debug("mediator receive returned");
behaviorSubject.onNext(rxContext);
} catch (Exception e) {
log.error("Error while mediating", e);
//behaviorSubject.onNext(rxContext);
}
});
f.isDone();
return behaviorSubject;
}
示例11: 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));
}
示例12: ConstitutionServiceImpl
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
@Inject
ConstitutionServiceImpl(final Gson gson,
@ConstitutionPref final StringPreference cachedConstitution) {
// initialize constitution from a cached value
final String json = cachedConstitution.get();
LOGD(TAG, json);
UsConstitution cached = gson.fromJson(json, UsConstitution.class);
constitutionSubject = BehaviorSubject.create(cached);
constitutionSubject.skip(1)
.subscribe(new Action1<Constitution>() {
@Override
public void call(Constitution constitution) {
//save all subsequent updates to the constitution
final String newConstitution = gson.toJson(constitution);
cachedConstitution.set(newConstitution);
}
});
}
示例13: TestDataStore
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
public TestDataStore() {
this.data = new TestData();
this.nonNullName = BehaviorSubject.create();
this.name = BehaviorSubject.create();
this.passName = BehaviorSubject.create();
this.defaultName = BehaviorSubject.create(this.data.getDefaultName());
this.messages = BehaviorSubject.create();
this.map = BehaviorSubject.create(this.data.getMap());
this.i = BehaviorSubject.create();
this.l = BehaviorSubject.create();
this.f = BehaviorSubject.create();
this.d = BehaviorSubject.create();
this.b = BehaviorSubject.create();
this.s = BehaviorSubject.create();
this.bb = BehaviorSubject.create();
this.c = BehaviorSubject.create();
this.ia = BehaviorSubject.create();
this.la = BehaviorSubject.create();
this.fa = BehaviorSubject.create();
}
示例14: ComposeMonitor
import rx.subjects.BehaviorSubject; //导入方法依赖的package包/类
public ComposeMonitor(DockerService dockerService, String fileName) {
this.monitor = BehaviorSubject.create();
this.dockerService = dockerService;
this.fileName = fileName;
this.observer = Observers.create(t -> {
List<String> containerIds = getContainerIds();
containerIds.forEach(s -> {
ContainerDetails details = dockerService.getContainer(s);
log.debug("get container {}", details);
if (checkContainer(details)) {
log.error("Container crashed {}", details);
monitor.onNext(ResultCode.ERROR);
monitor.onCompleted();
return;
}
});
});
}
示例15: 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);
}