io.deepsense.neptune.clientlibrary.services.serverconfigurationprovider.ServerConfigurationProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary.services.serverconfigurationprovider;
import com.google.common.base.Preconditions;
import io.deepsense.neptune.apiclient.ApiException;
import io.deepsense.neptune.apiclient.model.ConfigInfo;
import io.deepsense.neptune.clientlibrary.config.internal.InternalConfiguration;
import io.deepsense.neptune.clientlibrary.exceptions.common.NeptuneRuntimeException;
import io.deepsense.neptune.clientlibrary.services.apiservice.ApiService;
import java.util.Optional;
public class ServerConfigurationProvider {
private final InternalConfiguration internalConfiguration;
private final ApiService apiService;
private ConfigInfo configInfo;
public ServerConfigurationProvider(InternalConfiguration internalConfiguration, ApiService apiService) {
this.internalConfiguration = Preconditions.checkNotNull(internalConfiguration);
this.apiService = Preconditions.checkNotNull(apiService);
}
public ConfigInfo getConfigInfo() {
if (isConfigInfoReady()) {
return configInfo;
} else {
try {
configInfo = apiService.getConfigInfo();
return configInfo;
} catch (ApiException exc) {
throw new NeptuneRuntimeException("Failed to get the server internalConfiguration!");
}
}
}
public long getMaxChannelValueSize() {
requireConfigInfo();
double maxBatchSizeAsFractionOfRequestSize =
internalConfiguration.getChannelValueBufferConfiguration().getMaxBatchSizeAsFractionOfRequestSize();
long maxFormContentSize = configInfo.getMaxFormContentSize();
return (long) (maxBatchSizeAsFractionOfRequestSize * (double) maxFormContentSize);
}
private boolean isConfigInfoReady() {
return Optional.ofNullable(configInfo).isPresent();
}
private void requireConfigInfo() {
if (!isConfigInfoReady()) {
getConfigInfo();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy