
io.mstream.trader.commons.config.ConfigClient Maven / Gradle / Ivy
package io.mstream.trader.commons.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.inject.Inject;
import java.util.Optional;
public class ConfigClient {
private static final Logger LOGGER = LogManager.getLogger();
private final CuratorFrameworkSupplier curatorSupplier;
private final ObjectMapper mapper;
@Inject
public ConfigClient(
CuratorFrameworkSupplier curatorSupplier,
ObjectMapper mapper
) {
this.curatorSupplier = curatorSupplier;
this.mapper = mapper;
}
public Optional read(Class configType) {
try {
byte[] configBytes = curatorSupplier.get().getData().forPath("/");
LOGGER.debug(
"fetched config: {}",
() -> new String(configBytes)
);
T config = mapper.readValue(
configBytes,
configType
);
return Optional.of(config);
} catch (Exception e) {
LOGGER.error("could not read the config", e);
return Optional.empty();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy