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

io.polyapi.client.internal.model.PolyContextConfiguration Maven / Gradle / Ivy

There is a newer version: 0.15.3
Show newest version
package io.polyapi.client.internal.model;

import java.util.Optional;
import java.util.Properties;
import java.util.function.Function;

import static java.lang.String.format;
import static java.util.function.Function.identity;

public class PolyContextConfiguration {
    private static final Long DEFAULT_TIMEOUT_VALUES = 30000L;

    private final Properties properties;

    public PolyContextConfiguration(Properties properties) {
        this.properties = properties;
    }

    public String getUrl() {
      return format("%s:%s", getHost(), getPort());
    }

    public String getHost() {
        return getProperty("io.polyapi.host");
    }

    public Integer getPort() {
        return getProperty("io.polyapi.port", Integer::valueOf, 443);
    }

    public String getApiKey() {
        return getProperty("io.polyapi.api.key");
    }

    public Long getConnectionTimeoutMillis() {
        return getProperty("io.polyapi.http.timeout.connection", Long::valueOf, DEFAULT_TIMEOUT_VALUES);
    }

    public Long getReadTimeoutMillis() {
        return getProperty("io.polyapi.http.timeout.read", Long::valueOf, DEFAULT_TIMEOUT_VALUES);
    }

    public Long getWriteTimeoutMillis() {
        return getProperty("io.polyapi.http.timeout.write", Long::valueOf, DEFAULT_TIMEOUT_VALUES);
    }

    public String getClientId() {
        return getProperty("io.polyapi.client.id");
    }

    private String getProperty(String key) {
        return this.getProperty(key, identity(), null);
    }

    private  T getProperty(String key, Function conversionFunction, T defaultValue) {
        return Optional.ofNullable(properties.getProperty(key))
                .map(conversionFunction)
                .orElse(defaultValue);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy