本文整理汇总了Java中org.reactivestreams.Subscriber.onSubscribe方法的典型用法代码示例。如果您正苦于以下问题:Java Subscriber.onSubscribe方法的具体用法?Java Subscriber.onSubscribe怎么用?Java Subscriber.onSubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.reactivestreams.Subscriber
的用法示例。
在下文中一共展示了Subscriber.onSubscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribe
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
subscriber.onSubscribe(
new Subscription() {
@Override
public void request(long n) {
if (n > 0) {
subscriber.onNext(ByteBuffer.wrap(bytes));
subscriber.onComplete();
}
}
@Override
public void cancel() {
}
}
);
}
示例2: subscribeActual
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribeActual(Subscriber<? super T> s) {
DeferredScalarSubscription<T> deferred = new DeferredScalarSubscription<T>(s);
s.onSubscribe(deferred);
T v;
try {
v = unit != null ? future.get(timeout, unit) : future.get();
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
if (!deferred.isCancelled()) {
s.onError(ex);
}
return;
}
if (v == null) {
s.onError(new NullPointerException("The future returned null"));
} else {
deferred.complete(v);
}
}
示例3: subscribe
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribe(Subscriber<? super E> s) {
subscriber = s;
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
try {
E event = dispatcher.waitFor(clazz, n);
subscriber.onNext(event);
} catch (InterruptedException e) {
if (subscriber != null)
subscriber.onError(e);
}
}
@Override
public void cancel() {
dispatcher.unregisterListener(this);
}
});
}
示例4: subscribeActual
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribeActual(Subscriber<? super T> s) {
DeferredScalarSubscription<T> deferred = new DeferredScalarSubscription<T>(s);
s.onSubscribe(deferred);
T t;
try {
t = ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value");
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
s.onError(ex);
return;
}
deferred.complete(t);
}
示例5: apply
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public Subscriber<? super T> apply(final Subscriber<? super T> observer) {
return new Subscriber<T>() {
@Override
public void onSubscribe(Subscription subscription) {
if (subscribedOnce.getAndSet(true)) {
throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " +
"concurrently. Use Flowable.share() instead.");
} else {
observer.onSubscribe(subscription);
}
}
@Override
public void onNext(T t) {
observer.onNext(t);
}
@Override
public void onError(Throwable throwable) {
observer.onError(throwable);
}
@Override
public void onComplete() {
observer.onComplete();
}
};
}
示例6: subscribe
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribe(final Subscriber<? super T> subscriber) {
try {
subscriber.onSubscribe(new ReactiveSubscription<T>(this, subscriber) {
@Override
protected void onRequest(long n) {
supplier.get().addListener(new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
onError(future.cause());
return;
}
if (future.getNow() != null) {
onNext(future.getNow());
}
onComplete();
}
});
}
});
} catch (Throwable throwable) {
//Exceptions.throwIfFatal(throwable);
Exceptions.getFinalCause(throwable);
subscriber.onError(throwable);
}
}
示例7: wrapSubscriber
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
public static <T> Subscriber<T> wrapSubscriber(Subscriber<T> subscriber, IRxBusQueue isResumedProvider)
{
return new Subscriber<T>()
{
@Override
public void onSubscribe(Subscription s) {
subscriber.onSubscribe(s);
}
@Override
public void onComplete()
{
subscriber.onComplete();
}
@Override
public void onError(Throwable e)
{
subscriber.onError(e);
}
@Override
public void onNext(T t)
{
if (RxUtil.safetyQueueCheck(t, isResumedProvider))
subscriber.onNext(t);
}
};
}
示例8: wrapSubscriber
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
public static <T> Subscriber<T> wrapSubscriber(Subscriber<T> subscriber, IRxBusQueue isResumedProvider)
{
return new Subscriber<T>()
{
@Override
public void onSubscribe(Subscription s) {
subscriber.onSubscribe(s);
}
@Override
public void onComplete()
{
subscriber.onComplete();
}
@Override
public void onError(Throwable e)
{
subscriber.onError(e);
}
@Override
public void onNext(T t)
{
if (RxUtil.safetyQueueCheck(t, isResumedProvider))
subscriber.onNext(t);
}
};
}
示例9: deleteAllReactive
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
/**
* Same as {@link #deleteAll()} but wrapped in a {@link Publisher}.
*
* @return Publisher that when subscribed will preform the delete operation.
*/
public Publisher<Void> deleteAllReactive() {
return new Publisher<Void>() {
@Override public void subscribe(final Subscriber<? super Void> s) {
s.onSubscribe(new Subscription() {
volatile boolean canceled = false;
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override public void request(long n) {
try {
File[] files = rootDirectory.listFiles();
if (files == null) return;
for (File file : files) {
file.delete();
}
if (canceled) return;
s.onComplete();
} catch (Exception e) {
if (canceled) return;
s.onError(e);
}
}
@Override public void cancel() {
canceled = true;
}
});
}
};
}
示例10: iterPub
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
private static <T> Publisher<T> iterPub(List<T> iter) {
return new Publisher<T>() {
@Override
public void subscribe(Subscriber subscriber) {
subscriber.onSubscribe(new Subscription() {
@Override
public void request(long l) {
try {
iter.forEach(s -> subscriber.onNext(s));
subscriber.onComplete();
} catch (Throwable t) {
subscriber.onError(t);
}
}
@Override
public void cancel() {
}
});
}
};
}
示例11: subscribeActual
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribeActual(Subscriber<? super T> s) {
if (s instanceof ConditionalSubscriber) {
s.onSubscribe(new ArrayConditionalSubscription<T>(
(ConditionalSubscriber<? super T>)s, array));
} else {
s.onSubscribe(new ArraySubscription<T>(s, array));
}
}
示例12: subscribeActual
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribeActual(Subscriber<? super Integer> s) {
if (s instanceof ConditionalSubscriber) {
s.onSubscribe(new RangeConditionalSubscription(
(ConditionalSubscriber<? super Integer>)s, start, end));
} else {
s.onSubscribe(new RangeSubscription(s, start, end));
}
}
示例13: subscribe
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribe(Subscriber<? super ByteBuffer> s) {
// TODO: For content-length 0 should we require them to do this?
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
s.onComplete();
}
@Override
public void cancel() {
}
});
}
示例14: retrieve
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override public Publisher<T> retrieve() {
return new Publisher<T>() {
@Override public void subscribe(final Subscriber<? super T> s) {
s.onSubscribe(new Subscription() {
volatile boolean canceled = false;
@Override public void request(long n) {
try {
T value = depositor.retrieve();
if (canceled) return;
if (value != null) {
s.onNext(value);
}
s.onComplete();
} catch (Exception e) {
if (canceled) return;
s.onError(e);
}
}
@Override public void cancel() {
canceled = true;
}
});
}
};
}
示例15: subscribe
import org.reactivestreams.Subscriber; //导入方法依赖的package包/类
@Override
public void subscribe(Subscriber<? super T> subscriber) {
subscriber.onSubscribe(new MqttSubscription(subscriber));
}