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

com.yelstream.topp.furnace.reactive.integration.SubscriberToQueue Maven / Gradle / Ivy

Go to download

Topp Furnace Reactive Integration provides interactions between selected reactive frameworks.

The newest version!
package com.yelstream.topp.furnace.reactive.integration;

import java.util.Queue;
import java.util.concurrent.Flow;
import java.util.concurrent.atomic.AtomicBoolean;

public class SubscriberToQueue implements Flow.Subscriber {

    private final Queue queue;
    private Flow.Subscription subscription;
    private final AtomicBoolean completed = new AtomicBoolean(false);

    public SubscriberToQueue(Queue queue) {
        this.queue = queue;
    }

    @Override
    public void onSubscribe(Flow.Subscription subscription) {
        this.subscription = subscription;
        subscription.request(Long.MAX_VALUE); // Request all items
    }

    @Override
    public void onNext(T item) {
        queue.offer(item); // Non-blocking put
    }

    @Override
    public void onError(Throwable throwable) {
        throwable.printStackTrace(); // Handle error appropriately
        completed.set(true);
    }

    @Override
    public void onComplete() {
        completed.set(true);
    }

    public boolean isCompleted() {
        return completed.get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy