App Engine Java SDK version 1.9.14
[gae.git] / java / src / main / com / google / appengine / tools / remoteapi / RemoteApiDelegate.java
bloba3f0797e256972bc8ae7634673c046646f2cc8a3
1 // Copyright 2010 Google Inc. All Rights Reserved.
3 package com.google.appengine.tools.remoteapi;
5 import com.google.apphosting.api.ApiProxy.Delegate;
6 import com.google.apphosting.api.ApiProxy.Environment;
8 /**
9 * Handles App Engine API calls by making HTTP requests to a remote server.
10 * The exact mechanism by which the requests are made is an implementation
11 * detail of subclasses. Users of this class are expected to call
12 * {@link #shutdown()} when they are done with an instance.
14 * <p>This class and its subclasses are thread-safe.
17 abstract class RemoteApiDelegate implements Delegate<Environment> {
18 private final RemoteRpc remoteRpc;
19 private final RemoteDatastore remoteDatastore;
21 /**
22 * Factory method.
24 public static RemoteApiDelegate newInstance(RemoteRpc remoteRpc, RemoteApiOptions options, Delegate<Environment> containerDelegate) {
25 return containerDelegate != null ?
26 new HostedRemoteApiDelegate(remoteRpc, options, containerDelegate) :
27 new StandaloneRemoteApiDelegate(remoteRpc, options);
30 /**
31 * Do not call directly, use
32 * {@link #newInstance(RemoteRpc, RemoteApiOptions, Delegate)} instead.
34 RemoteApiDelegate(RemoteRpc rpc, RemoteApiOptions options) {
35 this.remoteRpc = rpc;
36 this.remoteDatastore =
37 new RemoteDatastore(remoteRpc.getClient().getAppId(), remoteRpc, options);
40 void resetRpcCount() {
41 remoteRpc.resetRpcCount();
44 int getRpcCount() {
45 return remoteRpc.getRpcCount();
48 final byte[] makeDefaultSyncCall(
49 String serviceName, String methodName, byte[] request) {
50 if (serviceName.equals(RemoteDatastore.DATASTORE_SERVICE)
51 && !Boolean.getBoolean("com.google.appengine.devappserver2")) {
52 return remoteDatastore.handleDatastoreCall(methodName, request);
53 } else {
54 return remoteRpc.call(serviceName, methodName, "", request);
58 /**
59 * Perform any necessary clean up and shut down.
61 public abstract void shutdown();