本文整理汇总了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<>();
}