當前位置: 首頁>>代碼示例>>Java>>正文


Java Subscriptions類代碼示例

本文整理匯總了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();
            }
        }
    }));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:BaseObservable.java

示例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();
            }
        }
    }));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:PendingResultObservable.java

示例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();
        }
    });
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:18,代碼來源:BonjourFinder.java

示例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();
        }
    });
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:18,代碼來源:BluetoothFinder.java

示例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));
    }
}
 
開發者ID:ibaca,項目名稱:autorest-streaming-example,代碼行數:27,代碼來源:XhrResourceBuilder.java

示例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);
                }
            }));
        }
    });
}
 
開發者ID:isfaaghyth,項目名稱:RxFBase,代碼行數:22,代碼來源:RxFirebase.java

示例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;
}
 
開發者ID:SnowdogApps,項目名稱:MoeSampleApp,代碼行數:18,代碼來源:HandlerThreadScheduler.java

示例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();
}
 
開發者ID:Zhuinden,項目名稱:navigator,代碼行數:20,代碼來源:DatabaseManager.java

示例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();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:22,代碼來源:TrampolineScheduler.java

示例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;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:ExecutorScheduler.java

示例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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:OperatorTimeoutWithSelector.java

示例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);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:OnSubscribeToObservableFuture.java

示例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();
            }
        }
    });
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:OnSubscribeRefCount.java

示例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);
            }
        }
    });
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:OperatorWindowWithSize.java

示例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);
        }
    })));
}
 
開發者ID:alexvictoor,項目名稱:MarbleTest4J,代碼行數:20,代碼來源:HotObservable.java


注:本文中的rx.subscriptions.Subscriptions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。