/** * Serializes one or more requests but does not execute them. The resulting HttpURLConnection * can be executed explicitly by the caller. * * @param requests one or more Requests to serialize * @return an HttpURLConnection which is ready to execute * @throws FacebookException If any of the requests in the batch are badly constructed or * if there are problems contacting the service * @throws IllegalArgumentException if the passed in collection is empty * @throws NullPointerException if the passed in collection or any of its contents are null */ public static HttpURLConnection toHttpConnection(Collection<GraphRequest> requests) { Validate.notEmptyAndContainsNoNulls(requests, "requests"); return toHttpConnection(new GraphRequestBatch(requests)); }
/** * Executes requests as a single batch asynchronously. This function will return immediately, * and the requests will be processed on a separate thread. In order to process results of a * request, or determine whether a request succeeded or failed, a callback must be specified * (see the {@link #setCallback(Callback) setCallback} method). * <p/> * This should only be called from the UI thread. * * @param requests the RequestBatch to execute * @return a RequestAsyncTask that is executing the request * @throws IllegalArgumentException if the passed in RequestBatch is empty * @throws NullPointerException if the passed in RequestBatch or any of its contents are * null */ public static GraphRequestAsyncTask executeBatchAsync(GraphRequestBatch requests) { Validate.notEmptyAndContainsNoNulls(requests, "requests"); GraphRequestAsyncTask asyncTask = new GraphRequestAsyncTask(requests); asyncTask.executeOnExecutor(FacebookSdk.getExecutor()); return asyncTask; }
Validate.notEmptyAndContainsNoNulls(requests, "requests");
/** * Executes requests as a single batch asynchronously. This function will return immediately, and the requests will * be processed on a separate thread. In order to process results of a request, or determine whether a request * succeeded or failed, a callback must be specified (see the {@link #setCallback(Callback) setCallback} method). * <p/> * This should only be called from the UI thread. * * @param requests * the RequestBatch to execute * @return a RequestAsyncTask that is executing the request * * @throws IllegalArgumentException if the passed in RequestBatch is empty * @throws NullPointerException if the passed in RequestBatch or any of its contents are null */ public static RequestAsyncTask executeBatchAsync(RequestBatch requests) { Validate.notEmptyAndContainsNoNulls(requests, "requests"); RequestAsyncTask asyncTask = new RequestAsyncTask(requests); asyncTask.executeOnSettingsExecutor(); return asyncTask; }
/** * Serializes one or more requests but does not execute them. The resulting HttpURLConnection can be executed * explicitly by the caller. * * @param requests * one or more Requests to serialize * @return an HttpURLConnection which is ready to execute * * @throws FacebookException * If any of the requests in the batch are badly constructed or if there are problems * contacting the service * @throws IllegalArgumentException if the passed in collection is empty * @throws NullPointerException if the passed in collection or any of its contents are null */ public static HttpURLConnection toHttpConnection(Collection<Request> requests) { Validate.notEmptyAndContainsNoNulls(requests, "requests"); return toHttpConnection(new RequestBatch(requests)); }
/** * Executes requests on the current thread as a single batch and returns the responses. * <p/> * This should only be used if you have transitioned off the UI thread. * * @param requests * the batch of Requests to execute * * @return a list of Response objects representing the results of the requests; responses are returned in the same * order as the requests were specified. * * @throws FacebookException * If there was an error in the protocol used to communicate with the service * @throws IllegalArgumentException if the passed in RequestBatch is empty * @throws NullPointerException if the passed in RequestBatch or any of its contents are null */ public static List<Response> executeBatchAndWait(RequestBatch requests) { Validate.notEmptyAndContainsNoNulls(requests, "requests"); HttpURLConnection connection = null; try { connection = toHttpConnection(requests); } catch (Exception ex) { List<Response> responses = Response.constructErrorResponses(requests.getRequests(), null, new FacebookException(ex)); runCallbacks(requests, responses); return responses; } List<Response> responses = executeConnectionAndWait(connection, requests); return responses; }