当前位置: 首页>>代码示例>>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;未经允许,请勿转载。