eu.lucaventuri.fibry.pubsub.PubSubOneActorPerSubscriber Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fibry Show documentation
Show all versions of fibry Show documentation
The first Java Actor System supporting fibers from Project Loom
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