Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / SearchApiHelper.java
blobd7072e50a982953331998cc29d1e987226487161
1 // Copyright 2010 Google Inc. All rights reserved.
2 package com.google.appengine.api.search;
4 import com.google.appengine.api.utils.FutureWrapper;
5 import com.google.apphosting.api.ApiProxy;
6 import com.google.protobuf.GeneratedMessage;
7 import com.google.protobuf.InvalidProtocolBufferException;
9 import java.util.concurrent.Future;
11 /**
12 * Provides support for translation of calls between userland and appserver
13 * land.
16 class SearchApiHelper {
18 private static final String PACKAGE = "search";
20 /**
21 * Makes an asynchronous call.
23 * @param method the method on the API to call
24 * @param request the request to forward to the API
25 * @param responseBuilder the response builder used to fill the response
26 * @param deadline the deadline of the call. if it is null, the default api deadline will be used
28 <T extends GeneratedMessage.Builder<T>>
29 Future<T> makeAsyncCall(String method, GeneratedMessage request, final T responseBuilder, Double deadline) {
30 Future<byte[]> response;
31 if (deadline == null) {
32 response = ApiProxy.makeAsyncCall(PACKAGE, method, request.toByteArray());
33 } else {
34 ApiProxy.ApiConfig apiConfig = new ApiProxy.ApiConfig();
35 apiConfig.setDeadlineInSeconds(deadline);
36 response = ApiProxy.makeAsyncCall(PACKAGE, method, request.toByteArray(), apiConfig);
38 return new FutureWrapper<byte[], T>(response) {
39 @Override
40 protected T wrap(byte[] responseBytes) {
41 if (responseBytes != null) {
42 try {
43 responseBuilder.mergeFrom(responseBytes);
44 } catch (InvalidProtocolBufferException e) {
45 throw new SearchServiceException(e.toString());
48 return responseBuilder;
51 @Override
52 protected Throwable convertException(Throwable cause) {
53 return cause;