/** * Converts the Asynchronous Request into a Synchronous Future that can be used to block via * {@code Future.get()}. Observables require blocking/synchronous functions * * @return JSONObject * @throws ExecutionException * @throws InterruptedException */ private JSONObject getRouteData() throws ExecutionException, InterruptedException { RequestFuture<JSONObject> future = RequestFuture.newFuture(); String url = "http://www.weather.com.cn/adat/sk/101010100.html"; JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, url, future, future); MyVolley.getRequestQueue().add(req); return future.get(); }
private boolean verifyCaptcha(String captcha) { RequestQueue queue = Volley.newRequestQueue(getContext()); RequestFuture future = RequestFuture.newFuture(); StringRequest request = new StringRequest(Request.Method.POST, "http://ar.qsboy.com/j/verifyCaptcha", future, future) { @Override protected Map<String, String> getParams() { Map<String, String> map = new HashMap<>(); map.put("phone", phone); map.put("captcha", captcha); return map; } }; queue.add(request); try { String s = (String) future.get(5, TimeUnit.SECONDS); boolean isValid = s != null && s.length() > 0; if (isValid) { Gson gson = new Gson(); gson.fromJson(s, App.User.class); } return isValid; } catch (InterruptedException | ExecutionException | TimeoutException e) { e.printStackTrace(); return false; } }
static <T> T generateData(Request<T> request, String listernerField) throws InterruptedException, ExecutionException { if (request == null) throw new NullPointerException("request can not be null"); RequestFuture<T> future = getRequestFuture(request, listernerField); return future.get(); }
DynamicCurrencyPairsVolleyNextRequest request = new DynamicCurrencyPairsVolleyNextRequest(nextUrl, future); getRequestQueue().add(request); String nextResponse = future.get(); // this will block nextPairs.clear(); market.parseCurrencyPairsMain(requestId, nextResponse, nextPairs);
@Override protected String[] doInBackground(Void... params) { if (this.currDate == null) { Log.e(TAG, "Cannot load for null date"); return null; } String cached = this.preferences.getCachedUrl(this.currDate); if (cached != null) { return new String[]{cached, this.preferences.getCachedTitle(this.currDate)}; } RequestFuture<String> future = RequestFuture.newFuture(); volleyRequestQueue.add( new StringRequest(Request.Method.GET, "https://dilbert.com/strip/" + currDate.toString(DilbertPreferences.DATE_FORMATTER) + "/", future, future) ); try { handledResponse = handleParse(future.get(15, TimeUnit.SECONDS)); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } return handledResponse; }
CheckerVolleyNextRequest request = new CheckerVolleyNextRequest(nextUrl, checkerInfo, future); getRequestQueue().add(request); String nextResponse = future.get(); // this will block market.parseTickerMain(requestId, nextResponse, tickerWrapper.ticker, checkerInfo);
requestQueue.add(request); try { backResponse.setResponse(parseToResponse(requestFuture.get())); } catch (Exception e) { OdooLog.e(e);