本文整理匯總了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));
}