當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestFuture類代碼示例

本文整理匯總了Java中com.android.volley.toolbox.RequestFuture的典型用法代碼示例。如果您正苦於以下問題:Java RequestFuture類的具體用法?Java RequestFuture怎麽用?Java RequestFuture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RequestFuture類屬於com.android.volley.toolbox包,在下文中一共展示了RequestFuture類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: volleySyncRequest

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
/**
 * Effettua una web request sincrona tramite Volley API, restituendo in risposta
 * l'oggetto JSON scaricato.
 */
public static JSONObject volleySyncRequest(Context c, String url) {

    // configurazione della webRequest
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
    RequestQueue requestQueue = Volley.newRequestQueue(c);
    requestQueue.add(request);

    // esecuzione sincrona della webRequest
    try {
        // limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
        // la risposta.
        return future.get(10, TimeUnit.SECONDS);

    } catch (InterruptedException | TimeoutException | ExecutionException e) {
        e.printStackTrace();
    }

    return null;
}
 
開發者ID:IelloDevTeam,項目名稱:IelloAndroidApp,代碼行數:25,代碼來源:HelperRete.java

示例2: volleySyncRequest

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
/**
 * Effettua una web request sincrona tramite Volley API, restituendo in risposta
 * l'oggetto JSON scaricato.
 */
static JSONObject volleySyncRequest(Context c, String url) {

    // configurazione della webRequest
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
    RequestQueue requestQueue = Volley.newRequestQueue(c);
    requestQueue.add(request);

    // esecuzione sincrona della webRequest
    try {
        // limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
        // la risposta.
        return future.get(10, TimeUnit.SECONDS);

    } catch (InterruptedException | TimeoutException | ExecutionException e) {
        e.printStackTrace();
    }

    return null;
}
 
開發者ID:IelloDevTeam,項目名稱:IelloAndroidAdminApp,代碼行數:25,代碼來源:HelperRete.java

示例3: getRequestFuture

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
static <T> RequestFuture<T> getRequestFuture(Request<T> request, String listernerField) {
    if (request == null) throw new NullPointerException("request can not be null");
    RequestFuture<T> future = RequestFuture.newFuture();

    String listenerFieldName = TextUtils.isEmpty(listernerField)? DEFAULT_LISTENER_FIELD: listernerField;
    String errorListenerFieldName = DEFAULT_ERROR_LISTENER_FIELD;
    try {
        Hack.HackedClass hackedClass = Hack.into(request.getClass());
        hackedClass.field(listenerFieldName).set(request, future);
        hackedClass.field(errorListenerFieldName).set(request, future);
    } catch (Hack.HackDeclaration.HackAssertionException e) {
        throw new IllegalStateException("the field name of your class is not correct: " + e.getHackedFieldName());
    }

    sRequestQueue.add(request);
    return future;
}
 
開發者ID:yangweigbh,項目名稱:VolleyX,代碼行數:18,代碼來源:VolleyX.java

示例4: invokeSignedSyncRequest

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
protected <T> T invokeSignedSyncRequest(int method, String resourcePath,
                                      Map<String, String> headers,
                                      Map<String, Object> params,
                                      Object entity, Class<T> returnType) {
    RequestFuture<T> future = RequestFuture.newFuture();
    ErrorListener error = onError();
    boolean refreshJWT = !(method == GET && JWT_PATH.equals(resourcePath));
    getRequestQueue().add(signer.invokeSignedRequest(accessKey, key(refreshJWT),
            method, getEndpoint(), getFullPath(resourcePath), null, params,
            entity, returnType, future, future));
    try {
        return future.get(requestTimeout, TimeUnit.SECONDS);
    } catch (Exception e) {
        error.onErrorResponse(new VolleyError(e));
    }
    return null;
}
 
開發者ID:Erudika,項目名稱:para-client-android,代碼行數:18,代碼來源:ParaClient.java

示例5: requestJsonObject

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
public static JSONObject requestJsonObject(Context context, int method, Map<String, String> headers, String url,
                                           JSONObject params, Response.ErrorListener errorListener) {
  RequestFuture<JSONObject> future = RequestFuture.newFuture();
  final Map<String, String> reqHeaders = headers;
  JsonObjectRequest request = new JsonObjectRequest(method, url, params, future, future) {
    public Map<String, String> getHeaders() {
      return reqHeaders != null ? reqHeaders : new HashMap<String, String>();
    }
  };
  RequestManager.getInstance(context).addToRequestQueue(request);
  try {
    return future.get(REQUEST_TIMEOUT, TimeUnit.SECONDS);
  } catch (Exception e) {
    errorListener.onErrorResponse(new VolleyError(e));
  }
  return null;
}
 
開發者ID:brianberg,項目名稱:taiga-android,代碼行數:18,代碼來源:HttpHelper.java

示例6: requestJsonArray

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
public static JSONArray requestJsonArray(Context context, int method, Map<String, String> headers, String url,
                                         JSONObject params, Response.ErrorListener errorListener) {
  RequestFuture<JSONArray> future = RequestFuture.newFuture();
  final Map<String, String> reqHeaders = headers;
  JsonArrayRequest request = new JsonArrayRequest(method, url, params, future, future) {
    public Map<String, String> getHeaders() {
      return reqHeaders != null ? reqHeaders : new HashMap<String, String>();
    }
  };
  RequestManager.getInstance(context).addToRequestQueue(request);
  try {
    return future.get(REQUEST_TIMEOUT, TimeUnit.SECONDS);
  } catch (Exception e) {
    errorListener.onErrorResponse(new VolleyError(e));
  }
  return null;
}
 
開發者ID:brianberg,項目名稱:taiga-android,代碼行數:18,代碼來源:HttpHelper.java

示例7: fetchSettingsOverNetwork

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
public final ContentFilters.ContentFilterSettingsResponse fetchOverNetwork$6f1d50b6()
{
  Utils.ensureNotOnMainThread();
  RequestFuture localRequestFuture = RequestFuture.newFuture();
  fetchSettingsOverNetwork(localRequestFuture, localRequestFuture, true);
  try
  {
    ContentFilters.ContentFilterSettingsResponse localContentFilterSettingsResponse = (ContentFilters.ContentFilterSettingsResponse)localRequestFuture.get();
    onResponse(localContentFilterSettingsResponse);
    return localContentFilterSettingsResponse;
  }
  catch (InterruptedException localInterruptedException)
  {
    logException(localInterruptedException);
    return null;
  }
  catch (ExecutionException localExecutionException)
  {
    for (;;)
    {
      logException(localExecutionException);
    }
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:25,代碼來源:DfeContentFilters.java

示例8: fetchJsonObject

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
private JSONObject fetchJsonObject(String paramString)
{
  try
  {
    RequestFuture localRequestFuture = RequestFuture.newFuture();
    JsonObjectWithHeadersRequest localJsonObjectWithHeadersRequest = new JsonObjectWithHeadersRequest(paramString, Collections.singletonMap("User-Agent", WalletRequestQueue.USER_AGENT_VALUE), localRequestFuture, localRequestFuture);
    this.mRequestQueue.add(localJsonObjectWithHeadersRequest);
    JSONObject localJSONObject = (JSONObject)localRequestFuture.get(5000L, TimeUnit.MILLISECONDS);
    return localJSONObject;
  }
  catch (TimeoutException localTimeoutException)
  {
    Log.w("GooglePlacesAddressSour", "TimeoutException while retrieving addresses from GooglePlaces", localTimeoutException);
    return null;
  }
  catch (InterruptedException localInterruptedException)
  {
    Log.w("GooglePlacesAddressSour", "InterruptedException while retrieving addresses from GooglePlaces", localInterruptedException);
    return null;
  }
  catch (ExecutionException localExecutionException)
  {
    Log.w("GooglePlacesAddressSour", "ExecutionException while retrieving addresses from GooglePlaces", localExecutionException);
  }
  return null;
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:27,代碼來源:GooglePlacesAddressSource.java

示例9: blockingGetRequestToken

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
/** Obtain an OAuth request token. */
@TargetApi(21)
public static Token blockingGetRequestToken(Context context, Object tag)
        throws VolleyError, InterruptedException {
    Util.assertNotOnMainThread();
    RequestFuture<Token> future = RequestFuture.newFuture();
    Map<String, String> extraHeaders = new HashMap<>();
    extraHeaders.put(KEY_CALLBACK, BuildConfig.CALLBACK_URL);
    if (Build.VERSION.SDK_INT >= 21) {
        extraHeaders.put(KEY_LANG_PREF,
                context.getResources().getConfiguration().locale.toLanguageTag());
    }
    // We use an empty token here because this is the initial request.
    OAuthTokenRequest request = new OAuthTokenRequest(ENDPOINT_GET_REQUEST_TOKEN,
            new Token.Builder().build(), extraHeaders, future, future);
    request.setTag(tag);
    return Volley.makeBlockingRequest(context, request, future);
}
 
開發者ID:jpd236,項目名稱:fantasywear,代碼行數:19,代碼來源:OAuthClient.java

示例10: blockingGetToken

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
/**
 * Exchange a request token and an OAuth verifier (attached to the given callback uri) for an
 * auth token.
 */
public static Token blockingGetToken(Context context, Object tag, Token requestToken,
        String callbackUri) throws VolleyError, InterruptedException {
    Util.assertNotOnMainThread();
    RequestFuture<Token> future = RequestFuture.newFuture();
    Map<String, String> extraHeaders = new HashMap<>();
    Uri uri = Uri.parse(callbackUri);
    String verifier = uri.getQueryParameter(KEY_VERIFIER);
    if (TextUtils.isEmpty(verifier)) {
        throw new AuthFailureError("Provided callbackUri has no verifier: " + callbackUri);
    }
    extraHeaders.put(KEY_VERIFIER, verifier);
    OAuthTokenRequest request = new OAuthTokenRequest(
            ENDPOINT_GET_TOKEN, requestToken, extraHeaders, future, future);
    request.setTag(tag);
    return Volley.makeBlockingRequest(context, request, future);
}
 
開發者ID:jpd236,項目名稱:fantasywear,代碼行數:21,代碼來源:OAuthClient.java

示例11: BaseRequest

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
/**
 * @param requestConfig Additional request configuration entity, used to provide some additional parameters
 * @param lock          autogenerated object used to perform synchronized requests
 */
protected BaseRequest(RequestMethod requestMethod, String requestUrl, RequestConfig requestConfig, RequestFuture<ResponseData> lock) {
    super(requestMethod.methodCode, requestUrl, lock);
    this.requestFormat = requestConfig.getRequestFormat();

    ResponseFormat responseFormatL = requestConfig.getResponseFormat();
    if (responseFormatL == null) {
        responseFormatL = this.requestFormat.toResponse();
    }
    this.responseFormat = responseFormatL;
    this.syncLock = lock;
    this.requestHandler = Handler.getRequestHandlerForFormat(this.requestFormat);
    this.responseHandler = Handler.getResponseHandlerForFormat(this.responseFormat);
    this.initRequestHeaders();
    this.responseClasSpecifier = requestConfig.getResponseClassSpecifier();
    this.errorResponseClasSpecifier = requestConfig.getErrorResponseClassSpecifier();
    this.result = new ResponseData();
}
 
開發者ID:lemberg,項目名稱:android-project-template,代碼行數:22,代碼來源:BaseRequest.java

示例12: getStory

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
public Story getStory(String storyId) {
    String STORY_PATH = "/story";
    String storyPath = mApiBaseUrl + STORY_PATH + "/" + storyId;

    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(storyPath, future, future);
    request.setRetryPolicy(RetryPolicyFactory.build());
    mRequestQueue.add(request);

    try {
        JSONObject response = future.get();
        return StoryMarshaller.marshall(response);
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:longdivision,項目名稱:hex,代碼行數:17,代碼來源:StoryService.java

示例13: getStories

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
public List<Story> getStories(Collection collection) {
    String apiUrl = getUrlForCollection(collection);

    RequestFuture<JSONArray> future = RequestFuture.newFuture();
    JsonArrayRequest request = new JsonArrayRequest(mApiBaseUrl + apiUrl, future, future);
    request.setRetryPolicy(RetryPolicyFactory.build());

    mRequestQueue.add(request);

    try {
        JSONArray response = future.get();
        return FrontPageMarshaller.marshall(response);
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:longdivision,項目名稱:hex,代碼行數:17,代碼來源:StoryCollectionService.java

示例14: postCheckIn

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
private long postCheckIn(String attendeeId, String eventId, boolean revert, String cookie) {
    RequestQueue queue = GutenbergApplication.from(getContext()).getRequestQueue();
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    queue.add(new CheckInRequest(cookie, eventId, attendeeId, revert, future, future));
    try {
        JSONObject object = future.get();
        return object.getLong("checkinTime");
    } catch (InterruptedException | ExecutionException | JSONException e) {
        Throwable cause = e.getCause();
        if (cause instanceof ServerError) {
            ServerError error = (ServerError) cause;
            Log.e(TAG, "Server error: " + new String(error.networkResponse.data));
        }
        Log.e(TAG, "Cannot sync checkin.", e);
    }
    return -1;
}
 
開發者ID:googlesamples,項目名稱:attendee-checkin,代碼行數:18,代碼來源:SyncAdapter.java

示例15: addToQueueSync

import com.android.volley.toolbox.RequestFuture; //導入依賴的package包/類
private Object addToQueueSync(RequestCreator requestCreator) throws Exception {
  final RequestFuture<Object> future = RequestFuture.newFuture();
  Request<Response> request = new VolleyRequest(getMethod(requestCreator.getMethod()),
      requestCreator.getUrl(), requestCreator, future) {
    @Override
    protected void deliverResponse(Response response) {
      super.deliverResponse(response);
      future.onResponse(response.getResponseObject());
    }
  };
  future.setRequest(request);
  addToQueue(request);
  int timeout = 30000;
  if (requestCreator.getRetryPolicy() != null) {
    timeout = requestCreator.getRetryPolicy().getCurrentTimeout();
  }
  return future.get(timeout, TimeUnit.MILLISECONDS);
}
 
開發者ID:orhanobut,項目名稱:wasp,代碼行數:19,代碼來源:VolleyNetworkStack.java


注:本文中的com.android.volley.toolbox.RequestFuture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。