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

io.github.jzdayz.config.Configuration Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package io.github.jzdayz.config;

import lombok.Data;

@Data
public class Configuration {

    private final static Configuration CONFIGURATION = new Configuration();

    public static Configuration getInstance(){
        return CONFIGURATION;
    }

    private static final String PREFIX = "light.rpc.";
    private static final String CLIENT_CONNECTION_TIMEOUT = PREFIX + "connectionTimeout";

    // ------------------------ client ------------------------
    private int clientConnectionTimeout = getPropertyInt(CLIENT_CONNECTION_TIMEOUT, 3000);


    private int getPropertyInt(String key, int defaultVal) {
        return Integer.parseInt(getPropertyString(key, String.valueOf(defaultVal)));
    }

    private String getPropertyString(String key, String defaultVal) {
        String envVal = System.getenv(transEnv(key));
        return System.getProperty(key, envVal == null ?
                defaultVal : envVal);
    }

    private long getPropertyLong(String key, long defaultVal) {
        return Long.parseLong(getPropertyString(key, String.valueOf(defaultVal)));
    }

    private String transEnv(String property) {
        return property.toUpperCase().replace('.', '_');
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy