- 修复组任务,其中一个子任务在获取文件长度失败后,重新恢复组合任务,组合任务状态变为完成的问题 https://github.com/AriaLyy/Aria/issues/628

pull/640/head
laoyuyu 5 years ago
parent 54cbdb7ee0
commit 669ac6b09c
  1. 1
      DEV_LOG.md
  2. 22
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java
  3. 7
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java
  4. 54
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/M3U8VodLoader.java
  5. 27
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java
  6. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java
  7. 8
      PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java
  8. 31
      PublicComponent/src/main/java/com/arialyy/aria/core/group/GroupRunState.java
  9. 11
      PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java
  10. 30
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java
  11. 2
      PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  12. 4
      app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  13. 10
      app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java
  14. 3
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodModule.java
  15. 2
      build.gradle

@ -4,6 +4,7 @@
- 修复40x错误,会继续重试并且无法重试成功的问题 https://github.com/AriaLyy/Aria/issues/619 - 修复40x错误,会继续重试并且无法重试成功的问题 https://github.com/AriaLyy/Aria/issues/619
- 修复wait模式下,resume(true)无效问题 - 修复wait模式下,resume(true)无效问题
- 修复now模式下的一些问题 https://github.com/AriaLyy/Aria/issues/620 - 修复now模式下的一些问题 https://github.com/AriaLyy/Aria/issues/620
- 修复组任务,其中一个子任务在获取文件长度失败后,重新恢复组合任务,组合任务状态变为完成的问题 https://github.com/AriaLyy/Aria/issues/628
+ v_3.8.6 (2020/2/17) + v_3.8.6 (2020/2/17)
- fix bug https://github.com/AriaLyy/Aria/issues/608 - fix bug https://github.com/AriaLyy/Aria/issues/608
- fix bug https://github.com/AriaLyy/Aria/issues/579#issuecomment-586665035 - fix bug https://github.com/AriaLyy/Aria/issues/579#issuecomment-586665035

@ -30,6 +30,7 @@ import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* 组合任务文件信息用于获取长度未知时组合任务的长度 * 组合任务文件信息用于获取长度未知时组合任务的长度
@ -41,8 +42,8 @@ public final class HttpDGInfoTask implements IInfoTask {
private final Object LOCK = new Object(); private final Object LOCK = new Object();
private ExecutorService mPool = null; private ExecutorService mPool = null;
private boolean getLenComplete = false; private boolean getLenComplete = false;
private int count; private AtomicInteger count = new AtomicInteger();
private int failCount; private AtomicInteger failCount = new AtomicInteger();
private DownloadGroupListener listener; private DownloadGroupListener listener;
/** /**
@ -50,18 +51,18 @@ public final class HttpDGInfoTask implements IInfoTask {
*/ */
private Callback subCallback = new Callback() { private Callback subCallback = new Callback() {
@Override public void onSucceed(String url, CompleteInfo info) { @Override public void onSucceed(String url, CompleteInfo info) {
count++; count.getAndIncrement();
checkGetSizeComplete(count, failCount); checkGetSizeComplete(count.get(), failCount.get());
ALog.d(TAG, "获取子任务信息完成"); ALog.d(TAG, "获取子任务信息完成");
} }
@Override public void onFail(AbsEntity entity, AriaException e, boolean needRetry) { @Override public void onFail(AbsEntity entity, AriaException e, boolean needRetry) {
ALog.e(TAG, String.format("获取文件信息失败,url:%s", ((DownloadEntity) entity).getUrl())); ALog.e(TAG, String.format("获取文件信息失败,url:%s", ((DownloadEntity) entity).getUrl()));
count++; count.getAndIncrement();
failCount++; failCount.getAndIncrement();
listener.onSubFail((DownloadEntity) entity, new AriaHTTPException(TAG, listener.onSubFail((DownloadEntity) entity, new AriaHTTPException(TAG,
String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl()))); String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl())));
checkGetSizeComplete(count, failCount); checkGetSizeComplete(count.get(), failCount.get());
} }
}; };
@ -79,7 +80,7 @@ public final class HttpDGInfoTask implements IInfoTask {
return; return;
} }
// 处理组合任务大小未知的情况 // 处理组合任务大小未知的情况
if (wrapper.isUnknownSize() && wrapper.getEntity().getFileSize() < 1) { if (wrapper.isUnknownSize()) {
mPool = Executors.newCachedThreadPool(); mPool = Executors.newCachedThreadPool();
getGroupSize(); getGroupSize();
try { try {
@ -107,6 +108,10 @@ public final class HttpDGInfoTask implements IInfoTask {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override public void run() { @Override public void run() {
for (DTaskWrapper dTaskWrapper : wrapper.getSubTaskWrapper()) { for (DTaskWrapper dTaskWrapper : wrapper.getSubTaskWrapper()) {
if (dTaskWrapper.getEntity().getFileSize() > 0) {
count.getAndIncrement();
continue;
}
cloneHeader(dTaskWrapper); cloneHeader(dTaskWrapper);
HttpDFileInfoTask infoTask = new HttpDFileInfoTask(dTaskWrapper); HttpDFileInfoTask infoTask = new HttpDFileInfoTask(dTaskWrapper);
infoTask.setCallback(subCallback); infoTask.setCallback(subCallback);
@ -158,7 +163,6 @@ public final class HttpDGInfoTask implements IInfoTask {
subOption.setFileNameAdapter(groupOption.getFileNameAdapter()); subOption.setFileNameAdapter(groupOption.getFileNameAdapter());
subOption.setUseServerFileName(groupOption.isUseServerFileName()); subOption.setUseServerFileName(groupOption.isUseServerFileName());
subOption.setFileNameAdapter(groupOption.getFileNameAdapter()); subOption.setFileNameAdapter(groupOption.getFileNameAdapter());
subOption.setRequestEnum(groupOption.getRequestEnum()); subOption.setRequestEnum(groupOption.getRequestEnum());
subOption.setHeaders(groupOption.getHeaders()); subOption.setHeaders(groupOption.getHeaders());

@ -26,6 +26,7 @@ import com.arialyy.aria.core.listener.DownloadGroupListener;
import com.arialyy.aria.core.loader.IInfoTask; import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.AriaException; import com.arialyy.aria.exception.AriaException;
import java.io.File;
/** /**
* http 组合任务加载器 * http 组合任务加载器
@ -53,6 +54,12 @@ final class HttpDGLoader extends AbsGroupLoader {
} }
onPostStart(); onPostStart();
for (DTaskWrapper wrapper : getWrapper().getSubTaskWrapper()) { for (DTaskWrapper wrapper : getWrapper().getSubTaskWrapper()) {
File subFile = new File(wrapper.getEntity().getFilePath());
if (wrapper.getEntity().getFileSize() > 0
&& subFile.exists()
&& subFile.length() == wrapper.getEntity().getFileSize()) {
continue;
}
DownloadEntity dEntity = wrapper.getEntity(); DownloadEntity dEntity = wrapper.getEntity();
startSubLoader(createSubLoader(wrapper, dEntity.getFileSize() < 0)); startSubLoader(createSubLoader(wrapper, dEntity.getFileSize() < 0));
} }

@ -51,6 +51,7 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -75,10 +76,11 @@ final class M3U8VodLoader extends BaseM3U8Loader {
private SparseArray<ThreadRecord> mAfterPeer = new SparseArray<>(); private SparseArray<ThreadRecord> mAfterPeer = new SparseArray<>();
private PeerIndexEvent mCurrentEvent; private PeerIndexEvent mCurrentEvent;
private String mCacheDir; private String mCacheDir;
private int aIndex = 0, bIndex = 0; private AtomicInteger afterPeerIndex = new AtomicInteger();
private int mCurrentFlagSize; private AtomicInteger beforePeerIndex = new AtomicInteger();
private AtomicInteger mCompleteNum = new AtomicInteger();
private AtomicInteger mCurrentFlagSize = new AtomicInteger();
private boolean isJump = false, isDestroy = false; private boolean isJump = false, isDestroy = false;
private int mCompleteNum = 0;
private ExecutorService mJumpThreadPool; private ExecutorService mJumpThreadPool;
private Thread jumpThread = null; private Thread jumpThread = null;
private M3U8TaskOption mM3U8Option; private M3U8TaskOption mM3U8Option;
@ -102,20 +104,20 @@ final class M3U8VodLoader extends BaseM3U8Loader {
} }
int getCompleteNum() { int getCompleteNum() {
return mCompleteNum; return mCompleteNum.get();
} }
void setCompleteNum(int mCompleteNum) { void setCompleteNum(int completeNum) {
this.mCompleteNum = mCompleteNum; mCompleteNum.set(completeNum);
} }
int getCurrentFlagSize() { int getCurrentFlagSize() {
mCurrentFlagSize = mFlagQueue.size(); mCurrentFlagSize.set(mFlagQueue.size());
return mCurrentFlagSize; return mCurrentFlagSize.get();
} }
void setCurrentFlagSize(int currentFlagSize) { void setCurrentFlagSize(int currentFlagSize) {
mCurrentFlagSize = currentFlagSize; mCurrentFlagSize.set(currentFlagSize);
} }
boolean isJump() { boolean isJump() {
@ -178,7 +180,7 @@ final class M3U8VodLoader extends BaseM3U8Loader {
try { try {
LOCK.lock(); LOCK.lock();
while (mFlagQueue.size() < EXEC_MAX_NUM && !isBreak()) { while (mFlagQueue.size() < EXEC_MAX_NUM && !isBreak()) {
if (mCompleteNum == mRecord.threadRecords.size()) { if (mCompleteNum.get() == mRecord.threadRecords.size()) {
break; break;
} }
@ -214,16 +216,18 @@ final class M3U8VodLoader extends BaseM3U8Loader {
ThreadRecord tr = null; ThreadRecord tr = null;
try { try {
// 优先下载peer指针之后的数据 // 优先下载peer指针之后的数据
if (bIndex == 0 && aIndex < mAfterPeer.size()) { if (beforePeerIndex.get() == 0 && afterPeerIndex.get() < mAfterPeer.size()) {
//ALog.d(TAG, String.format("afterArray size:%s, index:%s", mAfterPeer.size(), aIndex)); //ALog.d(TAG, String.format("afterArray size:%s, index:%s", mAfterPeer.size(), aIndex));
tr = mAfterPeer.valueAt(aIndex); tr = mAfterPeer.valueAt(afterPeerIndex.get());
aIndex++; afterPeerIndex.getAndIncrement();
} }
// 如果指针之后的数组没有切片了,则重新初始化指针位置,并获取指针之前的数组获取切片进行下载 // 如果指针之后的数组没有切片了,则重新初始化指针位置,并获取指针之前的数组获取切片进行下载
if (mBeforePeer.size() > 0 && (tr == null || bIndex != 0) && bIndex < mBeforePeer.size()) { if (mBeforePeer.size() > 0
tr = mBeforePeer.valueAt(bIndex); && (tr == null || beforePeerIndex.get() != 0)
bIndex++; && beforePeerIndex.get() < mBeforePeer.size()) {
tr = mBeforePeer.valueAt(beforePeerIndex.get());
beforePeerIndex.getAndIncrement();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -256,19 +260,19 @@ final class M3U8VodLoader extends BaseM3U8Loader {
return; return;
} }
// 设置需要下载的切片 // 设置需要下载的切片
mCompleteNum = 0; mCompleteNum.set(0);
for (ThreadRecord tr : mRecord.threadRecords) { for (ThreadRecord tr : mRecord.threadRecords) {
if (!tr.isComplete) { if (!tr.isComplete) {
mAfterPeer.put(tr.threadId, tr); mAfterPeer.put(tr.threadId, tr);
} else { } else {
mCompleteNum++; mCompleteNum.getAndIncrement();
} }
} }
getStateManager().updateStateCount(); getStateManager().updateStateCount();
if (mCompleteNum <= 0) { if (mCompleteNum.get() <= 0) {
getListener().onStart(0); getListener().onStart(0);
} else { } else {
int percent = mCompleteNum * 100 / mRecord.threadRecords.size(); int percent = mCompleteNum.get() * 100 / mRecord.threadRecords.size();
getListener().onResume(percent); getListener().onResume(percent);
} }
} }
@ -329,7 +333,7 @@ final class M3U8VodLoader extends BaseM3U8Loader {
isJump = true; isJump = true;
notifyWaitLock(false); notifyWaitLock(false);
mCurrentFlagSize = mFlagQueue.size(); mCurrentFlagSize.set(mFlagQueue.size());
// 停止所有正在执行的线程任务 // 停止所有正在执行的线程任务
try { try {
TempFlag flag; TempFlag flag;
@ -403,12 +407,12 @@ final class M3U8VodLoader extends BaseM3U8Loader {
mBeforePeer.clear(); mBeforePeer.clear();
mAfterPeer.clear(); mAfterPeer.clear();
mFlagQueue.clear(); mFlagQueue.clear();
aIndex = 0; afterPeerIndex.set(0);
bIndex = 0; beforePeerIndex.set(0);
mCompleteNum = 0; mCompleteNum.set(0);
for (ThreadRecord tr : mRecord.threadRecords) { for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) { if (tr.isComplete) {
mCompleteNum++; mCompleteNum.getAndIncrement();
continue; continue;
} }
if (tr.threadId < mCurrentEvent.peerIndex) { if (tr.threadId < mCurrentEvent.peerIndex) {

@ -29,8 +29,8 @@ import com.arialyy.aria.core.loader.ILoaderVisitor;
import com.arialyy.aria.core.manager.ThreadTaskManager; import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.processor.ITsMergeHandler; import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.task.ThreadTask; import com.arialyy.aria.core.task.ThreadTask;
import com.arialyy.aria.exception.AriaM3U8Exception;
import com.arialyy.aria.exception.AriaException; import com.arialyy.aria.exception.AriaException;
import com.arialyy.aria.exception.AriaM3U8Exception;
import com.arialyy.aria.m3u8.BaseM3U8Loader; import com.arialyy.aria.m3u8.BaseM3U8Loader;
import com.arialyy.aria.m3u8.M3U8Listener; import com.arialyy.aria.m3u8.M3U8Listener;
import com.arialyy.aria.m3u8.M3U8TaskOption; import com.arialyy.aria.m3u8.M3U8TaskOption;
@ -40,6 +40,7 @@ import com.arialyy.aria.util.FileUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* m3u8 点播下载状态管理器 * m3u8 点播下载状态管理器
@ -49,9 +50,9 @@ public final class VodStateManager implements IThreadStateManager {
private M3U8Listener listener; private M3U8Listener listener;
private int startThreadNum; // 启动的线程总数 private int startThreadNum; // 启动的线程总数
private int cancelNum = 0; // 已经取消的线程的数 private AtomicInteger cancelNum = new AtomicInteger(0); // 已经取消的线程的数
private int stopNum = 0; // 已经停止的线程数 private AtomicInteger stopNum = new AtomicInteger(0); // 已经停止的线程数
private int failNum = 0; // 失败的线程数 private AtomicInteger failNum = new AtomicInteger(0); // 失败的线程数
private long progress; private long progress;
private TaskRecord taskRecord; // 任务记录 private TaskRecord taskRecord; // 任务记录
private Looper looper; private Looper looper;
@ -74,11 +75,11 @@ public final class VodStateManager implements IThreadStateManager {
int peerIndex = msg.getData().getInt(ISchedulers.DATA_M3U8_PEER_INDEX); int peerIndex = msg.getData().getInt(ISchedulers.DATA_M3U8_PEER_INDEX);
switch (msg.what) { switch (msg.what) {
case STATE_STOP: case STATE_STOP:
stopNum++; stopNum.getAndIncrement();
removeSignThread((ThreadTask) msg.obj); removeSignThread((ThreadTask) msg.obj);
// 处理跳转位置后,恢复任务 // 处理跳转位置后,恢复任务
if (loader.isJump() if (loader.isJump()
&& (stopNum == loader.getCurrentFlagSize() || loader.getCurrentFlagSize() == 0) && (stopNum.get() == loader.getCurrentFlagSize() || loader.getCurrentFlagSize() == 0)
&& !loader.isBreak()) { && !loader.isBreak()) {
loader.resumeTask(); loader.resumeTask();
return true; return true;
@ -90,7 +91,7 @@ public final class VodStateManager implements IThreadStateManager {
} }
break; break;
case STATE_CANCEL: case STATE_CANCEL:
cancelNum++; cancelNum.getAndIncrement();
removeSignThread((ThreadTask) msg.obj); removeSignThread((ThreadTask) msg.obj);
if (loader.isBreak()) { if (loader.isBreak()) {
@ -99,7 +100,7 @@ public final class VodStateManager implements IThreadStateManager {
} }
break; break;
case STATE_FAIL: case STATE_FAIL:
failNum++; failNum.getAndIncrement();
for (ThreadRecord tr : taskRecord.threadRecords) { for (ThreadRecord tr : taskRecord.threadRecords) {
if (tr.threadId == peerIndex) { if (tr.threadId == peerIndex) {
loader.getBeforePeer().put(peerIndex, tr); loader.getBeforePeer().put(peerIndex, tr);
@ -175,9 +176,9 @@ public final class VodStateManager implements IThreadStateManager {
}; };
void updateStateCount() { void updateStateCount() {
cancelNum = 0; cancelNum.set(0);
stopNum = 0; stopNum.set(0);
failNum = 0; failNum.set(0);
} }
@Override public void setLooper(TaskRecord taskRecord, Looper looper) { @Override public void setLooper(TaskRecord taskRecord, Looper looper) {
@ -233,12 +234,12 @@ public final class VodStateManager implements IThreadStateManager {
@Override public boolean isFail() { @Override public boolean isFail() {
printInfo("isFail"); printInfo("isFail");
return failNum != 0 && failNum == loader.getCurrentFlagSize() && !loader.isJump(); return failNum.get() != 0 && failNum.get() == loader.getCurrentFlagSize() && !loader.isJump();
} }
@Override public boolean isComplete() { @Override public boolean isComplete() {
if (m3U8Option.isIgnoreFailureTs()) { if (m3U8Option.isIgnoreFailureTs()) {
return loader.getCompleteNum() + failNum >= taskRecord.threadRecords.size() return loader.getCompleteNum() + failNum.get() >= taskRecord.threadRecords.size()
&& !loader.isJump(); && !loader.isJump();
} else { } else {
return loader.getCompleteNum() == taskRecord.threadRecords.size() && !loader.isJump(); return loader.getCompleteNum() == taskRecord.threadRecords.size() && !loader.isJump();

@ -163,8 +163,10 @@ public class RecordHelper {
// 目标文件 // 目标文件
File targetFile = new File(mTaskRecord.filePath); File targetFile = new File(mTaskRecord.filePath);
// 处理组合任务其中一个子任务完成的情况 // 处理组合任务其中一个子任务完成的情况
if (tr.isComplete && targetFile.exists() && targetFile.length() == mWrapper.getEntity() if (tr.isComplete
.getFileSize()) { && targetFile.exists()
&& targetFile.length() != 0
&& targetFile.length() == mWrapper.getEntity().getFileSize()) {
tr.isComplete = true; tr.isComplete = true;
} else { } else {
ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath())); ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath()));

@ -153,7 +153,7 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
if (!checkSubTask(url, "开始")) { if (!checkSubTask(url, "开始")) {
return; return;
} }
if (!mState.isRunning) { if (!mState.isRunning.get()) {
startTimer(); startTimer();
} }
AbsSubDLoadUtil d = getDownloader(url, false); AbsSubDLoadUtil d = getDownloader(url, false);
@ -212,7 +212,7 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
} }
@Override public boolean isRunning() { @Override public boolean isRunning() {
return mState != null && mState.isRunning; return mState != null && mState.isRunning.get();
} }
@Override public void cancel() { @Override public void cancel() {
@ -275,11 +275,11 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
} }
private synchronized void startTimer() { private synchronized void startTimer() {
mState.isRunning = true; mState.isRunning.set(true);
mTimer = new ScheduledThreadPoolExecutor(1); mTimer = new ScheduledThreadPoolExecutor(1);
mTimer.scheduleWithFixedDelay(new Runnable() { mTimer.scheduleWithFixedDelay(new Runnable() {
@Override public void run() { @Override public void run() {
if (!mState.isRunning) { if (!mState.isRunning.get()) {
closeTimer(); closeTimer();
} else if (mCurrentLocation >= 0) { } else if (mCurrentLocation >= 0) {
long t = 0; long t = 0;

@ -19,6 +19,8 @@ import com.arialyy.aria.core.listener.IDGroupListener;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* 组合任务执行中的状态信息 * 组合任务执行中的状态信息
@ -32,17 +34,18 @@ public final class GroupRunState {
/** /**
* 已经完成的任务数 * 已经完成的任务数
*/ */
private int mCompleteNum; private AtomicInteger mCompleteNum = new AtomicInteger();
/** /**
* 失败的任务数 * 失败的任务数
*/ */
private int mFailNum; private AtomicInteger mFailNum = new AtomicInteger();
/** /**
* 停止的任务数 * 停止的任务数
*/ */
private int mStopNum; private AtomicInteger mStopNum = new AtomicInteger();
;
/** /**
* 当前进度 * 当前进度
@ -62,7 +65,7 @@ public final class GroupRunState {
/** /**
* 是否在执行 * 是否在执行
*/ */
boolean isRunning = false; AtomicBoolean isRunning = new AtomicBoolean(false);
/** /**
* 子任务失败停止记录用于当子任务失败重新被用户点击开始时更新{@link #mStopNum}{@link #mFailNum} * 子任务失败停止记录用于当子任务失败重新被用户点击开始时更新{@link #mStopNum}{@link #mFailNum}
@ -88,11 +91,11 @@ public final class GroupRunState {
* @return {@code true}组合任务正在执行 * @return {@code true}组合任务正在执行
*/ */
public boolean isRunning() { public boolean isRunning() {
return isRunning; return isRunning.get();
} }
public void setRunning(boolean running) { public void setRunning(boolean running) {
isRunning = running; isRunning.set(running);
} }
String getGroupHash() { String getGroupHash() {
@ -110,21 +113,21 @@ public final class GroupRunState {
* 获取失败的数量 * 获取失败的数量
*/ */
public int getFailNum() { public int getFailNum() {
return mFailNum; return mFailNum.get();
} }
/** /**
* 获取停止的数量 * 获取停止的数量
*/ */
public int getStopNum() { public int getStopNum() {
return mStopNum; return mStopNum.get();
} }
/** /**
* 获取完成的数量 * 获取完成的数量
*/ */
public int getCompleteNum() { public int getCompleteNum() {
return mCompleteNum; return mCompleteNum.get();
} }
/** /**
@ -138,7 +141,7 @@ public final class GroupRunState {
* 更新完成的数量mCompleteNum + 1 * 更新完成的数量mCompleteNum + 1
*/ */
public void updateCompleteNum() { public void updateCompleteNum() {
mCompleteNum++; mCompleteNum.getAndIncrement();
} }
/** /**
@ -156,10 +159,10 @@ public final class GroupRunState {
public void updateCount(String key) { public void updateCount(String key) {
if (mFailTemp.contains(key)) { if (mFailTemp.contains(key)) {
mFailTemp.remove(key); mFailTemp.remove(key);
mFailNum--; mFailNum.getAndDecrement();
} else if (mStopTemp.contains(key)) { } else if (mStopTemp.contains(key)) {
mStopTemp.remove(key); mStopTemp.remove(key);
mStopNum--; mStopNum.getAndDecrement();
} }
} }
@ -170,7 +173,7 @@ public final class GroupRunState {
*/ */
public void countStopNum(String key) { public void countStopNum(String key) {
mStopTemp.add(key); mStopTemp.add(key);
mStopNum++; mStopNum.getAndIncrement();
} }
/** /**
@ -180,6 +183,6 @@ public final class GroupRunState {
*/ */
public void countFailNum(String key) { public void countFailNum(String key) {
mFailTemp.add(key); mFailTemp.add(key);
mFailNum++; mFailNum.getAndIncrement();
} }
} }

@ -121,9 +121,14 @@ final class SimpleSchedulers implements Handler.Callback {
|| mGState.getStopNum() + mGState.getFailNum() + mGState.getCompleteNum() || mGState.getStopNum() + mGState.getFailNum() + mGState.getCompleteNum()
== mGState.getSubSize()) { == mGState.getSubSize()) {
mQueue.clear(); mQueue.clear();
mGState.isRunning = false; mGState.isRunning.set(false);
if (mGState.getCompleteNum() > 0) {
ALog.e(TAG, String.format("任务组【%s】停止", mGState.getGroupHash()));
mGState.listener.onStop(mGState.getProgress());
} else {
mGState.listener.onFail(false, new AriaException(TAG, mGState.listener.onFail(false, new AriaException(TAG,
String.format("任务组【%s】下载失败", mGState.getGroupHash()))); String.format("任务组【%s】下载失败", mGState.getGroupHash())));
}
} else { } else {
startNext(); startNext();
} }
@ -147,7 +152,7 @@ final class SimpleSchedulers implements Handler.Callback {
+ mQueue.getCacheSize() + mQueue.getCacheSize()
== mGState.getSubSize()) { == mGState.getSubSize()) {
mQueue.clear(); mQueue.clear();
mGState.isRunning = false; mGState.isRunning.set(false);
mGState.listener.onStop(mGState.getProgress()); mGState.listener.onStop(mGState.getProgress());
} else { } else {
startNext(); startNext();
@ -183,7 +188,7 @@ final class SimpleSchedulers implements Handler.Callback {
mGState.listener.onStop(mGState.getProgress()); mGState.listener.onStop(mGState.getProgress());
} }
mQueue.clear(); mQueue.clear();
mGState.isRunning = false; mGState.isRunning.set(false);
} else { } else {
startNext(); startNext();
} }

@ -24,26 +24,28 @@ import com.arialyy.aria.core.inf.IThreadStateManager;
import com.arialyy.aria.core.listener.IEventListener; import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.exception.AriaException; import com.arialyy.aria.exception.AriaException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.FileUtil; import com.arialyy.aria.util.FileUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* 线程任务管理器用于处理多线程下载时任务的状态回调 * 线程任务管理器用于处理多线程下载时任务的状态回调
*/ */
public class NormalThreadStateManager implements IThreadStateManager { public class NormalThreadStateManager implements IThreadStateManager {
private final String TAG = "ThreadTaskStateManager"; private final String TAG = CommonUtil.getClassName(this);
/** /**
* 任务状态回调 * 任务状态回调
*/ */
private IEventListener mListener; private IEventListener mListener;
private int mThreadNum; // 启动的线程总数 private int mThreadNum; // 启动的线程总数
private int mCancelNum = 0; // 已经取消的线程的数 private AtomicInteger mCancelNum = new AtomicInteger(0); // 已经取消的线程的数
private int mStopNum = 0; // 已经停止的线程数 private AtomicInteger mStopNum = new AtomicInteger(0); // 已经停止的线程数
private int mFailNum = 0; // 失败的线程数 private AtomicInteger mFailNum = new AtomicInteger(0); // 失败的线程数
private int mCompleteNum = 0; // 完成的线程数 private AtomicInteger mCompleteNum = new AtomicInteger(0); // 完成的线程数
private long mProgress; //当前总进度 private long mProgress; //当前总进度
private TaskRecord mTaskRecord; // 任务记录 private TaskRecord mTaskRecord; // 任务记录
private Looper mLooper; private Looper mLooper;
@ -75,19 +77,19 @@ public class NormalThreadStateManager implements IThreadStateManager {
checkLooper(); checkLooper();
switch (msg.what) { switch (msg.what) {
case STATE_STOP: case STATE_STOP:
mStopNum++; mStopNum.getAndIncrement();
if (isStop()) { if (isStop()) {
quitLooper(); quitLooper();
} }
break; break;
case STATE_CANCEL: case STATE_CANCEL:
mCancelNum++; mCancelNum.getAndIncrement();
if (isCancel()) { if (isCancel()) {
quitLooper(); quitLooper();
} }
break; break;
case STATE_FAIL: case STATE_FAIL:
mFailNum++; mFailNum.getAndIncrement();
if (isFail()) { if (isFail()) {
Bundle b = msg.getData(); Bundle b = msg.getData();
mListener.onFail(b.getBoolean(DATA_RETRY, false), mListener.onFail(b.getBoolean(DATA_RETRY, false),
@ -96,7 +98,7 @@ public class NormalThreadStateManager implements IThreadStateManager {
} }
break; break;
case STATE_COMPLETE: case STATE_COMPLETE:
mCompleteNum++; mCompleteNum.getAndIncrement();
if (isComplete()) { if (isComplete()) {
ALog.d(TAG, "isComplete, completeNum = " + mCompleteNum); ALog.d(TAG, "isComplete, completeNum = " + mCompleteNum);
//if (mTaskRecord.taskType == ITaskWrapper.D_SFTP) { //if (mTaskRecord.taskType == ITaskWrapper.D_SFTP) {
@ -168,7 +170,7 @@ public class NormalThreadStateManager implements IThreadStateManager {
//ALog.d(TAG, //ALog.d(TAG,
// String.format("isStop; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s", mStopNum, // String.format("isStop; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s", mStopNum,
// mCancelNum, mFailNum, mCompleteNum)); // mCancelNum, mFailNum, mCompleteNum));
return mStopNum == mThreadNum || mStopNum + mCompleteNum == mThreadNum; return mStopNum.get() == mThreadNum || mStopNum.get() + mCompleteNum.get() == mThreadNum;
} }
/** /**
@ -179,8 +181,8 @@ public class NormalThreadStateManager implements IThreadStateManager {
//ALog.d(TAG, //ALog.d(TAG,
// String.format("isFail; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s", mStopNum, // String.format("isFail; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s", mStopNum,
// mCancelNum, mFailNum, mCompleteNum)); // mCancelNum, mFailNum, mCompleteNum));
return mCompleteNum != mThreadNum return mCompleteNum.get() != mThreadNum
&& (mFailNum == mThreadNum || mFailNum + mCompleteNum == mThreadNum); && (mFailNum.get() == mThreadNum || mFailNum.get() + mCompleteNum.get() == mThreadNum);
} }
/** /**
@ -192,7 +194,7 @@ public class NormalThreadStateManager implements IThreadStateManager {
// String.format("isComplete; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s", // String.format("isComplete; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s",
// mStopNum, // mStopNum,
// mCancelNum, mFailNum, mCompleteNum)); // mCancelNum, mFailNum, mCompleteNum));
return mCompleteNum == mThreadNum; return mCompleteNum.get() == mThreadNum;
} }
/** /**
@ -202,7 +204,7 @@ public class NormalThreadStateManager implements IThreadStateManager {
//ALog.d(TAG, String.format("isCancel; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s", //ALog.d(TAG, String.format("isCancel; stopNum: %s, cancelNum: %s, failNum: %s, completeNum: %s",
// mStopNum, // mStopNum,
// mCancelNum, mFailNum, mCompleteNum)); // mCancelNum, mFailNum, mCompleteNum));
return mCancelNum == mThreadNum; return mCancelNum.get() == mThreadNum;
} }
/** /**

@ -98,7 +98,7 @@ class DelegateFind extends AbsDelegate {
*/ */
<T extends AbsDbWrapper> List<T> findRelationData(SQLiteDatabase db, Class<T> clazz, <T extends AbsDbWrapper> List<T> findRelationData(SQLiteDatabase db, Class<T> clazz,
String... expression) { String... expression) {
return exeRelationSql(db, clazz, 1, 10, expression); return exeRelationSql(db, clazz, 1, Integer.MAX_VALUE, expression);
} }
/** /**

@ -89,7 +89,9 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
} }
@Override public void resume(View v, AbsEntity entity) { @Override public void resume(View v, AbsEntity entity) {
Aria.download(this).loadGroup(mTaskId).resume(); Aria.download(this).loadGroup(mTaskId)
.unknownSize()
.resume(true);
} }
@Override public void cancel(View v, AbsEntity entity) { @Override public void cancel(View v, AbsEntity entity) {

@ -36,11 +36,11 @@ public class GroupModule extends BaseModule {
//urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574141924272&di=7861479e7cb3cea98d585eaf108f056f&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F562c11dfa9ec8a13c0741f5afd03918fa0ecc01a.jpg"); //urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574141924272&di=7861479e7cb3cea98d585eaf108f056f&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F562c11dfa9ec8a13c0741f5afd03918fa0ecc01a.jpg");
//String[] str = getContext().getResources().getStringArray(R.array.group_urls_1); //String[] str = getContext().getResources().getStringArray(R.array.group_urls_1);
//Collections.addAll(urls, str); //Collections.addAll(urls, str);
urls.add("http://img2.imgtn.bdimg.com/it/u=3105600238,693167464&fm=26&gp=0.jpg"); urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-9/fr/cp0/e15/q65/85148967_168821394550033_6164348723502514176_n.jpg?_nc_cat=105&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQni9wIDOcxkQGfqH7jFwLuRWV3cIi0We11MXp1V0_vfrQ3-SBV4Ue034aJXzzIzdNI&_nc_ht=scontent-hkt1-1.xx&_nc_tp=14&oh=37829bbfd4f7179fcc3527a7a7971f53&oe=5F00FC35");
urls.add("http://a4.att.hudong.com/22/59/19300001325156131228593878903.jpg"); urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-0/cp0/e15/q65/p480x480/84206444_168821471216692_7979166053252988928_n.jpg?_nc_cat=106&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQny1ZTkxw-sq4mSH2TThaQNRJB89uKG2cW9e3DgcI78qXE7b8Jlyox749lXkcngYBs&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=6714e2c9b3d76e12eff960b6aa22cdfb&oe=5EEE640F");
urls.add("http://pic1.win4000.com/mobile/2019-12-16/5df71dc866a0c.jpg"); urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-0/cp0/e15/q65/p480x480/86702402_168821534550019_6064732312896012288_n.jpg?_nc_cat=101&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQnfJfW55cqVfs0lzZOjEa8kGoxvrA--\\brjaelZgcf8MzqQUhjH3moqGoekMQlATXRM&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=96f4f776c05b2c200cfb720fa36f938b&oe=5EFA310D");
urls.add("http://pics4.baidu.com/feed/e824b899a9014c08545e5585620d360e7bf4f421.jpeg"); urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-0/cp0/e15/q65/p480x480/85236032_168821577883348_2800973234302877696_n.jpg?_nc_cat=106&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQlNvaTlYUspquMWBLnkgVOHdzG4pX2XW3NSHYxvVYsaJF8Ehy9tGn6R6Ned5UwcwAM&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=6fd5e6442712e4da111d09e8902c68c5&oe=5EFE1528");
urls.add("http://img.blog.163.com/photo/iFUKcs6shB4PNlfxwH-yTw==/2542563464627686395.jpg"); urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-1/cp0/e15/q65/p120x120/80398195_141232180642288_3692820603451998208_n.jpg?_nc_cat=109&_nc_sid=dbb9e7&efg=eyJpIjoidCJ9&_nc_oc=AQmsZxgvLgoObkqHbcKS8qIZ3w_QhssRwLSF5o-8P6q_kf962w32kmjLqcg6lH9qxWI&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=269e655e7b901e8d07d9362142a0fdda&oe=5EF43734");
return urls; return urls;
} }

@ -39,7 +39,8 @@ public class M3U8VodModule extends BaseViewModule {
//private final String defUrl = "https://youku.cdn7-okzy.com/20191213/16167_c3592a02/index.m3u8"; //private final String defUrl = "https://youku.cdn7-okzy.com/20191213/16167_c3592a02/index.m3u8";
//private final String defUrl = "http://qn.shytong.cn/b83137769ff6b555/11b0c9970f9a3fa0.mp4.m3u8"; //private final String defUrl = "http://qn.shytong.cn/b83137769ff6b555/11b0c9970f9a3fa0.mp4.m3u8";
//private final String defUrl = "https://135zyv5.xw0371.com/2018/10/29/X05c7CG3VB91gi1M/playlist.m3u8"; //private final String defUrl = "https://135zyv5.xw0371.com/2018/10/29/X05c7CG3VB91gi1M/playlist.m3u8";
private final String defUrl = "https://fangao.qfxmj.com/video/20191111/dbf7e2aa0c5f42a8b040442b54c13e3a/cloudv-transfer/555555556nr593o75556r165q86n82n0_eb3da35b8f4442808756a6ddc8ec1372_0_3.m3u8?wsSecret=d5fb403512d4cd427f18858086b35ce4&wsTime=1582197537"; //private final String defUrl = "https://fangao.qfxmj.com/video/20191111/dbf7e2aa0c5f42a8b040442b54c13e3a/cloudv-transfer/555555556nr593o75556r165q86n82n0_eb3da35b8f4442808756a6ddc8ec1372_0_3.m3u8?wsSecret=d5fb403512d4cd427f18858086b35ce4&wsTime=1582197537";
private final String defUrl = "https://v1.szjal.cn/20190819/Ql6UD1od/index.m3u8";
private final String filePath = private final String filePath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
//+ "/道士下山.ts"; //+ "/道士下山.ts";

@ -45,7 +45,7 @@ task clean(type: Delete) {
ext { ext {
versionCode = 387 versionCode = 387
versionName = '3.8.7-beta-1' versionName = '3.8.7-beta-4'
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = versionName publishVersion = versionName

Loading…
Cancel
Save