Android SDK Version
  • java.lang.Object
    • java.util.AbstractCollection<E>
      • java.util.AbstractList<GraphRequest>
        • com.facebook.GraphRequestBatch
All Implemented Interfaces:
java.lang.Iterable<GraphRequest>, java.util.Collection<GraphRequest>, java.util.List<GraphRequest>

public class GraphRequestBatch
extends java.util.AbstractList<GraphRequest>
RequestBatch contains a list of Request objects that can be sent to Facebook in a single round-trip.
Nested Class Summary
Modifier and TypeClass and Description
static interface GraphRequestBatch.Callback
Specifies the interface that consumers of the RequestBatch class can implement in order to be notified when the entire batch completes execution.
static interface GraphRequestBatch.OnProgressCallback
Specifies the interface that consumers of the RequestBatch class can implement in order to be notified when the batch makes progress.
Field Summary
Fields inherited from class java.util.AbstractList
modCount
Constructor Summary
Constructor and Description
GraphRequestBatch()
Constructor.
GraphRequestBatch(java.util.Collection<GraphRequest> requests)
Constructor.
GraphRequestBatch(GraphRequest... requests)
Constructor.
GraphRequestBatch(GraphRequestBatch requests)
Constructor.
Method Summary
Modifier and TypeMethod and Description
booleanadd(GraphRequest request) 
voidadd(int location, GraphRequest request) 
voidaddCallback(GraphRequestBatch.Callback callback)
Adds a batch-level callback which will be called when the entire batch has finished executing.
voidclear() 
java.util.List<GraphResponse>executeAndWait()
Executes this batch on the current thread and returns the responses.
GraphRequestAsyncTaskexecuteAsync()
Executes this batch asynchronously.
GraphRequestget(int i) 
java.lang.StringgetBatchApplicationId()
Getter for the batch application id.
intgetTimeout()
Gets the timeout to wait for responses from the server before a timeout error occurs.
GraphRequestremove(int location) 
voidremoveCallback(GraphRequestBatch.Callback callback)
Removes a batch-level callback.
GraphRequestset(int location, GraphRequest request) 
voidsetBatchApplicationId(java.lang.String batchApplicationId)
Setter for the batch application id.
voidsetTimeout(int timeoutInMilliseconds)
Sets the timeout to wait for responses from the server before a timeout error occurs.
intsize() 
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
Methods inherited from interface java.lang.Iterable
forEach
Constructor Detail

GraphRequestBatch

public GraphRequestBatch()
Constructor. Creates an empty batch.

GraphRequestBatch

public GraphRequestBatch(java.util.Collection<GraphRequest> requests)
Constructor.
Parameters:
requests - the requests to add to the batch

GraphRequestBatch

public GraphRequestBatch(GraphRequest... requests)
Constructor.
Parameters:
requests - the requests to add to the batch

GraphRequestBatch

public GraphRequestBatch(GraphRequestBatch requests)
Constructor.
Parameters:
requests - the requests to add to the batch
Method Detail

getTimeout

public int getTimeout()
Gets the timeout to wait for responses from the server before a timeout error occurs.
Returns:
the timeout, in milliseconds; 0 (the default) means do not timeout

setTimeout

public void setTimeout(int timeoutInMilliseconds)
Sets the timeout to wait for responses from the server before a timeout error occurs.
Parameters:
timeoutInMilliseconds - the timeout, in milliseconds; 0 means do not timeout

addCallback

public void addCallback(GraphRequestBatch.Callback callback)
Adds a batch-level callback which will be called when the entire batch has finished executing.
Parameters:
callback - the callback

removeCallback

public void removeCallback(GraphRequestBatch.Callback callback)
Removes a batch-level callback.
Parameters:
callback - the callback

add

public final boolean add(GraphRequest request)
Specified by:
add in interface java.util.Collection<GraphRequest>
Specified by:
add in interface java.util.List<GraphRequest>
Overrides:
add in class java.util.AbstractList<GraphRequest>

add

public final void add(int location,
                      GraphRequest request)
Specified by:
add in interface java.util.List<GraphRequest>
Overrides:
add in class java.util.AbstractList<GraphRequest>

clear

public final void clear()
Specified by:
clear in interface java.util.Collection<GraphRequest>
Specified by:
clear in interface java.util.List<GraphRequest>
Overrides:
clear in class java.util.AbstractList<GraphRequest>

get

public final GraphRequest get(int i)
Specified by:
get in interface java.util.List<GraphRequest>
Specified by:
get in class java.util.AbstractList<GraphRequest>

remove

public final GraphRequest remove(int location)
Specified by:
remove in interface java.util.List<GraphRequest>
Overrides:
remove in class java.util.AbstractList<GraphRequest>

set

public final GraphRequest set(int location,
                              GraphRequest request)
Specified by:
set in interface java.util.List<GraphRequest>
Overrides:
set in class java.util.AbstractList<GraphRequest>

size

public final int size()
Specified by:
size in interface java.util.Collection<GraphRequest>
Specified by:
size in interface java.util.List<GraphRequest>
Specified by:
size in class java.util.AbstractCollection<GraphRequest>

getBatchApplicationId

public final java.lang.String getBatchApplicationId()
Getter for the batch application id.
Returns:
the batch application id.

setBatchApplicationId

public final void setBatchApplicationId(java.lang.String batchApplicationId)
Setter for the batch application id.
Parameters:
batchApplicationId - The batch application id.

executeAndWait

public final java.util.List<GraphResponse> executeAndWait()
Executes this batch on the current thread and returns the responses.
This should only be used if you have transitioned off the UI thread.
Returns:
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
java.lang.IllegalArgumentException - if the passed in RequestBatch is empty
java.lang.NullPointerException - if the passed in RequestBatch or any of its contents are null

executeAsync

public final GraphRequestAsyncTask executeAsync()
Executes this batch asynchronously. This function will return immediately, and the batch 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 GraphRequest.setCallback(GraphRequest.Callback))
This should only be called from the UI thread.
Returns:
a RequestAsyncTask that is executing the request
Throws:
java.lang.IllegalArgumentException - if this batch is empty
java.lang.NullPointerException - if any of the contents of this batch are null