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

eu.lucaventuri.fibry.Spawner Maven / Gradle / Ivy

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

import eu.lucaventuri.common.CountingExitable;
import eu.lucaventuri.common.Exitable;

import java.util.function.Consumer;
import java.util.function.Function;

/** Class able to create new actors with a predefined logic */
class Spawner extends CountingExitable {
    private final Function logic;
    private final ActorSystem.NamedStateActorCreator creator;
    private Consumer finalizer = state -> addFinished();

    Spawner(ActorSystem.NamedStateActorCreator creator,  Function logic) {
        this.logic = logic;
        this.creator=creator;
    }

    public Actor spawn() {
        addCreated();

        return creator.newActorWithReturn(logic);
    }

    public Consumer finalizer() {
        return finalizer;
    }
}