|
|
@ -14,7 +14,6 @@ |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package com.arialyy.aria.core.queue.pool; |
|
|
|
package com.arialyy.aria.core.queue.pool; |
|
|
|
|
|
|
|
|
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
@ -25,6 +24,7 @@ import com.arialyy.aria.core.task.Task; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.LinkedBlockingQueue; |
|
|
|
import java.util.concurrent.LinkedBlockingQueue; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by lyy on 2016/8/14. |
|
|
|
* Created by lyy on 2016/8/14. |
|
|
@ -35,6 +35,7 @@ public class CachePool implements IPool { |
|
|
|
private static final Object LOCK = new Object(); |
|
|
|
private static final Object LOCK = new Object(); |
|
|
|
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
|
|
|
|
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
|
|
|
|
private static volatile CachePool INSTANCE = null; |
|
|
|
private static volatile CachePool INSTANCE = null; |
|
|
|
|
|
|
|
private static final long TIME_OUT = 1000; |
|
|
|
private Map<String, Task> mCacheArray; |
|
|
|
private Map<String, Task> mCacheArray; |
|
|
|
private LinkedBlockingQueue<Task> mCacheQueue; |
|
|
|
private LinkedBlockingQueue<Task> mCacheQueue; |
|
|
|
|
|
|
|
|
|
|
@ -75,13 +76,19 @@ public class CachePool implements IPool { |
|
|
|
|
|
|
|
|
|
|
|
@Override public Task pollTask() { |
|
|
|
@Override public Task pollTask() { |
|
|
|
synchronized (LOCK) { |
|
|
|
synchronized (LOCK) { |
|
|
|
Task task = mCacheQueue.poll(); |
|
|
|
try { |
|
|
|
|
|
|
|
Task task = null; |
|
|
|
|
|
|
|
task = mCacheQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); |
|
|
|
if (task != null) { |
|
|
|
if (task != null) { |
|
|
|
String url = task.getDownloadEntity().getDownloadUrl(); |
|
|
|
String url = task.getDownloadEntity().getDownloadUrl(); |
|
|
|
mCacheArray.remove(CommonUtil.keyToHashKey(url)); |
|
|
|
mCacheArray.remove(CommonUtil.keyToHashKey(url)); |
|
|
|
} |
|
|
|
} |
|
|
|
return task; |
|
|
|
return task; |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public Task getTask(String downloadUrl) { |
|
|
|
@Override public Task getTask(String downloadUrl) { |
|
|
|