Skip to content
Snippets Groups Projects
Commit fad7ee19 authored by Powers, Peter M.'s avatar Powers, Peter M.
Browse files

servlet cleaning

parent ed004497
No related branches found
No related tags found
2 merge requests!577Production Release | nshmp-haz,!573Dependency updates
...@@ -27,7 +27,6 @@ import gov.usgs.earthquake.nshmp.www.meta.Status; ...@@ -27,7 +27,6 @@ import gov.usgs.earthquake.nshmp.www.meta.Status;
import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.Key; import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.Key;
import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.ServiceQueryData; import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.ServiceQueryData;
import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.ServiceRequestData; import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.ServiceRequestData;
import io.micronaut.http.HttpRequest; import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpResponse;
...@@ -82,7 +81,6 @@ public final class RateService { ...@@ -82,7 +81,6 @@ public final class RateService {
var service = query.service; var service = query.service;
try { try {
var timer = ServletUtil.timer();
if (query.isNull()) { if (query.isNull()) {
return handleDoGetUsage(request, service); return handleDoGetUsage(request, service);
......
...@@ -3,8 +3,6 @@ package gov.usgs.earthquake.nshmp.www.services; ...@@ -3,8 +3,6 @@ package gov.usgs.earthquake.nshmp.www.services;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -16,7 +14,6 @@ import gov.usgs.earthquake.nshmp.model.HazardModel; ...@@ -16,7 +14,6 @@ import gov.usgs.earthquake.nshmp.model.HazardModel;
import gov.usgs.earthquake.nshmp.www.Response; import gov.usgs.earthquake.nshmp.www.Response;
import gov.usgs.earthquake.nshmp.www.WsUtils; import gov.usgs.earthquake.nshmp.www.WsUtils;
import gov.usgs.earthquake.nshmp.www.meta.Status; import gov.usgs.earthquake.nshmp.www.meta.Status;
import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpResponse;
public class ServicesUtil { public class ServicesUtil {
...@@ -36,25 +33,12 @@ public class ServicesUtil { ...@@ -36,25 +33,12 @@ public class ServicesUtil {
static Hazard calcHazard( static Hazard calcHazard(
Function<HazardModel, CalcConfig> configFunction, Function<HazardModel, CalcConfig> configFunction,
Function<CalcConfig, Site> siteFunction) throws InterruptedException, ExecutionException { Function<CalcConfig, Site> siteFunction) throws InterruptedException, ExecutionException {
// TODO reduce for singleton model
var futuresList = Stream.of(ServletUtil.model()) HazardModel model = ServletUtil.model();
.map(model -> { CalcConfig config = configFunction.apply(model);
var config = configFunction.apply(model); Site site = siteFunction.apply(config);
var site = siteFunction.apply(config); CompletableFuture<Hazard> future = calcHazard(model, config, site);
return calcHazard(model, config, site); return future.get();
})
.collect(Collectors.toList());
var hazardsFuture = CompletableFuture
.allOf(futuresList.toArray(new CompletableFuture[futuresList.size()]))
.thenApply(v -> {
return futuresList.stream()
.map(future -> future.join())
.collect(Collectors.toList());
});
var hazards = hazardsFuture.get().toArray(new Hazard[] {});
return Hazard.merge(hazards);
} }
@Deprecated @Deprecated
...@@ -129,11 +113,10 @@ public class ServicesUtil { ...@@ -129,11 +113,10 @@ public class ServicesUtil {
HazardModel model, HazardModel model,
CalcConfig config, CalcConfig config,
Site site) { Site site) {
return CompletableFuture
.supplyAsync( return CompletableFuture.supplyAsync(
() -> HazardCalcs.hazard( () -> HazardCalcs.hazard(model, config, site, ServletUtil.CALC_EXECUTOR),
model, config, site, ServletUtil.CALC_EXECUTOR), ServletUtil.TASK_EXECUTOR);
ServletUtil.TASK_EXECUTOR);
} }
} }
...@@ -10,14 +10,12 @@ import java.nio.file.FileSystemNotFoundException; ...@@ -10,14 +10,12 @@ import java.nio.file.FileSystemNotFoundException;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javax.inject.Singleton; import javax.inject.Singleton;
import com.google.common.base.Stopwatch;
import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import com.google.gson.Gson; import com.google.gson.Gson;
...@@ -33,7 +31,6 @@ import gov.usgs.earthquake.nshmp.gmm.Imt; ...@@ -33,7 +31,6 @@ import gov.usgs.earthquake.nshmp.gmm.Imt;
import gov.usgs.earthquake.nshmp.model.HazardModel; import gov.usgs.earthquake.nshmp.model.HazardModel;
import gov.usgs.earthquake.nshmp.www.WsUtils; import gov.usgs.earthquake.nshmp.www.WsUtils;
import gov.usgs.earthquake.nshmp.www.meta.MetaUtil; import gov.usgs.earthquake.nshmp.www.meta.MetaUtil;
import io.micronaut.context.annotation.Value; import io.micronaut.context.annotation.Value;
import io.micronaut.context.event.ShutdownEvent; import io.micronaut.context.event.ShutdownEvent;
import io.micronaut.context.event.StartupEvent; import io.micronaut.context.event.StartupEvent;
...@@ -48,24 +45,15 @@ import io.micronaut.runtime.event.annotation.EventListener; ...@@ -48,24 +45,15 @@ import io.micronaut.runtime.event.annotation.EventListener;
public class ServletUtil { public class ServletUtil {
public static final Gson GSON; public static final Gson GSON;
public static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern(
"yyyy-MM-dd'T'HH:mm:ssXXX");
static final ListeningExecutorService CALC_EXECUTOR; static final ListeningExecutorService CALC_EXECUTOR;
static final ExecutorService TASK_EXECUTOR; static final ExecutorService TASK_EXECUTOR;
static final int THREAD_COUNT; static final int THREAD_COUNT;
/* Stateful flag to reject requests while a result is pending. */
static boolean uhtBusy = false;
static long hitCount = 0;
static long missCount = 0;
@Value("${nshmp-haz.model-path}") @Value("${nshmp-haz.model-path}")
private Path modelPath; private Path modelPath;
// private static List<HazardModel> HAZARD_MODELS = new ArrayList<>();
private static HazardModel HAZARD_MODEL; private static HazardModel HAZARD_MODEL;
static { static {
...@@ -143,33 +131,6 @@ public class ServletUtil { ...@@ -143,33 +131,6 @@ public class ServletUtil {
} }
} }
public static Timer timer() {
return new Timer();
}
/*
* Simple timer object. The servlet timer just runs. The calculation timer can
* be started later.
*/
@Deprecated
public static final class Timer {
Stopwatch servlet = Stopwatch.createStarted();
Stopwatch calc = Stopwatch.createUnstarted();
public Timer start() {
calc.start();
return this;
}
public String servletTime() {
return servlet.toString();
}
public String calcTime() {
return calc.toString();
}
}
private static class PathConverter implements JsonSerializer<Path> { private static class PathConverter implements JsonSerializer<Path> {
@Override @Override
public JsonElement serialize( public JsonElement serialize(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment