当前位置: 首页>>代码示例>>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;未经允许,请勿转载。