@Override public RawGcsCreationToken call() throws Exception { ApiProxy.setEnvironmentForCurrentThread(environment); return append(token, chunk); } }, 50, TimeUnit.MILLISECONDS);
@Override public void flushLogs(Environment paramE) { parent.flushLogs(paramE); }
@Override public List<Thread> getRequestThreads(Environment paramE) { return parent.getRequestThreads(paramE); } }
private static Queue getQueue(String queueName) { if (queueName == null) { Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes(); queueName = (String) attributes.get(TaskHandler.TASK_QUEUE_NAME_HEADER); } return queueName == null ? QueueFactory.getDefaultQueue() : QueueFactory.getQueue(queueName); }
public String getApp() { return ApiProxy.getCurrentEnvironment().getAppId(); }
@Override public void initOrSkip() { // Create a fake development environment if not run in the Google SDK if (ApiProxy.getCurrentEnvironment() == null) { ApiProxy.setEnvironmentForCurrentThread(this); } }
/** * @return {@code true} if there is time and space left to continue adding more snapshots, * or if we should stop here. */ public boolean timeAndSpaceRemaining() { // Do we have enough time left in this request to do any more work? long timeRemaining = ApiProxy.getCurrentEnvironment().getRemainingMillis(); if(timeRemaining < BUFFER_MS) { return false; } if(estimatedSizeInBytes > MAX_RESPONSE_SIZE) { return false; } return true; }
import com.google.apphosting.api.ApiProxy; ... final ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); final Map<String, Object> attributes = env.getAttributes(); final String hostAndPort = (String) attributes.get("com.google.appengine.runtime.default_version_hostname"); final String url = "http://" + hostAndPort + "/";
private static boolean cloudTraceContextEquals(CloudTraceContext obj1, CloudTraceContext obj2) { return Arrays.equals(obj1.getTraceId(), obj2.getTraceId()) && obj1.getSpanId() == obj2.getSpanId() && obj1.getTraceMask() == obj2.getTraceMask(); } }
@Override public void log(Environment arg0, LogRecord arg1) { this.parent.log(arg0, arg1); }
@Override public byte[] makeSyncCall(Environment arg0, String arg1, String arg2, byte[] arg3) throws ApiProxyException { this.checkPendingFutures(); return this.parent.makeSyncCall(arg0, arg1, arg2, arg3); }
@Override public Future<byte[]> makeAsyncCall(Environment arg0, String arg1, String arg2, byte[] arg3, ApiConfig arg4) { this.checkPendingFutures(); return this.parent.makeAsyncCall(arg0, arg1, arg2, arg3, arg4); }
public static String getCurrentRequestId() { return (String) ApiProxy.getCurrentEnvironment().getAttributes().get("com.google.appengine.runtime.request_log_id"); } }
@Test public void testGetAppId() { String expectedAppId = getExpectedAppId("testGetAppId"); String appId = ApiProxy.getCurrentEnvironment().getAppId(); // AppIds in the US are prefixed with s~ and in Europe e~ so just match the end. String errMsg = "The appId should end with " + expectedAppId + ", but was " + appId; Assert.assertTrue(errMsg, appId.endsWith(expectedAppId)); }
ApiProxy.Environment proxyEnvironment = ApiProxy.getCurrentEnvironment(); Map<String, Object> attributes = proxyEnvironment.getAttributes(); String hostname = (String) attributes.get(LocalEnvironment.DEFAULT_VERSION_HOSTNAME);
@Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { ApiProxy.setEnvironmentForCurrentThread(environment); super.handle(target, request, response, dispatch); }
protected static URL getUrl(String path) throws MalformedURLException { ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); Object localhost = env.getAttributes().get("com.google.appengine.runtime.default_version_hostname"); return new URL("http://" + localhost + "/" + path); }
@Override protected void doStop() throws Exception { ApiProxy.setEnvironmentForCurrentThread(environment); helper.tearDown(); environment = null; super.doStop(); }
@Test public void testInstanceId() { ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); String instanceId = (String) env.getAttributes().get("com.google.appengine.instance.id"); String errMsg = "The instance id should not be null"; Assert.assertNotNull(errMsg, instanceId); }
@Test public void testRequestId() { ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); String requestId = (String) env.getAttributes().get("com.google.appengine.runtime.request_log_id"); String errMsg = "The request id should not be null"; Assert.assertNotNull(errMsg, requestId); } }