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


Java ReplaySubject.onNext方法代碼示例

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


在下文中一共展示了ReplaySubject.onNext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

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

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

示例5: createAccount

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public Observable<Account> createAccount(final Activity callingActivity, final User me, final String user, final String password)
{
    ReplaySubject<Account> subject = ReplaySubject.create();

    // Create the account if necessary
    Account account = new Account(user, accountType);
    final Bundle extraData = new Bundle();
    extraData.putString(USER_DATA, gson.toJson(me));
    boolean accountCreated = accountManager.addAccountExplicitly(account, password, extraData);
    if(accountCreated) {
        FetLife.getBus().post(new AccountCreatedEvent(account));
    }else{
        // If we didn't create the account, at least make sure to update it
        accountManager.setPassword(account, password);
    }

    subject.onNext(account);
    setCurrentAccount(account);

    if(callingActivity != null)
    {
        // Check whether we were launched explicitly to create the account
        Bundle extras = callingActivity.getIntent().getExtras();
        if(extras != null && accountCreated)
        {
            AccountAuthenticatorResponse response = extras.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
            if(response != null)
            {
                // Let them know we succeeded if so...
                Bundle result = new Bundle();
                result.putString(AccountManager.KEY_ACCOUNT_NAME, user);
                result.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
                response.onResult(result);
            }
        }
    }

    return subject.asObservable();
}
 
開發者ID:xcjs,項目名稱:fetlife-oss,代碼行數:40,代碼來源:FetLifeAccountManager.java

示例6: fetch

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
private void fetch(String tag, ReplaySubject<Feed> feedSubject, ReplaySubject<RemoteStatus> statusSubject, CacheMode mode) {
    statusSubject.onNext(RemoteStatus.LOADING);
    Action1<Feed> action = (x) -> {
        statusSubject.onNext(RemoteStatus.NOT_LOADING);
        feedSubject.onNext(x);
    };
    if (tag == null) {
        rest.defaultFeed(mode).subscribe(action);
    } else {
        rest.search(mode, tag).subscribe(action);
    }
}
 
開發者ID:mmastrac,項目名稱:progscrape-android,代碼行數:13,代碼來源:Model.java

示例7: testAlreadyUnsubscribedInterleavesWithClient

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Test
public void testAlreadyUnsubscribedInterleavesWithClient() {
    ReplaySubject<Integer> source = ReplaySubject.create();

    Subscriber<Integer> done = Subscribers.empty();
    done.unsubscribe();

    @SuppressWarnings("unchecked")
    Observer<Integer> o = mock(Observer.class);
    InOrder inOrder = inOrder(o);

    Observable<Integer> result = source.publish().refCount();

    result.subscribe(o);

    source.onNext(1);

    result.subscribe(done);

    source.onNext(2);
    source.onComplete();

    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(2);
    inOrder.verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
 
開發者ID:akarnokd,項目名稱:RxJavaFlow,代碼行數:28,代碼來源:OnSubscribeRefCountTest.java

示例8: testReplaySubject

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public void testReplaySubject() {
    ReplaySubject<Integer> replaySubject = ReplaySubject.create();
    replaySubject.subscribe(new SubAction("Early: "));
    replaySubject.onNext(0);
    replaySubject.onNext(1);
    replaySubject.subscribe(new SubAction("Later: "));
    replaySubject.onNext(2);
}
 
開發者ID:yeungeek,項目名稱:Android-Gradle-Samples,代碼行數:9,代碼來源:SubjectTest.java

示例9: testReplaySubjectLimit

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public void testReplaySubjectLimit() throws Exception {
    ReplaySubject<Integer> replaySubject =/* ReplaySubject.createWithSize(2);*/
            ReplaySubject.createWithTime(150, TimeUnit.MICROSECONDS, Schedulers.immediate());
    replaySubject.onNext(0);
    Thread.sleep(100);
    replaySubject.onNext(1);
    Thread.sleep(100);
    replaySubject.onNext(2);
    replaySubject.subscribe(new SubAction("Later: "));
    replaySubject.onNext(3);
}
 
開發者ID:yeungeek,項目名稱:Android-Gradle-Samples,代碼行數:12,代碼來源:SubjectTest.java

示例10: ermittleDeinenZug

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Override
public Observable<Zug> ermittleDeinenZug() {

    ReplaySubject<Zug> subject = ReplaySubject.create();
    if (zug != null) {
        subject.onNext(zug);
    }
    subject.onCompleted();

    return subject;
}
 
開發者ID:DokChess,項目名稱:dokchess,代碼行數:12,代碼來源:MockEngine.java

示例11: allowOnlyLocalhost

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public static IngressPolicy allowOnlyLocalhost(){
	ReplaySubject<Set<String>> subject = ReplaySubject.create();
	Set<String> list = new HashSet<String>();
	list.add("127.0.0.1");
	subject.onNext(list);
	return new InetAddressWhiteListIngressPolicy(subject);
}
 
開發者ID:allenxwang,項目名稱:RxNetty,代碼行數:8,代碼來源:IngressPolicies.java

示例12: toObservableListOfOne

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
private static <T> Observable<List<Observable<T>>> toObservableListOfOne(Observable<T> observable){
	List<Observable<T>> list = new ArrayList<Observable<T>>(1);
	list.add(observable);
	ReplaySubject<List<Observable<T>>> subject = ReplaySubject.create(1);
	subject.onNext(list);
	return subject;
}
 
開發者ID:allenxwang,項目名稱:RxNetty,代碼行數:8,代碼來源:RemoteObservable.java

示例13: emitsSuccessfulResultFor

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public void emitsSuccessfulResultFor(Class<T> itemClass, T item) {
    ReplaySubject<Result<T>> subject = getOrCreateSubjectFor(itemClass);
    subject.onNext(Result.response(Response.success(item)));
    subject.onCompleted();
}
 
開發者ID:savvasdalkitsis,項目名稱:Mondo,代碼行數:6,代碼來源:FakeObservableCache.java

示例14: emitSuccessfulOAuthFor

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public void emitSuccessfulOAuthFor(String clientId, String clientSecret, String code,
                                   String grantType, String redirectUri, ApiOAuthToken apiOAuthToken) {
    ReplaySubject<Result<ApiOAuthToken>> subject = oAuthSubjects.get(keyFor(clientId, clientSecret, code, grantType, redirectUri));
    subject.onNext(Result.response(Response.success(apiOAuthToken)));
    subject.onCompleted();
}
 
開發者ID:savvasdalkitsis,項目名稱:Mondo,代碼行數:7,代碼來源:FakeMondoApi.java

示例15: turnOn

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Override
@RequiresPermission(allOf = {
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN,
})
public Observable<Void> turnOn() {
    if (adapter == null) {
        return Observable.error(new ChangePowerStateException());
    }

    final ReplaySubject<Void> turnOnMirror = ReplaySubject.createWithSize(1);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE,
                                                    BluetoothAdapter.ERROR);
            final int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                                    BluetoothAdapter.ERROR);
            if (oldState == BluetoothAdapter.STATE_OFF &&
                    newState == BluetoothAdapter.STATE_TURNING_ON) {
                logger.info(LOG_TAG, "Bluetooth turning on");
            } else if (oldState == BluetoothAdapter.STATE_TURNING_ON &&
                    newState == BluetoothAdapter.STATE_ON) {
                logger.info(LOG_TAG, "Bluetooth turned on");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onNext(null);
                turnOnMirror.onCompleted();
            } else {
                logger.info(LOG_TAG, "Bluetooth failed to turn on");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onError(new ChangePowerStateException());
            }
        }
    };
    applicationContext.registerReceiver(receiver,
                                        new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
    if (!adapter.enable()) {
        applicationContext.unregisterReceiver(receiver);
        return Observable.error(new ChangePowerStateException());
    }

    return turnOnMirror;
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:48,代碼來源:NativeBluetoothStack.java


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