本文整理匯總了Java中rx.subscriptions.Subscriptions類的典型用法代碼示例。如果您正苦於以下問題:Java Subscriptions類的具體用法?Java Subscriptions怎麽用?Java Subscriptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Subscriptions類屬於rx.subscriptions包,在下文中一共展示了Subscriptions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
@Override
public void call(Subscriber<? super T> subscriber) {
final GoogleApiClient apiClient = createApiClient(subscriber);
try {
apiClient.connect();
} catch (Throwable ex) {
subscriber.onError(ex);
}
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
}
}));
}
示例2: call
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
@Override
public void call(final Subscriber<? super T> subscriber) {
result.setResultCallback(new ResultCallback<T>() {
@Override
public void onResult(T t) {
subscriber.onNext(t);
complete = true;
subscriber.onCompleted();
}
});
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (!complete) {
result.cancel();
}
}
}));
}
示例3: createBonjourObservable
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public static Observable<Peer> createBonjourObservable(final Context context) {
return Observable.create(new Observable.OnSubscribe<Peer>() {
@Override
public void call(Subscriber<? super Peer> subscriber) {
final BonjourFinder finder = new BonjourFinder(context, subscriber);
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
finder.cancel();
}
}));
finder.scan();
}
});
}
示例4: createBluetoothObservable
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public static Observable<Peer> createBluetoothObservable(final Context context) {
return Observable.create(new Observable.OnSubscribe<Peer>() {
@Override
public void call(Subscriber<? super Peer> subscriber) {
final BluetoothFinder finder = new BluetoothFinder(context, subscriber);
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
finder.cancel();
}
}));
finder.scan();
}
});
}
示例5: eventSourceSubscription
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
private <T> void eventSourceSubscription(Subscriber<T> s) {
final EventSource source = new EventSource(uri());
final QueuedProducer<T> producer = new QueuedProducer<>(s);
try {
s.add(subscribeEventListener(source, "message", evt -> {
producer.onNext(parse(Js.<MessageEvent<String>>cast(evt).data));
}));
s.add(subscribeEventListener(source, "open", evt -> {
log.fine("Connection opened: " + uri());
}));
s.add(subscribeEventListener(source, "error", evt -> {
log.log(Level.SEVERE, "Error: " + evt);
if (source.readyState == source.CLOSED) {
producer.onError(new RuntimeException("Event source error"));
}
}));
s.setProducer(producer);
s.add(Subscriptions.create(() -> {
// hack because elemental API EventSource.close is missing
Js.<MessagePort>uncheckedCast(source).close();
}));
} catch (Throwable e) {
log.log(Level.FINE, "Received http error for: " + uri(), e);
s.onError(new RuntimeException("Event source error", e));
}
}
示例6: singleValue
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
@NonNull public static Observable<DataSnapshot> singleValue(final Query query) {
return Observable.create(new Observable.OnSubscribe<DataSnapshot>() {
@Override public void call(final Subscriber<? super DataSnapshot> subscriber) {
final ValueEventListener valueEvent = query.addValueEventListener(new ValueEventListener() {
@Override public void onDataChange(DataSnapshot dataSnapshot) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(dataSnapshot);
}
}
@Override public void onCancelled(DatabaseError databaseError) {
subscriber.onError(databaseError.toException());
}
});
subscriber.add(Subscriptions.create(new Action0() {
@Override public void call() {
query.removeEventListener(valueEvent);
}
}));
}
});
}
示例7: schedule
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
@Override
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit) {
if (innerSubscription.isUnsubscribed()) {
return Subscriptions.empty();
}
final ScheduledAction scheduledAction = new ScheduledAction(action, operationQueue);
final ScheduledExecutorService executor = IOSScheduledExecutorPool.getInstance();
Future<?> future;
if (delayTime <= 0) {
future = executor.submit(scheduledAction);
} else {
future = executor.schedule(scheduledAction, delayTime, unit);
}
scheduledAction.add(Subscriptions.from(future));
scheduledAction.addParent(innerSubscription);
return scheduledAction;
}
示例8: openDatabase
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public void openDatabase() {
subscription = Observable.create(new Observable.OnSubscribe<Realm>() {
@Override
public void call(final Subscriber<? super Realm> subscriber) {
final Realm observableRealm = Realm.getDefaultInstance();
final RealmChangeListener<Realm> listener = realm -> {
if(!subscriber.isUnsubscribed()) {
subscriber.onNext(observableRealm);
}
};
observableRealm.addChangeListener(listener);
subscriber.add(Subscriptions.create(() -> {
observableRealm.removeChangeListener(listener);
observableRealm.close();
}));
subscriber.onNext(observableRealm);
}
}).subscribeOn(looperScheduler.getScheduler()).unsubscribeOn(looperScheduler.getScheduler()).subscribe();
}
示例9: enqueue
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
private Subscription enqueue(Action0 action, long execTime) {
if (this.innerSubscription.isUnsubscribed()) {
return Subscriptions.unsubscribed();
}
final TimedAction timedAction = new TimedAction(action, Long.valueOf(execTime), this.counter.incrementAndGet());
this.queue.add(timedAction);
if (this.wip.getAndIncrement() != 0) {
return Subscriptions.create(new Action0() {
public void call() {
InnerCurrentThreadScheduler.this.queue.remove(timedAction);
}
});
}
do {
TimedAction polled = (TimedAction) this.queue.poll();
if (polled != null) {
polled.action.call();
}
} while (this.wip.decrementAndGet() > 0);
return Subscriptions.unsubscribed();
}
示例10: schedule
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public Subscription schedule(Action0 action) {
if (isUnsubscribed()) {
return Subscriptions.unsubscribed();
}
Subscription ea = new ScheduledAction(action, this.tasks);
this.tasks.add(ea);
this.queue.offer(ea);
if (this.wip.getAndIncrement() != 0) {
return ea;
}
try {
this.executor.execute(this);
return ea;
} catch (RejectedExecutionException t) {
this.tasks.remove(ea);
this.wip.decrementAndGet();
RxJavaPlugins.getInstance().getErrorHandler().handleError(t);
throw t;
}
}
示例11: call
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public Subscription call(final TimeoutSubscriber<T> timeoutSubscriber, final Long seqId, Worker inner) {
if (this.val$firstTimeoutSelector == null) {
return Subscriptions.unsubscribed();
}
try {
return ((Observable) this.val$firstTimeoutSelector.call()).unsafeSubscribe(new Subscriber<U>() {
public void onCompleted() {
timeoutSubscriber.onTimeout(seqId.longValue());
}
public void onError(Throwable e) {
timeoutSubscriber.onError(e);
}
public void onNext(U u) {
timeoutSubscriber.onTimeout(seqId.longValue());
}
});
} catch (Throwable t) {
Exceptions.throwOrReport(t, timeoutSubscriber);
return Subscriptions.unsubscribed();
}
}
示例12: call
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public void call(Subscriber<? super T> subscriber) {
subscriber.add(Subscriptions.create(new Action0() {
public void call() {
ToObservableFuture.this.that.cancel(true);
}
}));
try {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(this.unit == null ? this.that.get() : this.that.get(this.time, this.unit));
subscriber.onCompleted();
}
} catch (Throwable e) {
if (!subscriber.isUnsubscribed()) {
Exceptions.throwOrReport(e, subscriber);
}
}
}
示例13: disconnect
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
private Subscription disconnect(final CompositeSubscription current) {
return Subscriptions.create(new Action0() {
public void call() {
OnSubscribeRefCount.this.lock.lock();
try {
if (OnSubscribeRefCount.this.baseSubscription == current && OnSubscribeRefCount.this.subscriptionCount.decrementAndGet() == 0) {
OnSubscribeRefCount.this.baseSubscription.unsubscribe();
OnSubscribeRefCount.this.baseSubscription = new CompositeSubscription();
}
OnSubscribeRefCount.this.lock.unlock();
} catch (Throwable th) {
OnSubscribeRefCount.this.lock.unlock();
}
}
});
}
示例14: init
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
void init() {
this.child.add(Subscriptions.create(new Action0() {
public void call() {
if (ExactSubscriber.this.noWindow) {
ExactSubscriber.this.unsubscribe();
}
}
}));
this.child.setProducer(new Producer() {
public void request(long n) {
if (n > 0) {
long u = n * ((long) OperatorWindowWithSize.this.size);
if (!((u >>> 31) == 0 || u / n == ((long) OperatorWindowWithSize.this.size))) {
u = Long.MAX_VALUE;
}
ExactSubscriber.this.requestMore(u);
}
}
});
}
示例15: call
import rx.subscriptions.Subscriptions; //導入依賴的package包/類
public void call(final Subscriber<? super T> subscriber) {
final SubscriptionLog subscriptionLog = new SubscriptionLog(scheduler.now());
observable.subscriptions.add(subscriptionLog);
final int subscriptionIndex = observable.getSubscriptions().size() - 1;
subscribers.add(subscriber);
subscriber.add((Subscriptions.create(new Action0() {
@Override
public void call() {
// on unsubscribe
observable.subscriptions.set(
subscriptionIndex,
new SubscriptionLog(subscriptionLog.subscribe, scheduler.now())
);
subscribers.remove(subscriber);
}
})));
}