當前位置: 首頁>>代碼示例>>Java>>正文


Java ReplaySubject類代碼示例

本文整理匯總了Java中rx.subjects.ReplaySubject的典型用法代碼示例。如果您正苦於以下問題:Java ReplaySubject類的具體用法?Java ReplaySubject怎麽用?Java ReplaySubject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ReplaySubject類屬於rx.subjects包,在下文中一共展示了ReplaySubject類的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: observe

import rx.subjects.ReplaySubject; //導入依賴的package包/類
@Test
public void observe() throws Exception {
    ReplaySubject<Cursor> collector = ReplaySubject.create();
    Subscription subscription = mSimplDb.get().observe(TableTest.class).subscribe(collector);
    mInsert.contentValues.put(DATA, "Data");
    mSimplDb.get().insert(mInsert).toBlocking().single();
    mInsert.contentValues.put(DATA, "data");
    mSimplDb.get().insert(mInsert).toBlocking().single();
    collector.onCompleted();
    subscription.unsubscribe();

    Cursor cursor = collector.toList().toBlocking().single().get(collector.size() - 1);
    assertEquals(2, cursor.getCount());
    cursor.moveToFirst();
    assertData("Data", cursor);
    cursor.moveToLast();
    assertData("data", cursor);
}
 
開發者ID:tynn,項目名稱:simplDb,代碼行數:19,代碼來源:SimplDbRxTest.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: 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

示例8: operatorUnbufferedObserveOn

import rx.subjects.ReplaySubject; //導入依賴的package包/類
@Test
public void operatorUnbufferedObserveOn() throws Exception {
    ReplaySubject<Integer> numbers = ReplaySubject.createWithSize(1);

    final AtomicInteger counter = new AtomicInteger();
    numbers.lift(new Rx.OperatorUnbufferedObserveOn<Integer>(Schedulers.immediate()))
            .subscribe(new Action1<Integer>() {
                @Override
                public void call(Integer number) {
                    counter.addAndGet(number);
                }
            });

    numbers.onNext(3);
    numbers.onNext(3);
    numbers.onNext(3);

    assertEquals(9, counter.get());
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:20,代碼來源:RxTests.java

示例9: 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

示例10: 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

示例11: 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

示例12: build

import rx.subjects.ReplaySubject; //導入依賴的package包/類
/**
 * Builds and validates the structure of the expected header then
 * returns an {@link Observable} that can be used to submit info to the
 * {@link Network}
 * @return  a new Publisher
 */
public Publisher build() {
    subject = ReplaySubject.createWithSize(3);
    for(int i = 0;i < HEADER_SIZE;i++) {
        if(lines[i] == null) {
            throw new IllegalStateException("Header not properly formed (must contain 3 lines) see Header.java");
        }
        subject.onNext(lines[i]);
    }
    
    Publisher p = new Publisher();
    p.subject = subject;
    
    if(notifier != null) {
        notifier.accept(p);
    }
    
    return p;
}
 
開發者ID:numenta,項目名稱:htm.java,代碼行數:25,代碼來源:Publisher.java

示例13: 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

示例14: 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

示例15: 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


注:本文中的rx.subjects.ReplaySubject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。