With Android, how do I set the maximum deadline fo

2019-05-06 15:39发布

When making a ClientEndpoint API request from an Android app to an App-Engine service, how do I set a deadline/timeout for the execute() action?

I'm looking for something like:

Foo foo = endpoint.getSomething(id) .setDeadline(2000/*ms*/) .execute();

3条回答
女痞
2楼-- · 2019-05-06 16:19

I am not sure if one can control that. Since the Endpoints are hosted in an App Engine environment, standard timeout for any App Engine HTTP Request should apply i.e. 60 seconds.

查看更多
地球回转人心会变
3楼-- · 2019-05-06 16:22

When building the endpoint, specify a connect and read timeout in HttpRequestInitializer. For example, in this case 20 and 10 secs respectively.

SomeEndpoint.Builder endpointBuilder = new SomeEndpoint.Builder(
    AndroidHttp.newCompatibleTransport(),
    new JacksonFactory(), new HttpRequestInitializer() {
        public void initialize(HttpRequest httpRequest) {
            httpRequest.setConnectTimeout(20 * 1000);
            httpRequest.setReadTimeout(10 * 1000);
        }
    });
查看更多
一夜七次
4楼-- · 2019-05-06 16:28

It is possible. You just need to implement your own HttpRequestInitializer where you set connect and read timeouts in its initialize method. This HttpRequestInitializer need to be passed then as a parameter to your endpoint builder constructor.

查看更多
登录 后发表回答