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

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

package eu.lucaventuri.fibry;

import java.util.ArrayList;
import java.util.List;

/** Strategy used to create the actors */
public enum CreationStrategy {
    /** One thread per actor */
    THREAD {
        @Override
        public  BaseActor start(BaseActor actor) {
            new Thread(actor::processMessages).start();

            return actor;
        }
    },
    /** One fiber per actor */
    FIBER {
        @Override
        public  BaseActor start(BaseActor actor) {
            ActorUtils.runAsFiber(actor::processMessages);

            return actor;
        }
    },
    /** If fibers are available, the it uses FIBER else it uses THREAD */
    AUTO {
        @Override
        public  BaseActor start(BaseActor actor) {
            return ActorUtils.areFibersAvailable() ? FIBER.start(actor) : THREAD.start(actor);
        }
    };

    /** Starts an actor */
    public abstract  BaseActor start(BaseActor actor);

    /** Return the strategies that are available */
    public Iterable available() {
        List list = new ArrayList<>();

        list.add(THREAD);
        if (ActorUtils.areFibersAvailable())
            list.add(FIBER);

        return list;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy