Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / SearchApiHelper.java
blob3c8f080a1742015349f52bf0be04451377cca17c
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 * from the call
28 <T extends GeneratedMessage.Builder<T>>
29 Future<T> makeAsyncCall(String method, GeneratedMessage request, final T responseBuilder) {
30 Future<byte[]> response =
31 ApiProxy.makeAsyncCall(PACKAGE, method, request.toByteArray());
32 return new FutureWrapper<byte[], T>(response) {
33 @Override
34 protected T wrap(byte[] responseBytes) {
35 if (responseBytes != null) {
36 try {
37 responseBuilder.mergeFrom(responseBytes);
38 } catch (InvalidProtocolBufferException e) {
39 throw new SearchServiceException(e.toString());
42 return responseBuilder;
45 @Override
46 protected Throwable convertException(Throwable cause) {
47 return cause;