com.facebook
Class RequestBatch

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<Request>
          extended by com.facebook.RequestBatch
All Implemented Interfaces:
Iterable<Request>, Collection<Request>, List<Request>
Direct Known Subclasses:
CacheableRequestBatch

public class RequestBatch
extends AbstractList<Request>

RequestBatch contains a list of Request objects that can be sent to Facebook in a single round-trip.


Nested Class Summary
static interface RequestBatch.Callback
          Specifies the interface that consumers of the RequestBatch class can implement in order to be notified when the entire batch completes execution.
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
RequestBatch()
          Constructor.
RequestBatch(Collection<Request> requests)
          Constructor.
RequestBatch(Request... requests)
          Constructor.
RequestBatch(RequestBatch requests)
          Constructor.
 
Method Summary
 void add(int location, Request request)
           
 boolean add(Request request)
           
 void addCallback(RequestBatch.Callback callback)
          Adds a batch-level callback which will be called when the entire batch has finished executing.
 void clear()
           
 List<Response> executeAndWait()
          Executes this batch on the current thread and returns the responses.
 RequestAsyncTask executeAsync()
          Executes this batch asynchronously.
 Request get(int i)
           
 int getTimeout()
          Gets the timeout to wait for responses from the server before a timeout error occurs.
 Request remove(int location)
           
 void removeCallback(RequestBatch.Callback callback)
          Removes a batch-level callback.
 Request set(int location, Request request)
           
 void setTimeout(int timeoutInMilliseconds)
          Sets the timeout to wait for responses from the server before a timeout error occurs.
 int size()
           
 
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, retainAll, toArray, toArray
 

Constructor Detail

RequestBatch

public RequestBatch()
Constructor. Creates an empty batch.


RequestBatch

public RequestBatch(Collection<Request> requests)
Constructor.

Parameters:
requests - the requests to add to the batch

RequestBatch

public RequestBatch(Request... requests)
Constructor.

Parameters:
requests - the requests to add to the batch

RequestBatch

public RequestBatch(RequestBatch 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(RequestBatch.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(RequestBatch.Callback callback)
Removes a batch-level callback.

Parameters:
callback - the callback

add

public final boolean add(Request request)
Specified by:
add in interface Collection<Request>
Specified by:
add in interface List<Request>
Overrides:
add in class AbstractList<Request>

add

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

clear

public final void clear()
Specified by:
clear in interface Collection<Request>
Specified by:
clear in interface List<Request>
Overrides:
clear in class AbstractList<Request>

get

public final Request get(int i)
Specified by:
get in interface List<Request>
Specified by:
get in class AbstractList<Request>

remove

public final Request remove(int location)
Specified by:
remove in interface List<Request>
Overrides:
remove in class AbstractList<Request>

set

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

size

public final int size()
Specified by:
size in interface Collection<Request>
Specified by:
size in interface List<Request>
Specified by:
size in class AbstractCollection<Request>

executeAndWait

public final List<Response> 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
IllegalArgumentException - if the passed in RequestBatch is empty
NullPointerException - if the passed in RequestBatch or any of its contents are null

executeAsync

public final RequestAsyncTask 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 Request.setCallback(com.facebook.Request.Callback))

This should only be called from the UI thread.

Returns:
a RequestAsyncTask that is executing the request
Throws:
IllegalArgumentException - if this batch is empty
NullPointerException - if any of the contents of this batch are null