mirror of
https://github.com/google/nomulus.git
synced 2025-05-12 22:38:16 +02:00
Use standard java thread factory instead of the AppEngine flavor
With Java 8 in GAE standard environment, we can now use standard java thread factory to run the metric reporter in the background in daemon mode, which would not interfere with basic scaling idle timeout as App Engine thread would. Because the thread is not created by ThreadManager, no App Engine APIs can be called from it. We therefore use GoogleCredential instead of AppIdentityCredential as HttpRequestInitializer, and NetHttpTransport instead of UlrFetchTransport as HttpTransport. MetricReporter is lazy injected because it depends on jsonCredential retrieved from CloudKms, which is not available in a test environment, causing FrontendServletTest and BackendServletTest to fail. Some minor re-formatting with google-java-format on edited files. Lastly removed moe comments in import statement, which makes the linter unhappy. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=172896227
This commit is contained in:
parent
b01fa6b4c9
commit
c702b4486c
8 changed files with 151 additions and 118 deletions
|
@ -15,7 +15,7 @@
|
|||
package google.registry.module.frontend;
|
||||
|
||||
import com.google.appengine.api.LifecycleManager;
|
||||
import com.google.appengine.api.LifecycleManager.ShutdownHook;
|
||||
import dagger.Lazy;
|
||||
import google.registry.monitoring.metrics.MetricReporter;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import java.io.IOException;
|
||||
|
@ -32,7 +32,7 @@ public final class FrontendServlet extends HttpServlet {
|
|||
|
||||
private static final FrontendComponent component = DaggerFrontendComponent.create();
|
||||
private static final FrontendRequestHandler requestHandler = component.requestHandler();
|
||||
private static final MetricReporter metricReporter = component.metricReporter();
|
||||
private static final Lazy<MetricReporter> metricReporter = component.metricReporter();
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +40,7 @@ public final class FrontendServlet extends HttpServlet {
|
|||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
try {
|
||||
metricReporter.startAsync().awaitRunning(10, TimeUnit.SECONDS);
|
||||
metricReporter.get().startAsync().awaitRunning(10, TimeUnit.SECONDS);
|
||||
logger.info("Started up MetricReporter");
|
||||
} catch (TimeoutException timeoutException) {
|
||||
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
||||
|
@ -48,15 +48,12 @@ public final class FrontendServlet extends HttpServlet {
|
|||
|
||||
LifecycleManager.getInstance()
|
||||
.setShutdownHook(
|
||||
new ShutdownHook() {
|
||||
@Override
|
||||
public void shutdown() {
|
||||
try {
|
||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||
logger.info("Shut down MetricReporter");
|
||||
} catch (TimeoutException timeoutException) {
|
||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
metricReporter.get().stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||
logger.info("Shut down MetricReporter");
|
||||
} catch (TimeoutException timeoutException) {
|
||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue