修复创建唯一id可能出现的问题

v3.7
laoyuyu 5 years ago
parent 9951f04bf6
commit 43915ad204
  1. 6
      Aria/src/main/java/com/arialyy/aria/core/common/controller/ControllerType.java
  2. 11
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java
  3. 11
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirStartTarget.java
  4. 3
      Aria/src/main/java/com/arialyy/aria/util/IdGenerator.java
  5. 5
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  6. 2
      build.gradle

@ -19,6 +19,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.SOURCE) public @interface ControllerType { @Retention(RetentionPolicy.SOURCE) public @interface ControllerType {
/**
* 仅用于第一次创建任务后续可调用`#start()#add()#setHighestPriority()`方法
*/
Class<StartController> START_CONTROLLER = StartController.class; Class<StartController> START_CONTROLLER = StartController.class;
/**
* 用于后续的任务控制后续可调用`#stop()#resume()#cancel()#cancel(boolean)#retry()#restart()`方法
*/
Class<NormalController> NORMAL_CONTROLLER = NormalController.class; Class<NormalController> NORMAL_CONTROLLER = NormalController.class;
} }

@ -19,6 +19,7 @@ import android.support.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate; import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -77,4 +78,14 @@ public class FtpDirNormalTarget extends AbsNormalTarget<FtpDirNormalTarget> {
@Override public DownloadGroupEntity getEntity() { @Override public DownloadGroupEntity getEntity() {
return (DownloadGroupEntity) super.getEntity(); return (DownloadGroupEntity) super.getEntity();
} }
/**
* 获取子任务管理器
*
* @return 子任务管理器
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public SubTaskManager getSubTaskManager() {
return mConfigHandler.getSubTaskManager();
}
} }

@ -19,6 +19,7 @@ import android.support.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsStartTarget; import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate; import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -79,4 +80,14 @@ public class FtpDirStartTarget extends AbsStartTarget<FtpDirStartTarget> {
@Override public DownloadGroupEntity getEntity() { @Override public DownloadGroupEntity getEntity() {
return (DownloadGroupEntity) super.getEntity(); return (DownloadGroupEntity) super.getEntity();
} }
/**
* 获取子任务管理器
*
* @return 子任务管理器
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public SubTaskManager getSubTaskManager() {
return mConfigHandler.getSubTaskManager();
}
} }

@ -51,7 +51,8 @@ public class IdGenerator {
public synchronized long nextId() { public synchronized long nextId() {
long ts = timeGen(); long ts = timeGen();
if (ts < lastTs) {// 刚刚生成的时间戳比上次的时间戳还小,出错 if (ts < lastTs) {// 刚刚生成的时间戳比上次的时间戳还小,出错
throw new RuntimeException("时间戳顺序错误"); //throw new RuntimeException("时间戳顺序错误");
ts = nextTs(lastTs);
} }
if (ts == lastTs) {// 刚刚生成的时间戳跟上次的时间戳一样,则需要生成一个sequence序列号 if (ts == lastTs) {// 刚刚生成的时间戳跟上次的时间戳一样,则需要生成一个sequence序列号
// sequence循环自增 // sequence循环自增

@ -31,6 +31,8 @@ import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
@ -302,6 +304,9 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
return Long.parseLong(temp); return Long.parseLong(temp);
} }
}) })
.option()
.addHeader("1", "@")
.controller(ControllerType.START_CONTROLLER)
.start(); .start();
} }

@ -43,7 +43,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.6.6_beta_1' publishVersion = '3.6.6_beta_2'
// publishVersion = '1.0.4' //FTP插件 // publishVersion = '1.0.4' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save