package com.atlassian.bitbucket.internal.importer.repository;

import com.atlassian.bitbucket.server.ApplicationPropertiesService;

import javax.annotation.Nonnull;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static com.atlassian.bitbucket.internal.importer.ImporterConstants.PROPERTY_MAX_IMPORT_REPOSITORY_THREAD;
import static com.atlassian.bitbucket.internal.importer.ImporterConstants.PROPERTY_MAX_IMPORT_REPOSITORY_THREAD_DEFAULT;

public class ExecutorFactory {

    private final int maxImportThread;

    public ExecutorFactory(@Nonnull ApplicationPropertiesService propertiesService) {
        maxImportThread = propertiesService.getPluginProperty(PROPERTY_MAX_IMPORT_REPOSITORY_THREAD,
                PROPERTY_MAX_IMPORT_REPOSITORY_THREAD_DEFAULT);
    }

    @Nonnull
    public ExecutorService create() {
        return Executors.newFixedThreadPool(maxImportThread);
    }
}
