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