remove dependency to Guava

This commit is contained in:
2019-09-01 15:44:36 +02:00
parent 8579974051
commit 0e9e2cd53a
6 changed files with 35 additions and 36 deletions

View File

@@ -3,6 +3,5 @@ dependencies {
compile project(':performanceDb')
compile lib_primitive_collections
compile lib_jackson_databind
compile lib_guava
}

View File

@@ -8,8 +8,7 @@ import java.util.List;
import java.util.regex.Pattern;
import org.lucares.pdb.api.DateTimeRange;
import com.google.common.base.Preconditions;
import org.lucares.utils.Preconditions;
public class PlotSettings {
@@ -120,7 +119,7 @@ public class PlotSettings {
public DateTimeRange dateRange() {
final String[] startEnd = dateRangeAsString.split(Pattern.quote(" - "));
Preconditions.checkArgument(startEnd.length == 2, "invalid date range");
Preconditions.checkEqual(startEnd, 2, "invalid date range: ''{0}''", dateRangeAsString);
final OffsetDateTime startDate = LocalDateTime.parse(startEnd[0], DATE_FORMAT).atOffset(ZoneOffset.UTC);
final OffsetDateTime endDate = LocalDateTime.parse(startEnd[1], DATE_FORMAT).atOffset(ZoneOffset.UTC);

View File

@@ -7,6 +7,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ProcessBuilder.Redirect;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
@@ -15,8 +16,6 @@ import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.io.Files;
public class Gnuplot {
private static final Logger LOGGER = LoggerFactory.getLogger(Gnuplot.class);
@@ -25,8 +24,9 @@ public class Gnuplot {
private static final String ENV_GNUPLOT_HOME = "GNUPLOT_HOME";
private static final String PROPERTY_GNUPLOT_HOME = "gnuplot.home";
private final Path tmpDirectory;
// This would be bad style if this code was executed in a web-container, because it would cause a memory leak.
// This would be bad style if this code was executed in a web-container, because
// it would cause a memory leak.
// But this code is only (and will only) be executed as standalone application.
private static final ExecutorService POOL = Executors.newCachedThreadPool();
@@ -43,15 +43,15 @@ public class Gnuplot {
LOGGER.debug(gnuplotFileContent);
final File gnuplotFile = File.createTempFile("gnuplot", ".dem", tmpDirectory.toFile());
Files.asCharSink(gnuplotFile, StandardCharsets.UTF_8).write(gnuplotFileContent);
Files.writeString(gnuplotFile.toPath(), gnuplotFileContent, StandardCharsets.UTF_8);
final long start = System.nanoTime();
try {
final ProcessBuilder processBuilder = new ProcessBuilder(gnuplotBinary(), gnuplotFile.getAbsolutePath())//
.redirectOutput(Redirect.PIPE)//
.redirectError(Redirect.PIPE);
.redirectOutput(Redirect.PIPE)//
.redirectError(Redirect.PIPE);
final Process process = processBuilder.start();
logOutput("stderr", process.getErrorStream());
logOutput("stdout", process.getInputStream());
@@ -69,18 +69,17 @@ public class Gnuplot {
METRICS_LOGGER.debug("gnuplot: {}ms", (System.nanoTime() - start) / 1_000_000.0);
}
private void logOutput(final String humanReadableType, final InputStream stream) throws IOException {
POOL.submit(()->{
try{
private void logOutput(final String humanReadableType, final InputStream stream) throws IOException {
POOL.submit(() -> {
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
String line;
while(( line = reader.readLine()) != null){
while ((line = reader.readLine()) != null) {
LOGGER.info("gnuplot {}: {}", humanReadableType, line);
}
}
catch (Exception e){
LOGGER.warn("Exception while reading "+ humanReadableType+ " of gnuplot command", e);
} catch (final Exception e) {
LOGGER.warn("Exception while reading " + humanReadableType + " of gnuplot command", e);
}
});
}