All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mutiny.zero.internal.BufferingTube Maven / Gradle / Ivy

Go to download

Mutiny Zero is a minimal API for creating reactive-streams compliant publishers

There is a newer version: 1.1.1
Show newest version
package mutiny.zero.internal;

import java.util.Queue;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.LinkedBlockingDeque;

public class BufferingTube extends BufferingTubeBase {

    private final LinkedBlockingDeque overflowQueue;

    public BufferingTube(Subscriber subscriber, int bufferSize) {
        super(subscriber);
        overflowQueue = new LinkedBlockingDeque<>(bufferSize);
    }

    @Override
    Queue overflowQueue() {
        return overflowQueue;
    }

    @Override
    protected void handleItem(T item) {
        if (outstandingRequests() > 0L) {
            dispatchQueue.offer(item);
            drainLoop();
        } else if (!overflowQueue.offer(item)) {
            fail(new IllegalStateException(
                    "The following item cannot be propagated because there is no demand and the overflow buffer is full: "
                            + item));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy