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

io.blockfrost.sdk.api.util.ConfigHelper Maven / Gradle / Ivy

There is a newer version: 0.1.3
Show newest version
package io.blockfrost.sdk.api.util;

import static io.blockfrost.sdk.api.util.ConfigConstants.*;

/**
 * Use this to set config parameters
 */
public enum ConfigHelper {
    INSTANCE();

    private int threadCount;
    private int rateLimitForPeriod;
    private int rateLimitRefreshPeriodInSec;
    private int timeoutDurationInMillis;
    private int connectionTimeout;

    ConfigHelper() {
        initEnv();
    }

    private ConfigHelper getInstance() {
        return INSTANCE;
    }

    public void initEnv() {
        //Init threadCount
        threadCount = getPropertyIntValue(BF_API_MAX_THREADS, 10);
        rateLimitForPeriod = getPropertyIntValue(BF_RATE_LIMIT_FOR_PERIOD, 10);
        rateLimitRefreshPeriodInSec = getPropertyIntValue(BF_RATE_LIMIT_REFRESH_PERIOD_IN_SEC, 1);
        timeoutDurationInMillis = getPropertyIntValue(BF_RATE_LIMIT_TIMEOUT_DURATION_IN_MILLIS, 5000);
        connectionTimeout = getPropertyIntValue(BF_CONNECTION_TIMEOUT, 90);
    }

    public int getThreadCount() {
        return threadCount;
    }

    public void setThreadCount(int threadCount) {
        this.threadCount = threadCount;
    }

    public int getRateLimitForPeriod() {
        return rateLimitForPeriod;
    }

    public void setRateLimitForPeriod(int rateLimitForPeriod) {
        this.rateLimitForPeriod = rateLimitForPeriod;
    }

    public int getRateLimitRefreshPeriodInSec() {
        return rateLimitRefreshPeriodInSec;
    }

    public void setRateLimitRefreshPeriodInSec(int rateLimitRefreshPeriodInSec) {
        this.rateLimitRefreshPeriodInSec = rateLimitRefreshPeriodInSec;
    }

    public int getTimeoutDurationInMillis() {
        return timeoutDurationInMillis;
    }

    public void setTimeoutDurationInMillis(int timeoutDurationInMillis) {
        this.timeoutDurationInMillis = timeoutDurationInMillis;
    }

    public int getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    private int getPropertyIntValue(String envName, int defaultValue) {
        String strValue = System.getProperty(envName);
        if (strValue == null || strValue.isEmpty()) {
            strValue = System.getenv(envName);
        }

        if(strValue == null || strValue.isEmpty())
            return defaultValue;

        try {
            return Integer.parseInt(strValue);
        } catch (Exception exp){
            return defaultValue;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy