本文整理汇总了Java中rx.observers.Subscribers类的典型用法代码示例。如果您正苦于以下问题:Java Subscribers类的具体用法?Java Subscribers怎么用?Java Subscribers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Subscribers类属于rx.observers包,在下文中一共展示了Subscribers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import rx.observers.Subscribers; //导入依赖的package包/类
public Subscriber<? super T> call(Subscriber<? super List<T>> child) {
try {
Observable<? extends TClosing> closing = (Observable) this.bufferClosingSelector.call();
final BufferingSubscriber bsub = new BufferingSubscriber(new SerializedSubscriber(child));
Subscriber<TClosing> closingSubscriber = new Subscriber<TClosing>() {
public void onNext(TClosing tClosing) {
bsub.emit();
}
public void onError(Throwable e) {
bsub.onError(e);
}
public void onCompleted() {
bsub.onCompleted();
}
};
child.add(closingSubscriber);
child.add(bsub);
closing.unsafeSubscribe(closingSubscriber);
return bsub;
} catch (Throwable t) {
Exceptions.throwOrReport(t, child);
return Subscribers.empty();
}
}
示例2: call
import rx.observers.Subscribers; //导入依赖的package包/类
public void call(Subscriber<? super T> subscriber) {
DisposeAction<Resource> disposeOnceOnly;
try {
Observable<? extends T> observable;
Resource resource = this.resourceFactory.call();
disposeOnceOnly = new DisposeAction(this.dispose, resource);
subscriber.add(disposeOnceOnly);
Observable<? extends T> source = (Observable) this.observableFactory.call(resource);
if (this.disposeEagerly) {
observable = source.doOnTerminate(disposeOnceOnly);
} else {
observable = source;
}
observable.unsafeSubscribe(Subscribers.wrap(subscriber));
} catch (Throwable e) {
Exceptions.throwOrReport(e, subscriber);
}
}
示例3: filtersByAddress
import rx.observers.Subscribers; //导入依赖的package包/类
@Test
public void filtersByAddress() {
final ShadowBluetoothAdapterExt shadowAdapter = getShadowBluetoothAdapter();
final PeripheralCriteria criteria = new PeripheralCriteria();
criteria.addPeripheralAddress(Testing.DEVICE_ADDRESS);
final LegacyLePeripheralScanner scanner = new LegacyLePeripheralScanner(stack, criteria);
scanner.call(Subscribers.empty());
assertThat(shadowAdapter.getLeScanCallbacks(), hasItem(scanner));
final BluetoothDevice device1 = Testing.createMockDevice();
scanner.onLeScan(device1, Testing.RSSI_DECENT, Testing.EMPTY_SCAN_RESPONSE);
final BluetoothDevice device2 = Testing.createMockDevice("BA:BE:CA:FE:BE:EF");
scanner.onLeScan(device2, Testing.RSSI_BETTER, Testing.EMPTY_SCAN_RESPONSE);
scanner.onConcludeScan();
assertThat(shadowAdapter.getLeScanCallbacks(), not(hasItem(scanner)));
assertThat(scanner.results.keySet(), hasItem(Testing.DEVICE_ADDRESS));
assertThat(scanner.results.keySet(), not(hasItem("BA:BE:CA:FE:BE:EF")));
}
示例4: concludesAtLimit
import rx.observers.Subscribers; //导入依赖的package包/类
@Test
public void concludesAtLimit() {
final ShadowBluetoothAdapterExt shadowAdapter = getShadowBluetoothAdapter();
final ShadowBluetoothLeScanner shadowScanner = BuruberiShadows.shadowOf(shadowAdapter.getBluetoothLeScanner());
final PeripheralCriteria criteria = new PeripheralCriteria();
criteria.setLimit(1);
final LollipopLePeripheralScanner scanner = new LollipopLePeripheralScanner(stack, criteria);
scanner.call(Subscribers.empty());
assertThat(shadowScanner.getScanCallbacks(), hasItem(scanner));
final BluetoothDevice device = Testing.createMockDevice();
final ScanResult scanResult = new ScanResult(device,
Testing.EMPTY_SCAN_RECORD,
Testing.RSSI_DECENT,
SystemClock.elapsedRealtimeNanos());
scanner.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, scanResult);
scanner.onConcludeScan();
assertThat(shadowScanner.getScanCallbacks(), not(hasItem(scanner)));
}
示例5: call
import rx.observers.Subscribers; //导入依赖的package包/类
@Override
public Subscriber<? super T> call(Subscriber<? super Observable<T>> child) {
Observable<? extends U> other;
try {
other = otherFactory.call();
} catch (Throwable e) {
child.onError(e);
return Subscribers.empty();
}
SourceSubscriber<T> sub = new SourceSubscriber<T>(child);
BoundarySubscriber<T, U> bs = new BoundarySubscriber<T, U>(child, sub);
sub.replaceWindow();
other.unsafeSubscribe(bs);
return sub;
}
示例6: start
import rx.observers.Subscribers; //导入依赖的package包/类
@Override
public void start() {
onMemberAddedEventSubscriber = Subscribers.create(remoteMembers::add, this::onError);
membership.listen().observeOn(scheduler)
.filter(MembershipEvent::isAdded)
.map(MembershipEvent::member)
.subscribe(onMemberAddedEventSubscriber);
onMemberRemovedEventSubscriber = Subscribers.create(remoteMembers::remove, this::onError);
membership.listen().observeOn(scheduler)
.filter(MembershipEvent::isRemoved)
.map(MembershipEvent::member)
.subscribe(onMemberRemovedEventSubscriber);
onGossipRequestSubscriber = Subscribers.create(this::onGossipReq, this::onError);
transport.listen().observeOn(scheduler)
.filter(this::isGossipReq)
.subscribe(onGossipRequestSubscriber);
spreadGossipTask = executor.scheduleWithFixedDelay(this::doSpreadGossip,
config.getGossipInterval(), config.getGossipInterval(), TimeUnit.MILLISECONDS);
}
示例7: call
import rx.observers.Subscribers; //导入依赖的package包/类
@Override
public Subscriber<? super T> call(Subscriber<? super T> child) {
Subscriber<T> parent;
if (firstTime.compareAndSet(true, false)) {
// don't delay subscription for the first time
parent = Subscribers.from(child);
} else {
final PublishSubject<T> subject = PublishSubject.create();
Worker worker = scheduler.createWorker();
worker.schedule(() -> {
subject.unsafeSubscribe(child);
}, duration, units);
child.add(worker);
parent = Subscribers.from(subject);
}
child.add(parent);
return parent;
}
示例8: call
import rx.observers.Subscribers; //导入依赖的package包/类
@Override
public void call(final Subscriber<? super T> subscriber) {
if (state.casState(State.STATES.UNSUBSCRIBED, State.STATES.SUBSCRIBED)) {
// drain queued notifications before subscription
// we do this here before PassThruObserver so the consuming thread can do this before putting itself in
// the line of the producer
state.buffer.sendAllNotifications(subscriber);
// register real observer for pass-thru ... and drain any further events received on first notification
state.setObserverRef(new PassThruObserver<>(subscriber, state));
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
state.setObserverRef(Subscribers.empty());
}
}));
} else if (State.STATES.SUBSCRIBED.ordinal() == state.state) {
subscriber.onError(new IllegalStateException("Content can only have one subscription. Use Observable.publish() if you want to multicast."));
} else if (State.STATES.DISPOSED.ordinal() == state.state) {
subscriber.onError(new IllegalStateException("Content stream is already disposed."));
}
}
示例9: call
import rx.observers.Subscribers; //导入依赖的package包/类
@Override
public void call(final Subscriber<? super T> s) {
if (state.casFirst(0, 1)) {
final NotificationLite<T> nl = NotificationLite.instance();
// drain queued notifications before subscription
// we do this here before PassThruObserver so the consuming thread can do this before putting itself in the line of the producer
BufferedObserver<? super T> buffered = (BufferedObserver<? super T>)state.observerRef;
Object o;
while ((o = buffered.buffer.poll()) != null) {
nl.accept(s, o);
}
// register real observer for pass-thru ... and drain any further events received on first notification
state.setObserverRef(new PassThruObserver<T>(s, buffered.buffer, state));
s.add(Subscriptions.create(new Action0() {
@Override
public void call() {
state.setObserverRef(Subscribers.empty());
}
}));
} else {
s.onError(new IllegalStateException("Only one subscriber allowed!"));
}
}
示例10: call
import rx.observers.Subscribers; //导入依赖的package包/类
public void call(final Subscriber<? super T> s) {
Worker worker = this.scheduler.createWorker();
s.add(worker);
worker.schedule(new Action0() {
public void call() {
if (!s.isUnsubscribed()) {
OnSubscribeDelaySubscription.this.source.unsafeSubscribe(Subscribers.wrap(s));
}
}
}, this.time, this.unit);
}
示例11: call
import rx.observers.Subscribers; //导入依赖的package包/类
public void call(Subscriber<? super T> s) {
try {
((Observable) this.observableFactory.call()).unsafeSubscribe(Subscribers.wrap(s));
} catch (Throwable t) {
Exceptions.throwOrReport(t, s);
}
}
示例12: testObserve
import rx.observers.Subscribers; //导入依赖的package包/类
@Test
public void testObserve() throws Exception {
ReplaySubject<String> values = ReplaySubject.create();
observe(reference)
.map(new Func1<DataSnapshot, String>() {
@Override
public String call(DataSnapshot dataSnapshot) {
return dataSnapshot.getValue(String.class);
}
})
.distinctUntilChanged()
.subscribe(values);
Observable
.concat(
setValue(reference, null),
setValue(reference, "foo"),
setValue(reference, "bar"),
setValue(reference, null)
)
.subscribe(Subscribers.<Void>empty());
List<String> observedValues = await(values.take(4).toList());
assertThat(observedValues, contains(null, "foo", "bar", null));
}
示例13: coalescesResults
import rx.observers.Subscribers; //导入依赖的package包/类
@Test
public void coalescesResults() {
final ShadowBluetoothAdapterExt shadowAdapter = getShadowBluetoothAdapter();
final PeripheralCriteria criteria = new PeripheralCriteria();
final LegacyLePeripheralScanner scanner = new LegacyLePeripheralScanner(stack, criteria);
scanner.call(Subscribers.empty());
assertThat(shadowAdapter.getLeScanCallbacks(), hasItem(scanner));
final BluetoothDevice device = Testing.createMockDevice();
scanner.onLeScan(device, Testing.RSSI_DECENT, Testing.EMPTY_SCAN_RESPONSE);
final ScannedPeripheral scannedPeripheral = scanner.results.get(device.getAddress());
assertThat(scannedPeripheral, is(notNullValue()));
assertThat(scannedPeripheral.rssi, is(equalTo(Testing.RSSI_DECENT)));
scanner.onLeScan(device, Testing.RSSI_BETTER, Testing.EMPTY_SCAN_RESPONSE);
final ScannedPeripheral scannedPeripheralAgain = scanner.results.get(device.getAddress());
assertThat(scannedPeripheralAgain, is(notNullValue()));
assertThat(scannedPeripheralAgain.rssi, is(equalTo(Testing.RSSI_BETTER)));
assertThat(scannedPeripheralAgain, is(sameInstance(scannedPeripheral)));
scanner.onConcludeScan();
assertThat(shadowAdapter.getLeScanCallbacks(), not(hasItem(scanner)));
}
示例14: filtersByAdvertisingData
import rx.observers.Subscribers; //导入依赖的package包/类
@Test
public void filtersByAdvertisingData() {
final String serviceIdentifier = "23D1BCEA5F782315DEEF1212E1FE0000";
final ShadowBluetoothAdapterExt shadowAdapter = getShadowBluetoothAdapter();
final PeripheralCriteria criteria = new PeripheralCriteria();
criteria.addExactMatchPredicate(AdvertisingData.TYPE_SERVICE_DATA_128_BIT_UUID,
serviceIdentifier);
final LegacyLePeripheralScanner scanner = new LegacyLePeripheralScanner(stack, criteria);
scanner.call(Subscribers.empty());
assertThat(shadowAdapter.getLeScanCallbacks(), hasItem(scanner));
final BluetoothDevice device1 = Testing.createMockDevice();
final byte[] advertisingData1 = new AdvertisingDataBuilder()
.add(AdvertisingData.TYPE_SERVICE_DATA_128_BIT_UUID, serviceIdentifier)
.buildRaw();
scanner.onLeScan(device1, Testing.RSSI_DECENT, advertisingData1);
final BluetoothDevice device2 = Testing.createMockDevice("BA:BE:CA:FE:BE:EF");
final byte[] advertisingData2 = new AdvertisingDataBuilder()
.add(AdvertisingData.TYPE_SERVICE_DATA_128_BIT_UUID,
"00D1BCEA5F782315DEEF1212E1FE00FF")
.buildRaw();
scanner.onLeScan(device2, Testing.RSSI_BETTER, advertisingData2);
scanner.onConcludeScan();
assertThat(shadowAdapter.getLeScanCallbacks(), not(hasItem(scanner)));
assertThat(scanner.results.keySet(), hasItem(Testing.DEVICE_ADDRESS));
assertThat(scanner.results.keySet(), not(hasItem("BA:BE:CA:FE:BE:EF")));
}
示例15: concludesAtLimit
import rx.observers.Subscribers; //导入依赖的package包/类
@Test
public void concludesAtLimit() {
final ShadowBluetoothAdapterExt shadowAdapter = getShadowBluetoothAdapter();
final PeripheralCriteria criteria = new PeripheralCriteria();
criteria.setLimit(1);
final LegacyLePeripheralScanner scanner = new LegacyLePeripheralScanner(stack, criteria);
scanner.call(Subscribers.empty());
assertThat(shadowAdapter.getLeScanCallbacks(), hasItem(scanner));
final BluetoothDevice device = Testing.createMockDevice();
scanner.onLeScan(device, Testing.RSSI_DECENT, Testing.EMPTY_SCAN_RESPONSE);
assertThat(shadowAdapter.getLeScanCallbacks(), not(hasItem(scanner)));
}