Java Code Examples for java.util.concurrent.Flow#Subscription

The following examples show how to use java.util.concurrent.Flow#Subscription . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Http1Request.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    if (this.subscription != null) {
        throw new IllegalStateException("already subscribed");
    }
    this.subscription = subscription;
    subscription.request(1);
}
 
Example 2
Source File: HttpInputStreamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
    synchronized (this) {
        closed = true;
        Flow.Subscription s = subscription;
        if (s != null) {
            s.cancel();
        }
        subscription = null;
    }
    super.close();
}
 
Example 3
Source File: DockerXDemoSubscriber.java    From Java-9-Spring-Webflux with Apache License 2.0 5 votes vote down vote up
public void onSubscribe(Flow.Subscription subscription) {
    //count = bufferSize - bufferSize / 2;// 当消费一半的时候重新请求
    (this.subscription = subscription).request(bufferSize);
    System.out.println("开始onSubscribe订阅");
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: DockerXDemoSubscriber.java    From Java-programming-methodology-Rxjava-articles with Apache License 2.0 5 votes vote down vote up
public void onSubscribe(Flow.Subscription subscription) {
    //count = bufferSize - bufferSize / 2;// 当消费一半的时候重新请求
    (this.subscription = subscription).request(bufferSize);
    System.out.println("开始onSubscribe订阅");
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: FlowApiLiveVideo.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    this.subscription = subscription;
    subscription.request(1);
}
 
Example 6
Source File: DockerXDemoSubscriber.java    From Java-9-Spring-Webflux with Apache License 2.0 4 votes vote down vote up
public Flow.Subscription getSubscription() {
    return subscription;
}
 
Example 7
Source File: JdkFlowAdapter.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
public void onSubscribe(final Flow.Subscription subscription) {
    this.subscription = subscription;
	s.onSubscribe(this);
}
 
Example 8
Source File: DemoSubscriber.java    From Java-9-Cookbook with MIT License 4 votes vote down vote up
public void onSubscribe(Flow.Subscription subscription) {
    this.subscription = subscription;
    this.subscription.request(0);
}
 
Example 9
Source File: Processor.java    From Java-9-Cookbook with MIT License 4 votes vote down vote up
public void onSubscribe(Flow.Subscription subscription) {
    this.subscription = subscription;
    this.subscription.request(0);
}
 
Example 10
Source File: MCRCommandListProcessor.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    this.upstreamSubscription = subscription;
    upstreamSubscription.request(1);
}
 
Example 11
Source File: ResponseProcessors.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    this.subscription = subscription;
    subscription.request(1);
}
 
Example 12
Source File: Actor.java    From Fibry with MIT License 4 votes vote down vote up
Flow.Subscriber<T> asReactiveSubscriber(int optimalQueueLength, Consumer<Throwable> onErrorHandler, Consumer<PartialActor<T, S>> onCompleteHandler) {
    AtomicReference<Flow.Subscription> sub = new AtomicReference<>();
    return new Flow.Subscriber<T>() {
        private void askRefill() {
            int messagesRequired = optimalQueueLength - queue.size();

            if (messagesRequired > 0)
                sub.get().request(messagesRequired);
        }

        @Override
        public void onSubscribe(Flow.Subscription subscription) {
            if (sub.get() != null)
                subscription.cancel();
            else {
                sub.set(subscription);
                askRefill();
            }
        }

        @Override
        public void onNext(T item) {
            Objects.requireNonNull(item);

            execAsync(() -> {
                actorLogic.accept(item);
                askRefill();
            });
        }

        @Override
        public void onError(Throwable throwable) {
            Objects.requireNonNull(throwable);
            execAsync(() -> {
                if (onErrorHandler != null)
                    onErrorHandler.accept(throwable);
            });

            sendPoisonPill();
        }

        @Override
        public void onComplete() {
            execAsync(() -> {
                if (onCompleteHandler != null)
                    onCompleteHandler.accept(Actor.this);
            });
            sendPoisonPill();
        }
    };
}
 
Example 13
Source File: DataProviderReactiveImpl.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super FlowData> subscriber) {
    subscribers.add(subscriber);
    Flow.Subscription subscription = new SubscriptionImpl(this);
    subscriber.onSubscribe(subscription);
}
 
Example 14
Source File: SimpleRowSubscriber.java    From pgadba with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
  this.subscription = subscription;
  this.subscription.request(10);
  demand += 10;
}
 
Example 15
Source File: ResponseProcessors.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    this.subscription = subscription;
    subscription.request(Long.MAX_VALUE);
}
 
Example 16
Source File: HttpInputStreamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription s) {
    this.subscription = s;
    s.request(Math.max(2, buffers.remainingCapacity() + 1));
}
 
Example 17
Source File: DockerXDemoSubscriber.java    From Java-programming-methodology-Rxjava-articles with Apache License 2.0 4 votes vote down vote up
public Flow.Subscription getSubscription() {
    return subscription;
}
 
Example 18
Source File: InvoiceCalculator.java    From Java-9-Programming-By-Example with MIT License 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    subscription.request(INFINITE);
}
 
Example 19
Source File: Lesson4.java    From Java-Concurrency-Multithreading-in-Practice with MIT License 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
	this.subscription = subscription;
	subscription.request(1);
}
 
Example 20
Source File: InventoryKeeper.java    From Java-9-Programming-By-Example with MIT License 4 votes vote down vote up
@Override
public void onSubscribe(Flow.Subscription subscription) {
    log.info("onSubscribe was called");
    subscription.request(3);
    this.subscription = subscription;
}