Package com.google.apphosting.api.ApiProxy

Examples of com.google.apphosting.api.ApiProxy.Environment


    assertEquals(a.getMostRecentUpdateMillis(), b.getMostRecentUpdateMillis());
  }

  private SettableFuture<Void> runInNewThread(final TaskStateInfo taskFromQueue)
      throws InterruptedException {
    final Environment environment = ApiProxy.getCurrentEnvironment();
    final SettableFuture<Void> settableFuture = SettableFuture.create();
    Thread t = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
View Full Code Here


    assertNull(sjSettings.getBackend());
    assertEquals("module1", sjSettings.getModule());
    assertEquals("v1", sjSettings.getVersion());

    settings = new MapSettings.Builder(settings).setModule("default").build();
    Environment env = ApiProxy.getCurrentEnvironment();
    Environment mockEnv = EasyMock.createNiceMock(Environment.class);
    EasyMock.expect(mockEnv.getModuleId()).andReturn("default").atLeastOnce();
    EasyMock.expect(mockEnv.getVersionId()).andReturn("2").atLeastOnce();
    EasyMock.expect(mockEnv.getAttributes()).andReturn(env.getAttributes()).anyTimes();
    EasyMock.replay(mockEnv);
    ApiProxy.setEnvironmentForCurrentThread(mockEnv);
    // Test when current module is the same as requested module
    try {
      sjSettings = settings.toShardedJobSettings("job1", key);
View Full Code Here

   *        java.nio.ByteBuffer, long)
   */
  @Override
  public Future<RawGcsCreationToken> continueObjectCreationAsync(final RawGcsCreationToken token,
      final ByteBuffer chunk, long timeoutMillis) {
    final Environment environment = ApiProxy.getCurrentEnvironment();
    return writePool.schedule(new Callable<RawGcsCreationToken>() {
      @Override
      public RawGcsCreationToken call() throws Exception {
        ApiProxy.setEnvironmentForCurrentThread(environment);
        return append(token, chunk);
View Full Code Here

   * @see ModulesService#getCurrentInstanceId()
   */
  private static final String INSTANCE_ID_ENV_ATTRIBUTE = "com.google.appengine.instance.id";

  private Pair<String, String> getCurrentModuleAndVersion() {
    Environment env = ApiProxy.getCurrentEnvironment();
    String majorVersion = Splitter.on('.').split(env.getVersionId()).iterator().next();
    if (majorVersion.contains(":")) {
      List<String> result = Splitter.on(':').splitToList(majorVersion);
      return Pair.of(result.get(0), result.get(1));
    } else {
      return Pair.of("default", majorVersion);
View Full Code Here

   * Some class loader trickery is required to make sure that we get the
   * {@link com.google.appengine.api.LifecycleManager} responsible for this
   * server instance.
   */
  private void triggerLifecycleShutdownHookImpl() {
    Environment prevEnvironment = ApiProxy.getCurrentEnvironment();
    try {
      ClassLoader serverClassLoader = containerService.getAppContext().getClassLoader();

      Class<?> lifeCycleManagerClass =
          Class.forName("com.google.appengine.api.LifecycleManager", true, serverClassLoader);
View Full Code Here

  }

  @Override
  public AppContext getCurrentAppContext() {
    AppContext result = null;
    Environment env = ApiProxy.getCurrentEnvironment();
    if (env != null && env.getVersionId() != null) {
      String moduleName = env.getModuleId();
      result = modules.getModule(moduleName).getMainContainer().getAppContext();
    }
    return result;
  }
View Full Code Here

   * so the caller may add or remove listeners
   *
   * @return The collection of registered RequestEndListeners.
   */
  public static Collection<RequestEndListener> getListeners() {
    Environment environment = ApiProxy.getCurrentEnvironment();
    @SuppressWarnings("unchecked")
    Collection<RequestEndListener> listenerSet = (Collection<RequestEndListener>)
        environment.getAttributes().get(LocalEnvironment.REQUEST_END_LISTENERS);
    return listenerSet;
  }
View Full Code Here

      if (installed()) {
        throw new IllegalStateException("remote API is already installed");
      }
      @SuppressWarnings("unchecked")
      Delegate<Environment> originalDelegate = ApiProxy.getDelegate();
      Environment originalEnv = ApiProxy.getCurrentEnvironment();
      RemoteApiClient installedClient = login(options);
      RemoteApiDelegate remoteApiDelegate;
      if (originalDelegate instanceof ThreadLocalDelegate) {
        ThreadLocalDelegate<Environment> installedDelegate =
            (ThreadLocalDelegate<Environment>) originalDelegate;
        Delegate<Environment> globalDelegate = installedDelegate.getGlobalDelegate();
        remoteApiDelegate = createDelegate(options, installedClient, globalDelegate);
        if (installedDelegate.getDelegateForThread() != null) {
          throw new IllegalStateException("remote API is already installed");
        }
        installedDelegate.setDelegateForThread(remoteApiDelegate);
      } else {
        remoteApiDelegate = createDelegate(options, installedClient, originalDelegate);
        ApiProxy.setDelegate(new ThreadLocalDelegate<Environment>(
            originalDelegate, remoteApiDelegate));
      }
      Environment installedEnv = null;
      String appIdOverrideToRestore = null;
      if (originalEnv == null) {
        installedEnv = createEnv(options, installedClient);
        ApiProxy.setEnvironmentForCurrentThread(installedEnv);
      } else {
View Full Code Here

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filters)
      throws IOException, ServletException {
    Preconditions.checkNotNull(recording, "recording shouldn't be null");
    Environment environment = getCurrentEnvironment();
    Long id = recording.begin(delegate, environment, (HttpServletRequest) request);
    final HttpServletResponse innerResponse = (HttpServletResponse) response;
    final int[] responseCode = {0};

    innerResponse.addHeader(TRACE_HEADER_NAME,
View Full Code Here

   * @return key that is used to store stats for this event.
   */
  public String startCustomRecording(String packageName, String methodName, boolean recordParams,
      Object... params) {
    long preNow = clock.currentTimeMillis();
    Environment environment = ApiProxy.getCurrentEnvironment();

    packageName = Strings.isNullOrEmpty(packageName) ? "custom" : packageName;
    methodName = Strings.isNullOrEmpty(methodName) ? "method" : methodName;

    RecordingData recordingData = new RecordingData();
    IndividualRpcStatsProto.Builder stats = IndividualRpcStatsProto.newBuilder();
    stats.setServiceCallName(packageName + "." + methodName);
    if (environment.getAttributes().containsKey(Recorder.CURRENT_NAMESPACE_KEY)) {
      stats.setNamespace(
            (String) environment.getAttributes().get(Recorder.CURRENT_NAMESPACE_KEY));
    }

    if (recordParams) {
      stats.setRequestDataSummary(
          settings.getPayloadRenderer().renderPayload(packageName, methodName, true, params));
    }

    Recorder.createStackTrace(2, stats, settings.getMaxLinesOfStackTrace());
    stats.setWasSuccessful(false);
    stats.setStartOffsetMilliseconds(clock.currentTimeMillis());
    recordingData.setStats(stats);
    if (!environment.getAttributes().containsKey(CUSTOM_RECORDING_KEY)) {
      environment.getAttributes().put(CUSTOM_RECORDING_KEY, Maps.newLinkedHashMap());
    }

    @SuppressWarnings("unchecked")
    Map<String, RecordingData> customRecordings =
        (Map<String, RecordingData>) environment.getAttributes().get(CUSTOM_RECORDING_KEY);
    String key = generateKey(stats.getServiceCallName(), preNow);
    recordingData.addOverhead(clock.currentTimeMillis() - preNow);
    customRecordings.put(key, recordingData);
    return key;
  }
View Full Code Here

TOP

Related Classes of com.google.apphosting.api.ApiProxy.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.