From 407837ebe2c7cf8fe7f39cd896641324b69ac060 Mon Sep 17 00:00:00 2001 From: Shyri Villar Date: Wed, 20 Jan 2016 20:11:36 +0100 Subject: [PATCH] Added configurable timeout --- .../libraries/volley/apiInvoker.mustache | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache index dbcfb7c454c..abb885bdabb 100644 --- a/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache @@ -49,6 +49,8 @@ public class ApiInvoker { private Map authentications; + private int connectionTimeout; + /** Content type "text/plain" with UTF-8 encoding. */ public static final ContentType TEXT_PLAIN_UTF8 = ContentType.create("text/plain", Consts.UTF_8); @@ -174,15 +176,15 @@ public class ApiInvoker { } public static void initializeInstance() { - initializeInstance(null, null, 0, null); + initializeInstance(null); } public static void initializeInstance(Cache cache) { - initializeInstance(cache, null, 0, null); + initializeInstance(cache, null, 0, null, 30); } - public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) { - INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery); + public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) { + INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout); setUserAgent("Android-Volley-Swagger"); // Setup authentications (key: authentication name, value: authentication). @@ -199,7 +201,7 @@ public class ApiInvoker { INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications); } - private ApiInvoker(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) { + private ApiInvoker(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) { if(cache == null) cache = new NoCache(); if(network == null) { HttpStack stack = new HurlStack(); @@ -211,6 +213,7 @@ public class ApiInvoker { } else { initConnectionRequest(cache, network, threadPoolSize, delivery); } + this.connectionTimeout = connectionTimeout; } public static ApiInvoker getInstance() { @@ -326,6 +329,14 @@ public class ApiInvoker { throw new RuntimeException("No API key authentication configured!"); } + public void setConnectionTimeout(int connectionTimeout){ + this.connectionTimeout = connectionTimeout; + } + + public int getConnectionTimeout() { + return connectionTimeout; + } + /** * Update query and header parameters based on authentication settings. * @@ -344,7 +355,7 @@ public class ApiInvoker { Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, future, future); if(request != null) { mRequestQueue.add(request); - return future.get(30, TimeUnit.SECONDS); + return future.get(connectionTimeout, TimeUnit.SECONDS); } else return "no data"; }