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


Java ReplaySubject.create方法代码示例

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


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

示例1: forceFallbackCommand

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
protected HystrixObservable<Response> forceFallbackCommand(Invocation invocation) {
  return new HystrixObservable<Response>() {
    @Override
    public Observable<Response> observe() {
      ReplaySubject<Response> subject = ReplaySubject.create();
      final Subscription sourceSubscription = toObservable().subscribe(subject);
      return subject.doOnUnsubscribe(sourceSubscription::unsubscribe);
    }

    @Override
    public Observable<Response> toObservable() {
      return Observable.create(f -> {
        try {
          f.onNext(FallbackPolicyManager.getFallbackResponse(handler.groupname, invocation));
        } catch (Exception e) {
          f.onError(e);
        }
      });
    }
  };
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:BizkeeperHandlerDelegate.java

示例2: replaySubject

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

示例3: getAdIdEnabledObservable

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
public Observable<Boolean> getAdIdEnabledObservable() {
    // Observable that emits Google Tracking Enabled
    if (adIdEnabledSubscription == null || adIdEnabledSubscription.isUnsubscribed()) {
        adIdEnabledSubject = ReplaySubject.create();

        adIdEnabledSubscription = Observable
                .concat(getAdIdEnabledFromMemoryObservable(),
                        getAdIdEnabledFromGoogleObservable())
                .first(entity -> entity != null)
                // lets retry if something goes wrong!
                .retry(2)
                .subscribe(adIdEnabledSubject);
    }

    return adIdEnabledSubject.asObservable();
}
 
开发者ID:mirhoseini,项目名称:fyber_mobile_offers,代码行数:18,代码来源:AppGoogleAds.java

示例4: testObserveAuth

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Test
public void testObserveAuth() throws Exception {
    Observable<Boolean> isAuthenticated =
            observeAuth(firebaseAuth)
            .map(new Func1<FirebaseUser, Boolean>() {
                @Override
                public Boolean call(FirebaseUser user) {
                    return user != null;
                }
            });

    ReplaySubject<Boolean> userState = ReplaySubject.create();
    isAuthenticated.subscribe(userState);

    await(authAnonymously(firebaseAuth));
    firebaseAuth.signOut();

    List<Boolean> observedState = await(userState.take(3).toList());
    assertThat(observedState, contains(false, true, false));
}
 
开发者ID:DariusL,项目名称:RxRoboBase,代码行数:21,代码来源:AuthenticationTest.java

示例5: loadCharacter

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
public Observable<CharactersResponse> loadCharacter(String query,
                                                    String privateKey,
                                                    String publicKey,
                                                    long timestamp) {
    if (characterSubscription == null || characterSubscription.isUnsubscribed()) {
        characterSubject = ReplaySubject.create();

        // generate hash using timestamp and API keys
        String hash = HashGenerator.generate(timestamp, privateKey, publicKey);

        characterSubscription = api.getCharacters(query, publicKey, hash, timestamp)
                .subscribeOn(scheduler.backgroundThread())
                .subscribe(characterSubject);
    }

    return characterSubject.asObservable();
}
 
开发者ID:mirhoseini,项目名称:marvel,代码行数:19,代码来源:SearchInteractorImpl.java

示例6: getAdIdObservable

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
public Observable<String> getAdIdObservable() {
    // Observable that emits Google Advertising adIdSubscription
    if (adIdSubscription == null || adIdSubscription.isUnsubscribed()) {
        adIdSubject = ReplaySubject.create();

        adIdSubscription = Observable
                .concat(getAdIdFromMemoryObservable(),
                        getAdIdFromGoogleObservable())
                .first(entity -> entity != null)
                // lets retry if something goes wrong!
                .retry(2)
                .subscribe(adIdSubject);
    }

    return adIdSubject.asObservable();
}
 
开发者ID:mirhoseini,项目名称:fyber_mobile_offers,代码行数:18,代码来源:AppGoogleAds.java

示例7: toObservable

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
/**
 * Creates an Observable stream from this queue. There should only ever be one subscriber to
 * this method. Calling this method twice will complete any previously opened observable
 * (leaving unprocessed elements in the queue).
 * @return An observable containing the contents of the queue in order
 */
public Observable<T> toObservable() {
    synchronized (mLock) {
        if (mSubject != null) {
            mSubject.onCompleted();
        }

        if (mQueue.isEmpty()) {
            mSubject = ReplaySubject.create();
        } else {
            mSubject = ReplaySubject.create(mQueue.size());

            for (T data : mQueue) {
                mSubject.onNext(data);
            }
        }
    }

    return mSubject.map(item -> {
        mQueue.remove();
        return item;
    }).asObservable();
}
 
开发者ID:marverenic,项目名称:Jockey,代码行数:29,代码来源:ObservableQueue.java

示例8: replaySubject

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
public static void replaySubject() {
    ReplaySubject<Integer> subject = ReplaySubject.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

示例9: call

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
public Observable<T> call(final Observable<T> observable) {
    final ReplaySubject<Notification<T>>
            subject = ReplaySubject.create();
    final Subscription subscription = observable.materialize().subscribe(subject);
    return view
            .switchMap(new Func1<Boolean, Observable<Notification<T>>>() {
                @Override
                public Observable<Notification<T>> call(final Boolean flag) {
                    if (flag) {
                        return subject;
                    } else {
                        return Observable.empty();
                    }
                }
            })
            .doOnUnsubscribe(new Action0() {
                @Override
                public void call() {
                    subscription.unsubscribe();
                }
            })
            .dematerialize();
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:25,代码来源:WaitViewReplayTransformer.java

示例10: zugSuchen

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
public final void zugSuchen(Stellung stellung, Observer<Zug> subject) {
    Collection<Zug> zuege = spielregeln.liefereGueltigeZuege(stellung);
    if (zuege.size() > 0) {
        ReplaySubject<BewerteterZug> suchErgebnisse = ReplaySubject.create();
        aktuelleSuchErgebnisse = suchErgebnisse;

        ErgebnisMelden melder = new ErgebnisMelden(subject, zuege.size());
        suchErgebnisse.subscribe(melder);

        for (Zug zug : zuege) {
            EinzelnenZugUntersuchen zugUntersuchen = new EinzelnenZugUntersuchen(stellung, zug, suchErgebnisse);
            suchErgebnisse.subscribe(zugUntersuchen);
            executorService.execute(zugUntersuchen);
        }
    } else {
        subject.onCompleted();
    }
}
 
开发者ID:DokChess,项目名称:dokchess,代码行数:20,代码来源:MinimaxParalleleSuche.java

示例11: getCityNames

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
private Observable<List<String>> getCityNames() {
    if (cityNames == null) {
        cityNames = ReplaySubject.create(1);

        geoNamesClient.getCities()
                .flatMap(cities -> Observable.from(cities.geonames))
                .map(city -> {
                    String format = String.format("%s,%s", city.name, city.countrycode);
                    return format;
                })
                .toList()
                .subscribe(cityNames);
    }
    Log.d(TAG, "Returning city names");
    return cityNames.asObservable();
}
 
开发者ID:rosshambrick,项目名称:rain-or-shine,代码行数:17,代码来源:CoordinatedWeatherManager.java

示例12: testServeListObservables

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Test
public void testServeListObservables(){
	// setup
	Observable<Integer> os1 = Observable.range(0, 101);
	Observable<Integer> os2 = Observable.range(100, 101);
	List<Observable<Integer>> toServe = new LinkedList<Observable<Integer>>();
	toServe.add(os1);
	toServe.add(os2);
	ReplaySubject <List<Observable<Integer>>> subject = ReplaySubject.create();
	subject.onNext(toServe);
	// serve
	PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000);
	int serverPort = portSelector.acquirePort();
	RemoteObservable.serveMany(serverPort, subject, Codecs.integer());
	// connect
	Observable<Integer> oc = RemoteObservable.connect("localhost", serverPort, Codecs.integer());
	// assert
	Observable.sumInteger(oc).toBlockingObservable().forEach(new Action1<Integer>(){
		@Override
		public void call(Integer t1) {
			Assert.assertEquals(20200, t1.intValue()); // sum of number 0-200
		}
	});
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:25,代码来源:RemoteObservableTest.java

示例13: saveBitmap

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
public ReplaySubject<String> saveBitmap(final Bitmap bitmap, final File folder, final String name) {
    bitmapSubject = ReplaySubject.create();
    try {
        String path = FileUtil.savePhoto(bitmap, folder, name);
        onSuccess(path);
    } catch (IOException e) {
        e.printStackTrace();
        onFail(e);
    }
    return bitmapSubject;
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:12,代码来源:RxFile.java

示例14: initObservable

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
    protected final void initObservable() {
        subject = ReplaySubject.create();
        subject.onBackpressureBuffer()
                .observeOn(EventThread.getScheduler(observeThread))
                .subscribeOn(EventThread.getScheduler(subscribeThread))
//                .subscribe(new Observer<Object>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//
//                    }
//
//                    @Override
//                    public void onNext(Object event) {
//                        try {
//                            if (valid) {
//                                handleEvent(event);
//                            }
//                        } catch (InvocationTargetException e) {
//                            throwRuntimeException("Could not dispatch event: " + event.getClass() + " to subscriber " + SubscriberReplayEvent.this, e);
//                        }
//                    }
//                });
                .subscribe(event -> {
                    try {
                        if (valid) {
                            handleEvent(event);
                        }
                    } catch (InvocationTargetException e) {
                        throwRuntimeException("Could not dispatch event: " + event.getClass() + " to subscriber " + SubscriberReplayEvent.this, e);
                    }
                });
    }
 
开发者ID:analizer1,项目名称:RxBusLib,代码行数:39,代码来源:SubscriberReplayEvent.java

示例15: login

import rx.subjects.ReplaySubject; //导入方法依赖的package包/类
@Override
public Observable<Response<LoginResponse>> login(String email, String password) {
    if (loginSubscription == null || loginSubscription.isUnsubscribed()) {
        loginSubject = ReplaySubject.create();

        loginSubscription = api.login(email, password)
                .subscribeOn(scheduler.backgroundThread())
                .subscribe(loginSubject);
    }

    return loginSubject.asObservable();
}
 
开发者ID:mirhoseini,项目名称:bcg,代码行数:13,代码来源:UserInteractorImpl.java


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