1.9.5
[gae.git] / java / src / main / com / google / appengine / tools / remoteapi / RemoteApiDelegate.java
blob978cad1509a2d5cbc3f92d9bf2eac46d2d097196
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.
15 abstract class RemoteApiDelegate implements Delegate<Environment> {
16 private final RemoteRpc remoteRpc;
17 private final RemoteDatastore remoteDatastore;
19 /**
20 * Factory method.
22 public static RemoteApiDelegate newInstance(RemoteRpc remoteRpc, RemoteApiOptions options, Delegate<Environment> containerDelegate) {
23 return containerDelegate != null ?
24 new HostedRemoteApiDelegate(remoteRpc, options, containerDelegate) :
25 new StandaloneRemoteApiDelegate(remoteRpc, options);
28 /**
29 * Do not call directly, use
30 * {@link #newInstance(RemoteRpc, RemoteApiOptions, Delegate)} instead.
32 RemoteApiDelegate(RemoteRpc rpc, RemoteApiOptions options) {
33 this.remoteRpc = rpc;
34 this.remoteDatastore =
35 new RemoteDatastore(remoteRpc.getClient().getAppId(), remoteRpc, options);
38 void resetRpcCount() {
39 remoteRpc.resetRpcCount();
42 int getRpcCount() {
43 return remoteRpc.getRpcCount();
46 final byte[] makeDefaultSyncCall(
47 Environment env, String serviceName, String methodName, byte[] request) {
48 if (serviceName.equals(RemoteDatastore.DATASTORE_SERVICE)
49 && !Boolean.getBoolean("com.google.appengine.devappserver2")) {
50 return remoteDatastore.handleDatastoreCall(methodName, request);
51 } else {
52 return remoteRpc.call(serviceName, methodName, "", request);
56 /**
57 * Perform any necessary clean up and shut down.
59 public abstract void shutdown();