本文整理汇总了Java中reactor.core.Disposable.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java Disposable.dispose方法的具体用法?Java Disposable.dispose怎么用?Java Disposable.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.Disposable
的用法示例。
在下文中一共展示了Disposable.dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clientCanCancelServerStreamExplicitly
import reactor.core.Disposable; //导入方法依赖的package包/类
@Test
public void clientCanCancelServerStreamExplicitly() throws InterruptedException {
AtomicInteger lastNumberConsumed = new AtomicInteger(Integer.MAX_VALUE);
ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(channel);
Flux<NumberProto.Number> test = stub
.responsePressure(Mono.just(Empty.getDefaultInstance()))
.doOnNext(number -> {lastNumberConsumed.set(number.getNumber(0)); System.out.println("C: " + number.getNumber(0));})
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.doOnComplete(() -> System.out.println("Completed"))
.doOnCancel(() -> System.out.println("Client canceled"));
Disposable subscription = test.publish().connect();
Thread.sleep(1000);
subscription.dispose();
Thread.sleep(1000);
// Cancellation may or may not deliver the last generated message due to delays in the gRPC processing thread
assertThat(Math.abs(lastNumberConsumed.get() - svc.getLastNumberProduced())).isLessThanOrEqualTo(3);
assertThat(svc.wasCanceled()).isTrue();
}
示例2: main
import reactor.core.Disposable; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Flux<String> flux = client.get() //
.uri("/sse/messages") //
.retrieve() //
.bodyToFlux(String.class) //
.doOnNext(System.out::println);
System.out.println("Subscribing to SSE");
Disposable subscription = flux.subscribe();
System.out.println("Press any key to terminate subscription...");
System.in.read();
subscription.dispose();
}
示例3: coordinatorCacheInnerDisposedOrNoReferenceNoLeak
import reactor.core.Disposable; //导入方法依赖的package包/类
@Test
public void coordinatorCacheInnerDisposedOrNoReferenceNoLeak() throws InterruptedException {
TestPublisher<Integer> source = TestPublisher.create();
MonoCacheTime<Integer> cached = new MonoCacheTime<>(source.mono(),
Duration.ofMillis(100), //short cache TTL should trigger state change if source is not never
Schedulers.parallel());
Disposable d1 = cached.subscribe();
cached.subscribe();
WeakReference<Signal<Integer>> refCoordinator = new WeakReference<>(cached.state);
assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class);
Thread.sleep(150);
source = null;
cached = null;
d1.dispose();
System.gc();
assertThat(refCoordinator.get()).isNull();
}
示例4: onCancel
import reactor.core.Disposable; //导入方法依赖的package包/类
@Override
public MonoSink<T> onCancel(Disposable d) {
Objects.requireNonNull(d, "onCancel");
SinkDisposable sd = new SinkDisposable(null, d);
if (!DISPOSABLE.compareAndSet(this, null, sd)) {
Disposable c = disposable;
if (c instanceof SinkDisposable) {
SinkDisposable current = (SinkDisposable) c;
if (current.onCancel == null) {
current.onCancel = d;
}
else {
d.dispose();
}
}
}
return this;
}
示例5: onCancel
import reactor.core.Disposable; //导入方法依赖的package包/类
@Override
public final FluxSink<T> onCancel(Disposable d) {
Objects.requireNonNull(d, "onCancel");
SinkDisposable sd = new SinkDisposable(null, d);
if (!DISPOSABLE.compareAndSet(this, null, sd)) {
Disposable c = disposable;
if (c instanceof SinkDisposable) {
SinkDisposable current = (SinkDisposable) c;
if (current.onCancel == null) {
current.onCancel = d;
}
else {
d.dispose();
}
}
}
return this;
}
示例6: cancelReceiver
import reactor.core.Disposable; //导入方法依赖的package包/类
final boolean cancelReceiver() {
Disposable c = receiverCancel;
if (c != CANCELLED) {
c = CANCEL.getAndSet(this, CANCELLED);
if (c != CANCELLED) {
c.dispose();
return true;
}
}
return false;
}
示例7: cancel
import reactor.core.Disposable; //导入方法依赖的package包/类
@Override
public void cancel() {
Disposable c = cancel;
if (c != OperatorDisposables.DISPOSED && c != FINISHED) {
c = CANCEL.getAndSet(this, OperatorDisposables.DISPOSED);
if (c != null && c != OperatorDisposables.DISPOSED && c != FINISHED) {
c.dispose();
}
}
}
示例8: subscriptionCancelNullifiesActual
import reactor.core.Disposable; //导入方法依赖的package包/类
@Test
public void subscriptionCancelNullifiesActual() {
UnicastProcessor<String> processor = UnicastProcessor.create();
assertThat(processor.downstreamCount())
.as("before subscribe")
.isZero();
LambdaSubscriber<String> subscriber = new LambdaSubscriber<>(null, null, null, null);
Disposable subscription = processor.subscribeWith(subscriber);
assertThat(processor.downstreamCount())
.as("after subscribe")
.isEqualTo(1);
assertThat(processor.actual())
.as("after subscribe")
.isSameAs(subscriber);
subscription.dispose();
assertThat(processor.downstreamCount())
.as("after subscription cancel")
.isZero();
assertThat(processor.actual())
.as("after subscription cancel")
.isNull();
}
示例9: reconnectsAfterRefCountZero
import reactor.core.Disposable; //导入方法依赖的package包/类
@Test
public void reconnectsAfterRefCountZero() {
AtomicLong subscriptionCount = new AtomicLong();
AtomicReference<SignalType> termination = new AtomicReference<>();
Flux<Integer> source = Flux.range(1, 50)
.delayElements(Duration.ofMillis(100))
.doFinally(termination::set)
.doOnSubscribe(s -> subscriptionCount.incrementAndGet());
Flux<Integer> refCounted = source.publish().refCount(2);
Disposable sub1 = refCounted.subscribe();
assertThat(subscriptionCount.get()).isZero();
assertThat(termination.get()).isNull();
Disposable sub2 = refCounted.subscribe();
assertThat(subscriptionCount.get()).isEqualTo(1);
assertThat(termination.get()).isNull();
sub1.dispose();
assertThat(subscriptionCount.get()).isEqualTo(1);
assertThat(termination.get()).isNull();
sub2.dispose();
assertThat(subscriptionCount.get()).isEqualTo(1);
assertThat(termination.get()).isEqualTo(SignalType.CANCEL);
try {
sub1 = refCounted.subscribe();
sub2 = refCounted.subscribe();
assertThat(subscriptionCount.get()).isEqualTo(2);
} finally {
sub1.dispose();
sub2.dispose();
}
}
示例10: setMainFuture
import reactor.core.Disposable; //导入方法依赖的package包/类
void setMainFuture(Disposable c) {
for (; ; ) {
Disposable a = mainFuture;
if (a == OperatorDisposables.DISPOSED) {
c.dispose();
return;
}
if (MAIN_FUTURE.compareAndSet(this, a, c)) {
return;
}
}
}
示例11: cancel
import reactor.core.Disposable; //导入方法依赖的package包/类
@Override
public void cancel() {
Disposable c = future;
if (c != OperatorDisposables.DISPOSED) {
c = FUTURE.getAndSet(this, OperatorDisposables.DISPOSED);
if (c != null && !OperatorDisposables.isDisposed(c)) {
c.dispose();
}
value = null;
}
s.cancel();
}
示例12: setRequestFuture
import reactor.core.Disposable; //导入方法依赖的package包/类
void setRequestFuture(Disposable c) {
for (; ; ) {
Disposable a = requestFuture;
if (a == OperatorDisposables.DISPOSED) {
c.dispose();
return;
}
if (REQUEST_FUTURE.compareAndSet(this, a, c)) {
return;
}
}
}
示例13: disposeSubscribeNoThreadLeak
import reactor.core.Disposable; //导入方法依赖的package包/类
@Test(timeout = 15000L)
public void disposeSubscribeNoThreadLeak() throws Exception {
WorkQueueProcessor<String> wq = WorkQueueProcessor.<String>builder().autoCancel(false).build();
Disposable d = wq.subscribe();
d.dispose();
d = wq.subscribe();
d.dispose();
d = wq.subscribe();
d.dispose();
while (wq.downstreamCount() != 0 && Thread.activeCount() > 2) {
}
}
示例14: dispose
import reactor.core.Disposable; //导入方法依赖的package包/类
/**
* Atomically dispose the {@link Disposable} in the field if not already disposed.
*
* @param updater the target field updater
* @param holder the target instance holding the field
* @return true if the {@link Disposable} held by the field was properly disposed
*/
public static <T> boolean dispose(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder) {
Disposable current = updater.get(holder);
Disposable d = DISPOSED;
if (current != d) {
current = updater.getAndSet(holder, d);
if (current != d) {
if (current != null) {
current.dispose();
}
return true;
}
}
return false;
}
示例15: validate
import reactor.core.Disposable; //导入方法依赖的package包/类
/**
* Verify that current is null and next is not null, otherwise signal a
* {@link NullPointerException} to the {@code errorCallback} and return false.
*
* @param current the current {@link Disposable}, expected to be null
* @param next the next {@link Disposable}, expected to be non-null
* @return true if the validation succeeded
*/
public static boolean validate(@Nullable Disposable current, Disposable next,
Consumer<RuntimeException> errorCallback) {
//noinspection ConstantConditions
if (next == null) {
errorCallback.accept(new NullPointerException("next is null"));
return false;
}
if (current != null) {
next.dispose();
errorCallback.accept(new IllegalStateException("Disposable already pushed"));
return false;
}
return true;
}