in runtime/impl/src/main/java/com/google/apphosting/runtime/JavaRuntimeFactory.java [52:202]
public JavaRuntime getStartedRuntime(NullSandboxPlugin sandboxPlugin, String[] args) {
JavaRuntimeParams params = JavaRuntimeParams.parseArgs(args);
List<String> unknownParams = params.getUnknownParams();
if (!unknownParams.isEmpty()) {
logger.atWarning().log("Unknown command line arguments: %s", unknownParams);
}
RuntimeLogSink logSink = new RuntimeLogSink(params.getMaxRuntimeLogPerRequest());
logSink.addHandlerToRootLogger();
maybeConfigureProfiler(params);
if (params.getLogJettyExceptionsToAppLogs()) {
// This system property is checked by JettyLogger, which is
// instantiated via reflection by Jetty and therefore we cannot
// pass options into it directly.
//
// TODO: This logic should really move down to
// JettyServletAdapter.
System.setProperty("appengine.jetty.also_log_to_apiproxy", "true");
}
if (params.getUrlfetchDeriveResponseMessage()) {
// This system property is checked by URLFetch's Connection class, which
// is directly instantiated by the Java API and cannot take constructor
// arguments.
System.setProperty("appengine.urlfetch.deriveResponseMessage", "true");
}
if (params.getMailSupportExtendedAttachmentEncodings()) {
// This system property is checked by GMTransport, which is directly
// registered with JavaMail and cannot take additional constructor arguments.
System.setProperty("appengine.mail.supportExtendedAttachmentEncodings", "true");
}
if (params.getForceReadaheadOnCloudsqlSocket()) {
System.setProperty("appengine.jdbc.forceReadaheadOnCloudsqlSocket", "true");
}
if (params.getMailFilenamePreventsInlining()) {
// This system property is checked by GMTransport, which is directly
// registered with JavaMail and cannot take additional constructor arguments.
System.setProperty("appengine.mail.filenamePreventsInlining", "true");
}
ServletEngineAdapter servletEngine = createServletEngine(params);
ApiDeadlineOracle deadlineOracle =
new ApiDeadlineOracle.Builder()
.initDeadlineMap(
params.getApiCallDeadline(),
params.getApiCallDeadlineMap(),
params.getMaxApiCallDeadline(),
params.getMaxApiCallDeadlineMap())
.initOfflineDeadlineMap(
params.getOfflineApiCallDeadline(),
params.getOfflineApiCallDeadlineMap(),
params.getMaxOfflineApiCallDeadline(),
params.getMaxOfflineApiCallDeadlineMap())
.build();
AnyRpcPlugin rpcPlugin = loadRpcPlugin(params);
rpcPlugin.initialize(params.getPort());
ApiHostClientFactory apiHostFactory = new ApiHostClientFactory();
BackgroundRequestCoordinator coordinator = new BackgroundRequestCoordinator();
ApiProxyImpl apiProxyImpl =
ApiProxyImpl.builder()
.setApiHost(
apiHostFactory.newAPIHost(
params.getTrustedHost(),
OptionalInt.of(params.getCloneMaxOutstandingApiRpcs())))
.setDeadlineOracle(deadlineOracle)
.setExternalDatacenterName(params.getExternalDatacenterName())
.setByteCountBeforeFlushing(params.getByteCountBeforeFlushing())
.setMaxLogLineSize(params.getMaxLogLineSize())
.setMaxLogFlushTime(Duration.ofSeconds(params.getMaxLogFlushSeconds()))
.setCoordinator(coordinator)
.setCloudSqlJdbcConnectivityEnabled(params.getEnableGaeCloudSqlJdbcConnectivity())
.setDisableApiCallLogging(params.getDisableApiCallLogging())
.build();
RequestManager.Builder requestManagerBuilder =
RequestManager.builder()
.setSoftDeadlineDelay(params.getJavaSoftDeadlineMs())
.setHardDeadlineDelay(params.getJavaHardDeadlineMs())
.setDisableDeadlineTimers(params.getUseCloneControllerForDeadlines())
.setRuntimeLogSink(Optional.of(logSink))
.setApiProxyImpl(apiProxyImpl)
.setMaxOutstandingApiRpcs(params.getCloneMaxOutstandingApiRpcs())
.setThreadStopTerminatesClone(params.getThreadStopTerminatesClone())
.setInterruptFirstOnSoftDeadline(params.getInterruptThreadsFirstOnSoftDeadline())
.setCyclesPerSecond(params.getCyclesPerSecond())
.setWaitForDaemonRequestThreads(params.getWaitForDaemonRequestThreads());
RequestManager requestManager = makeRequestManager(requestManagerBuilder);
apiProxyImpl.setRequestManager(requestManager);
ApplicationEnvironment.RuntimeConfiguration configuration =
ApplicationEnvironment.RuntimeConfiguration.builder()
.setCloudSqlJdbcConnectivityEnabled(params.getEnableGaeCloudSqlJdbcConnectivity())
.setUseGoogleConnectorJ(params.getDefaultUseGoogleConnectorj())
.build();
JavaRuntime.Builder runtimeBuilder =
JavaRuntime.builder()
.setServletEngine(servletEngine)
.setSandboxPlugin(sandboxPlugin)
.setRpcPlugin(rpcPlugin)
.setSharedDirectory(new File(params.getApplicationRoot()))
.setRequestManager(requestManager)
.setRuntimeVersion("Google App Engine/" + params.getAppengineReleaseName())
.setConfiguration(configuration)
.setDeadlineOracle(deadlineOracle)
.setCoordinator(coordinator)
.setCompressResponse(params.getRuntimeHttpCompression())
.setEnableHotspotPerformanceMetrics(params.getEnableHotspotPerformanceMetrics())
.setPollForNetwork(params.getPollForNetwork())
.setDefaultToNativeUrlStreamHandler(params.getDefaultToNativeUrlStreamHandler())
.setForceUrlfetchUrlStreamHandler(params.getForceUrlfetchUrlStreamHandler())
.setIgnoreDaemonThreads(!params.getWaitForDaemonRequestThreads())
.setUseEnvVarsFromAppInfo(params.getUseEnvVarsFromAppInfo())
.setFixedApplicationPath(params.getFixedApplicationPath())
.setRedirectStdoutStderr(!params.getUseJettyHttpProxy())
.setLogJsonToFile(params.getLogJsonToVarLog());
JavaRuntime runtime = makeRuntime(runtimeBuilder);
ApiProxy.setDelegate(apiProxyImpl);
ServletEngineAdapter.Config runtimeOptions =
ServletEngineAdapter.Config.builder()
.setUseJettyHttpProxy(params.getUseJettyHttpProxy())
.setApplicationRoot(params.getApplicationRoot())
.setFixedApplicationPath(params.getFixedApplicationPath())
.setJettyHttpAddress(HostAndPort.fromParts("0.0.0.0", params.getJettyHttpPort()))
.setJettyRequestHeaderSize(params.getJettyRequestHeaderSize())
.setJettyResponseHeaderSize(params.getJettyResponseHeaderSize())
.setEvaluationRuntimeServerInterface(runtime)
.build();
try {
runtime.start(runtimeOptions);
} catch (Exception e) {
try {
runtime.stop();
} catch (Throwable th) {
// Swallow this exception -- the other one is what matters.
}
throw new RuntimeException("Could not start server", e);
}
return runtime;
}