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

eu.lucaventuri.fibry.pubsub.PubSubOneActorPerSubscriber Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package eu.lucaventuri.fibry.pubsub;

import eu.lucaventuri.fibry.Actor;
import eu.lucaventuri.fibry.ActorSystem;
import eu.lucaventuri.fibry.Stereotypes;

import java.util.function.Consumer;

/**
 * One dedicated actor for each subscriber, plus one actor per topic. In this way, subscribers cannot block each other.
 * This is overkill if your consumer is already an actor
 */
public class PubSubOneActorPerSubscriber extends PubSubOneActorPerTopic {
    @Override
    public Subscription subscribe(String topic, Consumer consumer) {
        Actor subscriberActor = ActorSystem.anonymous().newActor(consumer);
        Subscription subscription = super.subscribe(topic, subscriberActor);

        return () -> {
            subscription.cancel();
            subscriberActor.askExit();
            subscriberActor.sendPoisonPill();
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy