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


Java Subscriber.onSubscribe方法代碼示例

本文整理匯總了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() {
            }
        }
    );
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:19,代碼來源:SingleByteArrayAsyncRequestProvider.java

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

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

示例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);
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:17,代碼來源:FlowableFromCallable.java

示例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();
        }
    };
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:30,代碼來源:SubscribeOnlyOnceFlowableOperator.java

示例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);
     }
 }
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:30,代碼來源:NettyFuturePublisher.java

示例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);
        }
    };
}
 
開發者ID:MFlisar,項目名稱:RxBus2,代碼行數:30,代碼來源:RxSubscriptionUtil.java

示例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);
        }
    };
}
 
開發者ID:MFlisar,項目名稱:RxBus2,代碼行數:31,代碼來源:RxBusUtil.java

示例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;
        }
      });
    }
  };
}
 
開發者ID:rogues-dev,項目名稱:hoard,代碼行數:35,代碼來源:Hoard.java

示例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() {

                }
            });
        }
    };
}
 
開發者ID:sejoung,項目名稱:ReactiveTest,代碼行數:29,代碼來源:PubSub2.java

示例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));
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:10,代碼來源:FlowableFromArray.java

示例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));
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:10,代碼來源:FlowableRange.java

示例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() {
        }
    });
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:15,代碼來源:ExecutionInterceptorTest.java

示例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;
        }
      });
    }
  };
}
 
開發者ID:rogues-dev,項目名稱:hoard,代碼行數:29,代碼來源:DefaultReactiveStreamDepositor.java

示例15: subscribe

import org.reactivestreams.Subscriber; //導入方法依賴的package包/類
@Override
public void subscribe(Subscriber<? super T> subscriber) {
    subscriber.onSubscribe(new MqttSubscription(subscriber));
}
 
開發者ID:cschneider,項目名稱:reactive-components,代碼行數:5,代碼來源:MqttSource.java


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