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

The following examples show how to use java.util.concurrent.Flow#Subscriber . 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: PgRowPublisherOperation.java    From pgadba with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public ParameterizedRowPublisherOperation<R> subscribe(Flow.Subscriber<? super Result.RowColumn> subscriber,
    CompletionStage<? extends R> result) {
  if (result == null) {
    throw new IllegalArgumentException("result is not allowed to be null");
  }
  if (subscriber == null) {
    throw new IllegalArgumentException("subscriber is not allowed to be null");
  }

  publisher.subscribe(subscriber);
  this.result = result;
  result.thenAccept(r -> {
    if (groupSubmission != null) {
      groupSubmission.addGroupResult(r);
    }
    submission.getCompletionStage().toCompletableFuture().complete(r);
  });
  return this;
}
 
Example 2
Source File: TestReactiveSubscribers.java    From Fibry with MIT License 5 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super Integer> subscriber) {
    subscriber.onSubscribe(new Flow.Subscription() {
        private final AtomicBoolean completed = new AtomicBoolean(false);
        private final AtomicInteger numMessagesToSend = new AtomicInteger();
        private final Actor<Flow.Subscriber<? super Integer>, Void, Void> actorRefill = ActorSystem.anonymous().newActor(sub -> {
            while (numSent.get() < numMax && numMessagesToSend.get() > 0) {
                subscriber.onNext(numSent.incrementAndGet());
                numMessagesToSend.decrementAndGet();
            }

            if (numSent.get() >= numMax) {
                if (completed.compareAndSet(false, true))
                    subscriber.onComplete();
            }
        });

        @Override
        public void request(long n) {
            if (numSent.get() >= numMax)
                return;

            numMessagesToSend.accumulateAndGet((int) n, Math::max);

            actorRefill.sendMessage(subscriber);
        }

        @Override
        public void cancel() {
            numSent.set(numMax);
        }
    });
}
 
Example 3
Source File: PushPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Subscription(Flow.Subscriber<? super T> subscriber) {
    PushPublisher.this.subscriber = subscriber;
}
 
Example 4
Source File: PullPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Subscription(Flow.Subscriber<? super T> subscriber, Iterator<T> iter) {
    this.subscriber = subscriber;
    this.iter = iter;
}
 
Example 5
Source File: PullPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super T> subscriber) {
    subscriber.onSubscribe(new Subscription(subscriber, iterable.iterator()));
}
 
Example 6
Source File: BlockingPushPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Subscription(Flow.Subscriber<? super T> subscriber) {
    BlockingPushPublisher.this.subscriber = subscriber;
}
 
Example 7
Source File: BlockingPushPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super T> subscriber) {
    state = SubscriptionState.OPENED;
    subscription = new Subscription(subscriber);
    subscriber.onSubscribe(subscription);
}
 
Example 8
Source File: RequestProcessors.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) {
    List<ByteBuffer> copy = copy(content, offset, length);
    this.delegate = new PullPublisher<>(copy);
    delegate.subscribe(subscriber);
}
 
Example 9
Source File: PushPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super T> subscriber) {
    subscription = new Subscription(subscriber);
    subscriber.onSubscribe(subscription);
}
 
Example 10
Source File: Subscription.java    From Java-9-Cookbook with MIT License 4 votes vote down vote up
public Subscription(Flow.Subscriber subscriber,
                    ExecutorService executor) {
    this.subscriber = subscriber;
    this.executor = executor;
}
 
Example 11
Source File: DemoSubscription.java    From Java-11-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
public DemoSubscription(Flow.Subscriber subscriber,
                        ExecutorService executor) {
    this.subscriber = subscriber;
    this.executor = executor;
}
 
Example 12
Source File: JdkFlowAdapter.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
public FlowSubscriber(Flow.Subscriber<? super T> subscriber) {
	this.subscriber = subscriber;
}
 
Example 13
Source File: RequestProcessors.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) {
    delegate.subscribe(subscriber);
}
 
Example 14
Source File: FlowAdapter.java    From java-async-util with Apache License 2.0 4 votes vote down vote up
IteratorBackedSubscription(final AsyncIterator<T> iterator,
    final Flow.Subscriber<? super T> subscriber) {
  this.iterator = Objects.requireNonNull(iterator);
  this.subscriber = Objects.requireNonNull(subscriber);
}
 
Example 15
Source File: RequestProcessors.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) {
    Iterable<ByteBuffer> iterable = this::iterator;
    this.delegate = new PullPublisher<>(iterable);
    delegate.subscribe(subscriber);
}
 
Example 16
Source File: ShortRequestBody.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) {
    delegate.subscribe(subscriber);
}
 
Example 17
Source File: TestReactiveSubscribersWhiteBox.java    From Fibry with MIT License 4 votes vote down vote up
@Override
public Flow.Subscriber<Integer> createFlowSubscriber(final WhiteboxSubscriberProbe<Integer> probe) {
    var realSubscriber = ActorSystem.anonymous().newActor((Integer n) -> {
    }).asReactiveSubscriber(100, null, null);

    return new Flow.Subscriber<Integer>() {
        @Override
        public void onSubscribe(Flow.Subscription subscription) {
            realSubscriber.onSubscribe(subscription);

            // register a successful Subscription, and create a Puppet,
            // for the WhiteboxVerification to be able to drive its tests:
            probe.registerOnSubscribe(new SubscriberPuppet() {
                @Override
                public void triggerRequest(long elements) {
                    subscription.request(elements);
                }

                @Override
                public void signalCancel() {
                    subscription.cancel();
                }
            });
        }

        @Override
        public void onNext(Integer item) {
            realSubscriber.onNext(item);
            probe.registerOnNext(item);
        }

        @Override
        public void onError(Throwable throwable) {
            realSubscriber.onError(throwable);
            probe.registerOnError(throwable);
        }

        @Override
        public void onComplete() {
            realSubscriber.onComplete();
            probe.registerOnComplete();
        }
    };
}
 
Example 18
Source File: PseudoPublisher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void subscribe(Flow.Subscriber<? super T> subscriber) {
    subscriber.onSubscribe(new Subscription(subscriber));
}
 
Example 19
Source File: ParameterizedRowPublisherOperation.java    From pgadba with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @return this {@code ParameterizedRowPublisherOperation}
 */
@Override
public ParameterizedRowPublisherOperation<T> subscribe(Flow.Subscriber<? super Result.RowColumn> subscriber,
                                                        CompletionStage<? extends T> result);
 
Example 20
Source File: RowPublisherOperation.java    From pgadba with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Subscribe to the stream of rows returned by this {@link Operation}. The
 *  value of the {@code result} parameter is the result of this {@link Operation}.
 *
 * @param subscriber Not null.
 * @param result Not null.
 * @return this RowPublisherOperation
 */
public RowPublisherOperation<T> subscribe(Flow.Subscriber<? super Result.RowColumn> subscriber,
                                          CompletionStage<? extends T> result);