aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/android/volley/NetworkDispatcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/android/volley/NetworkDispatcher.java')
-rw-r--r--src/main/java/com/android/volley/NetworkDispatcher.java31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/main/java/com/android/volley/NetworkDispatcher.java b/src/main/java/com/android/volley/NetworkDispatcher.java
index 2c04ce0..6e47465 100644
--- a/src/main/java/com/android/volley/NetworkDispatcher.java
+++ b/src/main/java/com/android/volley/NetworkDispatcher.java
@@ -21,16 +21,16 @@ import android.net.TrafficStats;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
-
+import android.support.annotation.VisibleForTesting;
import java.util.concurrent.BlockingQueue;
/**
* Provides a thread for performing network dispatch from a queue of requests.
*
- * Requests added to the specified queue are processed from the network via a
- * specified {@link Network} interface. Responses are committed to cache, if
- * eligible, using a specified {@link Cache} interface. Valid responses and
- * errors are posted back to the caller via a {@link ResponseDelivery}.
+ * <p>Requests added to the specified queue are processed from the network via a specified {@link
+ * Network} interface. Responses are committed to cache, if eligible, using a specified {@link
+ * Cache} interface. Valid responses and errors are posted back to the caller via a {@link
+ * ResponseDelivery}.
*/
public class NetworkDispatcher extends Thread {
@@ -46,16 +46,19 @@ public class NetworkDispatcher extends Thread {
private volatile boolean mQuit = false;
/**
- * Creates a new network dispatcher thread. You must call {@link #start()}
- * in order to begin processing.
+ * Creates a new network dispatcher thread. You must call {@link #start()} in order to begin
+ * processing.
*
* @param queue Queue of incoming requests for triage
* @param network Network interface to use for performing requests
* @param cache Cache interface to use for writing responses to cache
* @param delivery Delivery interface to use for posting responses
*/
- public NetworkDispatcher(BlockingQueue<Request<?>> queue,
- Network network, Cache cache, ResponseDelivery delivery) {
+ public NetworkDispatcher(
+ BlockingQueue<Request<?>> queue,
+ Network network,
+ Cache cache,
+ ResponseDelivery delivery) {
mQueue = queue;
mNetwork = network;
mCache = cache;
@@ -63,8 +66,8 @@ public class NetworkDispatcher extends Thread {
}
/**
- * Forces this dispatcher to quit immediately. If any requests are still in
- * the queue, they are not guaranteed to be processed.
+ * Forces this dispatcher to quit immediately. If any requests are still in the queue, they are
+ * not guaranteed to be processed.
*/
public void quit() {
mQuit = true;
@@ -99,10 +102,14 @@ public class NetworkDispatcher extends Thread {
// of time. Update consumer-proguard-rules.pro when modifying this. See also
// https://github.com/google/volley/issues/114
private void processRequest() throws InterruptedException {
- long startTimeMs = SystemClock.elapsedRealtime();
// Take a request from the queue.
Request<?> request = mQueue.take();
+ processRequest(request);
+ }
+ @VisibleForTesting
+ void processRequest(Request<?> request) {
+ long startTimeMs = SystemClock.elapsedRealtime();
try {
request.addMarker("network-queue-take");