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

net.minestom.server.thread.ThreadProvider Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.thread;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.atomic.AtomicInteger;

@FunctionalInterface
@ApiStatus.Experimental
public interface ThreadProvider {
    static  @NotNull ThreadProvider counter() {
        return new ThreadProvider<>() {
            private final AtomicInteger counter = new AtomicInteger();

            @Override
            public int findThread(@NotNull T partition) {
                return counter.getAndIncrement();
            }
        };
    }

    /**
     * Performs a server tick for all chunks based on their linked thread.
     *
     * @param partition the partition
     */
    int findThread(@NotNull T partition);

    /**
     * Defines how often chunks thread should be updated.
     *
     * @return the refresh type
     */
    default @NotNull RefreshType refreshType() {
        return RefreshType.NEVER;
    }

    /**
     * Defines how often chunks thread should be refreshed.
     */
    enum RefreshType {
        /**
         * Thread never change after being defined once.
         * 

* Means that {@link #findThread(Object)} will only be called once for each partition. */ NEVER, /** * Thread is updated as often as possible. *

* Means that {@link #findThread(Object)} may be called multiple time for each partition. */ ALWAYS } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy