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
;
12 * Provides support for translation of calls between userland and appserver
16 class SearchApiHelper
{
18 private static final String PACKAGE
= "search";
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());
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
) {
40 protected T
wrap(byte[] responseBytes
) {
41 if (responseBytes
!= null) {
43 responseBuilder
.mergeFrom(responseBytes
);
44 } catch (InvalidProtocolBufferException e
) {
45 throw new SearchServiceException(e
.toString());
48 return responseBuilder
;
52 protected Throwable
convertException(Throwable cause
) {