Search in sources :

Example 1 with BoxObject

use of com.box.androidsdk.content.models.BoxObject in project box-android-sdk by box.

the class BoxRequestBatch method onSend.

@Override
public BoxResponseBatch onSend() throws BoxException {
    BoxResponseBatch responses = new BoxResponseBatch();
    if (mExecutor != null) {
        ArrayList<BoxFutureTask<BoxObject>> tasks = new ArrayList<BoxFutureTask<BoxObject>>();
        for (BoxRequest req : mRequests) {
            BoxFutureTask task = req.toTask();
            mExecutor.submit(task);
            tasks.add(task);
        }
        for (BoxFutureTask<BoxObject> task : tasks) {
            try {
                BoxResponse<BoxObject> response = task.get();
                responses.addResponse(response);
            } catch (InterruptedException e) {
                throw new BoxException(e.getMessage(), e);
            } catch (ExecutionException e) {
                throw new BoxException(e.getMessage(), e);
            }
        }
    } else {
        for (BoxRequest req : mRequests) {
            BoxObject value = null;
            Exception ex = null;
            try {
                value = req.send();
            } catch (Exception e) {
                ex = e;
            }
            BoxResponse<BoxObject> response = new BoxResponse<BoxObject>(value, ex, req);
            responses.addResponse(response);
        }
    }
    return responses;
}
Also used : BoxException(com.box.androidsdk.content.BoxException) ArrayList(java.util.ArrayList) BoxFutureTask(com.box.androidsdk.content.BoxFutureTask) ExecutionException(java.util.concurrent.ExecutionException) BoxException(com.box.androidsdk.content.BoxException) BoxObject(com.box.androidsdk.content.models.BoxObject) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BoxException (com.box.androidsdk.content.BoxException)1 BoxFutureTask (com.box.androidsdk.content.BoxFutureTask)1 BoxObject (com.box.androidsdk.content.models.BoxObject)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1