本文整理匯總了Java中rx.subjects.ReplaySubject.createWithSize方法的典型用法代碼示例。如果您正苦於以下問題:Java ReplaySubject.createWithSize方法的具體用法?Java ReplaySubject.createWithSize怎麽用?Java ReplaySubject.createWithSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.subjects.ReplaySubject
的用法示例。
在下文中一共展示了ReplaySubject.createWithSize方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例2: 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;
}
示例3: write
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public Observable<Net.HttpResponse> write (ByteString data) {
Buffer buffer = Buffer.buffer (data.toByteArray ());
ReplaySubject<Net.HttpResponse> subject = ReplaySubject.createWithSize(1);
request.handler (response -> {
if (!okStatuses.contains (response.statusCode ())) {
throw new IllegalStateException (format("Unexpected statusCode %s and message %S",
response.statusCode (), response.statusMessage ()));
}
response.bodyHandler (body -> {
subject.onNext (
new Net.HttpResponse () {
@Override
public BytesEvent data () {
return Codecs.BYTES.from (body.getBytes ());
}
@Override
public int status () {
return response.statusCode ();
}
});
subject.onCompleted ();
});
})
.exceptionHandler ( ex -> subject.onError (ex))
.putHeader ("Content-Length", String.valueOf (buffer.length ()))
.end (buffer);
return subject;
}
示例4: getFeed
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
private RefreshableRemoteData<Feed> getFeed(String tag) {
ReplaySubject<RemoteStatus> statusSubject = ReplaySubject.createWithSize(1);
ReplaySubject<Feed> feedSubject = ReplaySubject.createWithSize(1);
PublishSubject<Void> refresh = PublishSubject.create();
refresh.observeOn(scheduler).forEach($ -> {
CacheMode mode = CacheMode.DISABLE_CACHE;
fetch(tag, feedSubject, statusSubject, mode);
});
fetch(tag, feedSubject, statusSubject, CacheMode.ENABLE_CACHE);
return new RefreshableRemoteData<>(feedSubject, statusSubject, refresh);
}
示例5: stopUpdates
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@SuppressWarnings("MissingPermission")
@Override
public void stopUpdates() {
Log.d(TAG, "stopUpdates()");
((LocationManager) context
.getSystemService(Context.LOCATION_SERVICE))
.removeUpdates(locationListener);
locationSubject.onCompleted();
locationSubject = ReplaySubject.createWithSize(BUFFER_SIZE);
}
示例6: Aws2Rx
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public Aws2Rx() {
this.subject = ReplaySubject.createWithSize(1);
}
示例7: 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;
}
示例8: turnOff
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Override
@RequiresPermission(allOf = {
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
})
public Observable<Void> turnOff() {
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_ON &&
newState == BluetoothAdapter.STATE_TURNING_OFF) {
logger.info(LOG_TAG, "Bluetooth turning off");
} else if (oldState == BluetoothAdapter.STATE_TURNING_OFF &&
newState == BluetoothAdapter.STATE_OFF) {
logger.info(LOG_TAG, "Bluetooth turned off");
applicationContext.unregisterReceiver(this);
turnOnMirror.onNext(null);
turnOnMirror.onCompleted();
} else {
logger.info(LOG_TAG, "Bluetooth failed to turn off");
applicationContext.unregisterReceiver(this);
turnOnMirror.onError(new ChangePowerStateException());
}
}
};
applicationContext.registerReceiver(receiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
if (!adapter.disable()) {
applicationContext.unregisterReceiver(receiver);
return Observable.error(new ChangePowerStateException());
}
return turnOnMirror;
}
示例9: operatorConditionalBinding
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Test
public void operatorConditionalBinding() throws Exception {
AtomicBoolean permitted = new AtomicBoolean(true);
Func1<AtomicBoolean, Boolean> predicate = new Func1<AtomicBoolean, Boolean>() {
@Override
public Boolean call(AtomicBoolean atomicBoolean) {
return atomicBoolean.get();
}
};
ReplaySubject<Integer> numbers = ReplaySubject.createWithSize(1);
final AtomicInteger counter = new AtomicInteger();
final AtomicBoolean errorCalled = new AtomicBoolean();
numbers.lift(new Rx.OperatorConditionalBinding<Integer, AtomicBoolean>(permitted, predicate))
.subscribe(new Subscriber<Integer>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
errorCalled.set(true);
}
@Override
public void onNext(Integer number) {
counter.addAndGet(number);
}
});
numbers.onNext(1);
numbers.onNext(2);
numbers.onNext(3);
assertEquals(6, counter.get());
permitted.set(false);
numbers.onNext(3);
numbers.onNext(4);
numbers.onNext(5);
numbers.onError(new Throwable("Everything is broken!"));
assertEquals(6, counter.get());
assertFalse(errorCalled.get());
}
示例10: RxSnapperListener
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public RxSnapperListener(String tag) {
this.subject = ReplaySubject.createWithSize(1);
this.tag = tag;
}
示例11: RxBus
import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
/**
* With this constructor the {@link RxBus} use a {@link ReplaySubject} and instantiate it calling the static method {@code ReplaySubject.createWithSize(cacheSize)}
* @see ReplaySubject
* @param cacheSize numbers of max events retained
*/
public RxBus(int cacheSize) {
super((Subject<T, R>) ReplaySubject.createWithSize(cacheSize));
mSubscriptionsList = new WeakHashMap<>();
}