|
|
|
@ -54,7 +54,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
private static volatile TaskSchedulers INSTANCE; |
|
|
|
|
private static FailureTaskHandler mFailureTaskHandler; |
|
|
|
|
|
|
|
|
|
private Map<String, Map<TaskEnum, ISchedulerListener>> mObservers = new ConcurrentHashMap<>(); |
|
|
|
|
private Map<String, Map<TaskEnum, Object>> mObservers = new ConcurrentHashMap<>(); |
|
|
|
|
private AriaConfig mAriaConfig; |
|
|
|
|
|
|
|
|
|
private TaskSchedulers() { |
|
|
|
@ -99,15 +99,19 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
*/ |
|
|
|
|
public void register(Object obj, TaskEnum taskEnum) { |
|
|
|
|
String targetName = obj.getClass().getName(); |
|
|
|
|
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(getKey(obj)); |
|
|
|
|
Map<TaskEnum, Object> listeners = mObservers.get(getKey(obj)); |
|
|
|
|
|
|
|
|
|
if (listeners == null) { |
|
|
|
|
listeners = new ConcurrentHashMap<>(); |
|
|
|
|
mObservers.put(getKey(obj), listeners); |
|
|
|
|
} |
|
|
|
|
String proxyClassName = targetName + taskEnum.proxySuffix; |
|
|
|
|
|
|
|
|
|
if (!hasProxyListener(listeners, taskEnum)) { |
|
|
|
|
if (obj instanceof BaseListenerInterface){ |
|
|
|
|
listeners.put(taskEnum, (ISchedulerListener) obj); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
String proxyClassName = targetName + taskEnum.proxySuffix; |
|
|
|
|
ISchedulerListener listener = createListener(proxyClassName); |
|
|
|
|
if (listener != null) { |
|
|
|
|
listener.setListener(obj); |
|
|
|
@ -124,7 +128,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
* @param taskEnum 代理类类型 |
|
|
|
|
* @return true,已注册代理类,false,没有注册代理类 |
|
|
|
|
*/ |
|
|
|
|
private boolean hasProxyListener(Map<TaskEnum, ISchedulerListener> listeners, TaskEnum taskEnum) { |
|
|
|
|
private boolean hasProxyListener(Map<TaskEnum, Object> listeners, TaskEnum taskEnum) { |
|
|
|
|
return !listeners.isEmpty() && listeners.get(taskEnum) != null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -137,9 +141,9 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
if (!mObservers.containsKey(getKey(obj))) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
for (Iterator<Map.Entry<String, Map<TaskEnum, ISchedulerListener>>> iter = |
|
|
|
|
for (Iterator<Map.Entry<String, Map<TaskEnum, Object>>> iter = |
|
|
|
|
mObservers.entrySet().iterator(); iter.hasNext(); ) { |
|
|
|
|
Map.Entry<String, Map<TaskEnum, ISchedulerListener>> entry = iter.next(); |
|
|
|
|
Map.Entry<String, Map<TaskEnum, Object>> entry = iter.next(); |
|
|
|
|
|
|
|
|
|
if (entry.getKey().equals(getKey(obj))) { |
|
|
|
|
iter.remove(); |
|
|
|
@ -202,12 +206,12 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
if (mObservers.size() > 0) { |
|
|
|
|
Set<String> keys = mObservers.keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); |
|
|
|
|
Map<TaskEnum, Object> listeners = mObservers.get(key); |
|
|
|
|
if (listeners == null || listeners.isEmpty()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
M3U8PeerTaskListener listener = |
|
|
|
|
(M3U8PeerTaskListener) listeners.get(TaskEnum.M3U8_PEER); |
|
|
|
|
M3U8PeerTaskListenerInterface listener = |
|
|
|
|
(M3U8PeerTaskListenerInterface) listeners.get(TaskEnum.M3U8_PEER); |
|
|
|
|
if (listener == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -250,12 +254,12 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
if (mObservers.size() > 0) { |
|
|
|
|
Set<String> keys = mObservers.keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); |
|
|
|
|
Map<TaskEnum, Object> listeners = mObservers.get(key); |
|
|
|
|
if (listeners == null || listeners.isEmpty()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
SubTaskListener<TASK, AbsNormalEntity> listener = |
|
|
|
|
(SubTaskListener<TASK, AbsNormalEntity>) listeners.get(TaskEnum.DOWNLOAD_GROUP_SUB); |
|
|
|
|
SubTaskListenerInterface<TASK, AbsNormalEntity> listener = |
|
|
|
|
(SubTaskListenerInterface<TASK, AbsNormalEntity>) listeners.get(TaskEnum.DOWNLOAD_GROUP_SUB); |
|
|
|
|
if (listener == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -368,18 +372,18 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
if (mObservers.size() > 0) { |
|
|
|
|
Set<String> keys = mObservers.keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); |
|
|
|
|
Map<TaskEnum, Object> listeners = mObservers.get(key); |
|
|
|
|
if (listeners == null || listeners.isEmpty()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
NormalTaskListener<TASK> listener = null; |
|
|
|
|
NormalTaskListenerInterface<TASK> listener = null; |
|
|
|
|
if (mObservers.get(key) != null) { |
|
|
|
|
if (taskType == ITask.DOWNLOAD) { |
|
|
|
|
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.DOWNLOAD); |
|
|
|
|
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD); |
|
|
|
|
} else if (taskType == ITask.DOWNLOAD_GROUP) { |
|
|
|
|
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP); |
|
|
|
|
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP); |
|
|
|
|
} else if (taskType == ITask.DOWNLOAD_GROUP) { |
|
|
|
|
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.UPLOAD); |
|
|
|
|
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.UPLOAD); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (listener != null) { |
|
|
|
@ -399,7 +403,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
if (mObservers.size() > 0) { |
|
|
|
|
Set<String> keys = mObservers.keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); |
|
|
|
|
Map<TaskEnum, Object> listeners = mObservers.get(key); |
|
|
|
|
if (listeners == null || listeners.isEmpty()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -420,7 +424,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void normalTaskCallback(int state, TASK task, NormalTaskListener<TASK> listener) { |
|
|
|
|
private void normalTaskCallback(int state, TASK task, NormalTaskListenerInterface<TASK> listener) { |
|
|
|
|
if (listener != null) { |
|
|
|
|
if (task == null && state != ISchedulers.CHECK_FAIL) { |
|
|
|
|
ALog.e(TAG, "TASK 为null,回调失败"); |
|
|
|
|