package com.atlassian.stash.internal.concurrent;

import com.atlassian.bitbucket.concurrent.BucketProcessor;
import com.atlassian.bitbucket.concurrent.BucketedExecutor;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.concurrent.TimeUnit;

/**
 * Internal extensions to the {@link BucketedExecutor} API.
 *
 * @param <T> the request / task type
 * @since 3.3
 */
public interface InternalBucketedExecutor<T extends Serializable> extends BucketedExecutor<T> {

    /**
     * Schedules a {@link BucketProcessor BucketProcessor} execution for the task
     * bucket {@code bucketId} on the local {@code ExecutorService}.
     *
     * @param bucketId the bucket identifier
     * @param delay    the time to wait before calling the bucket processor
     * @param timeUnit the time unit of {@code delay}
     */
    void scheduleLocally(@Nonnull String bucketId, long delay, @Nonnull TimeUnit timeUnit);

    /**
     * Informs the executor that the number of nodes in the cluster has been updated, allowing the executor to,
     * for example, resize its thread pool.
     *
     * @param nodeCount the current node count for the cluster
     */
    void updateClusterSize(int nodeCount);
}
