本文整理匯總了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();
}
示例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());
}
示例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);
}
示例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
}
});
}
示例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();
}
示例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);
}
}
示例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));
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}