io.vlingo.reactivestreams.StreamPublisher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vlingo-streams Show documentation
Show all versions of vlingo-streams Show documentation
Reactive Streams for the VLINGO XOOM Platform.
// Copyright © 2012-2020 VLINGO LABS. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.
package io.vlingo.reactivestreams;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import io.vlingo.actors.Actor;
import io.vlingo.actors.Stoppable;
import io.vlingo.common.Scheduled;
public class StreamPublisher extends Actor implements Publisher, ControlledSubscription, Scheduled, Stoppable {
private final StreamPublisherDelegate delegate;
@SuppressWarnings("unchecked")
public StreamPublisher(final Source source, final PublisherConfiguration configuration) {
this.delegate = new StreamPublisherDelegate<>(source, configuration, selfAs(ControlledSubscription.class), scheduler(), selfAs(Scheduled.class), selfAs(Stoppable.class));
}
//===================================
// Publisher
//===================================
@Override
public void subscribe(final Subscriber super T> subscriber) {
if (subscriber != null) {
delegate.subscribe(subscriber);
}
}
//===================================
// ControlledSubscription
//===================================
@Override
public void cancel(final SubscriptionController controller) {
delegate.cancel(controller);
}
@Override
public void request(final SubscriptionController controller, final long maximum) {
delegate.request(controller, maximum);
}
//===================================
// Scheduled
//===================================
@Override
public void intervalSignal(final Scheduled scheduled, final Void data) {
delegate.processNext();
}
//===================================
// Internal implementation
//===================================
@Override
public void stop() {
delegate.stop();
super.stop();
}
}