pull/330/head
AriaLyy 8 years ago
parent ad6ea4fac9
commit bae48a4126
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  2. 15
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java

@ -85,7 +85,7 @@ public class DownloadTaskQueue
} }
startTask(task); startTask(task);
for (DownloadTask temp : tempTasks){ for (DownloadTask temp : tempTasks) {
mExecutePool.putTask(temp); mExecutePool.putTask(temp);
} }
} }

@ -38,20 +38,19 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
protected QUEUE mQueue; protected QUEUE mQueue;
private Map<String, IDownloadSchedulerListener<TASK>> mSchedulerListeners = private Map<String, ISchedulerListener<TASK>> mSchedulerListeners = new ConcurrentHashMap<>();
new ConcurrentHashMap<>();
@Override @Override
public void addSchedulerListener(String targetName, ISchedulerListener<TASK> schedulerListener) { public void addSchedulerListener(String targetName, ISchedulerListener<TASK> schedulerListener) {
mSchedulerListeners.put(targetName, (IDownloadSchedulerListener<TASK>) schedulerListener); mSchedulerListeners.put(targetName, schedulerListener);
} }
@Override public void removeSchedulerListener(String targetName, @Override public void removeSchedulerListener(String targetName,
ISchedulerListener<TASK> schedulerListener) { ISchedulerListener<TASK> schedulerListener) {
//该内存泄露解决方案:http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element //该内存泄露解决方案:http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element
for (Iterator<Map.Entry<String, IDownloadSchedulerListener<TASK>>> iter = for (Iterator<Map.Entry<String, ISchedulerListener<TASK>>> iter =
mSchedulerListeners.entrySet().iterator(); iter.hasNext(); ) { mSchedulerListeners.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, IDownloadSchedulerListener<TASK>> entry = iter.next(); Map.Entry<String, ISchedulerListener<TASK>> entry = iter.next();
if (entry.getKey().equals(targetName)) iter.remove(); if (entry.getKey().equals(targetName)) iter.remove();
} }
} }
@ -99,7 +98,7 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
} }
} }
private void callback(int state, TASK task, IDownloadSchedulerListener<TASK> listener) { private void callback(int state, TASK task, ISchedulerListener<TASK> listener) {
if (listener != null) { if (listener != null) {
if (task == null) { if (task == null) {
Log.e(TAG, "TASK 为null,回调失败"); Log.e(TAG, "TASK 为null,回调失败");
@ -134,7 +133,9 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
listener.onTaskFail(task); listener.onTaskFail(task);
break; break;
case SUPPORT_BREAK_POINT: case SUPPORT_BREAK_POINT:
listener.onNoSupportBreakPoint(task); if (listener instanceof IDownloadSchedulerListener) {
((IDownloadSchedulerListener<TASK>) listener).onNoSupportBreakPoint(task);
}
break; break;
} }
} }

@ -497,7 +497,7 @@ final class SqlHelper extends SQLiteOpenHelper {
} }
private static void close(SQLiteDatabase db) { private static void close(SQLiteDatabase db) {
if (db != null && db.isOpen()) db.close(); //if (db != null && db.isOpen()) db.close();
} }
private static SQLiteDatabase checkDb(SQLiteDatabase db) { private static SQLiteDatabase checkDb(SQLiteDatabase db) {

Loading…
Cancel
Save