diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index cae8612f..8c2a5237 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -42,8 +42,7 @@ import java.util.TimerTask; * Created by AriaL on 2017/7/1. * 任务处理器 */ -public abstract class AbsFileer> - implements Runnable { +public abstract class AbsFileer> { private static final String STATE = "_state_"; private static final String RECORD = "_record_"; /** @@ -104,13 +103,6 @@ public abstract class AbsFileer= Build.VERSION_CODES.LOLLIPOP; - } - @Override protected void finalize() throws Throwable { super.finalize(); if (mConfigThreadPool != null) { @@ -333,10 +330,6 @@ public abstract class AbsThreadTask CHUNK_LENGTH) { + while (!Thread.currentThread().isInterrupted() && this.bytesWillBeSentOrReceive > CHUNK_LENGTH) { long nowTick = System.nanoTime(); long missedTime = this.timeCostPerChunk - (nowTick - this.lastPieceSentOrReceiveTick); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index 7643a8f7..6a1adcf4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -266,8 +266,8 @@ public class DownloadGroupTarget extends BaseGroupTarget im if (oldFile.exists()) { oldFile.renameTo(new File(newPath)); } - if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", newPath)) { - ALog.w(TAG, String.format("更新文件名失败,路径【%s】已存在", newPath)); + if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=? or isComplete='true'", newPath)) { + ALog.w(TAG, String.format("更新文件名失败,路径【%s】已存在或文件已下载", newPath)); return; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 9e9ed848..36db9187 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -26,13 +26,11 @@ import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.NetUtils; import java.io.File; -import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** @@ -56,7 +54,6 @@ public abstract class AbsGroupUtil implements IUtil { */ long mTotalLen = 0; long mCurrentLocation = 0; - private ExecutorService mExePool; protected IDownloadGroupListener mListener; DownloadGroupTaskEntity mGTEntity; private boolean isRunning = false; @@ -97,7 +94,6 @@ public abstract class AbsGroupUtil implements IUtil { AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity groupEntity) { mListener = listener; mGTEntity = groupEntity; - mExePool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); mUpdateInterval = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval(); } @@ -228,10 +224,6 @@ public abstract class AbsGroupUtil implements IUtil { isCancel = true; closeTimer(); onCancel(); - if (!mExePool.isShutdown()) { - mExePool.shutdown(); - } - Set keys = mDownloaderMap.keySet(); for (String key : keys) { Downloader dt = mDownloaderMap.get(key); @@ -251,9 +243,6 @@ public abstract class AbsGroupUtil implements IUtil { isStop = true; closeTimer(); onStop(); - if (!mExePool.isShutdown()) { - mExePool.shutdown(); - } Set keys = mDownloaderMap.keySet(); for (String key : keys) { @@ -392,9 +381,8 @@ public abstract class AbsGroupUtil implements IUtil { ChildDownloadListener listener = new ChildDownloadListener(taskEntity); Downloader dt = new Downloader(listener, taskEntity); mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt); - if (mExePool.isShutdown()) return dt; if (start) { - mExePool.execute(dt); + dt.start(); } return dt; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index 9bc2ec5b..acf9192b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -33,7 +33,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.Channels; -import java.nio.channels.ClosedByInterruptException; import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; @@ -57,7 +56,7 @@ final class HttpThreadTask extends AbsThreadTask temp = mThreadTasks.get(getKey(key)); - for (Future future : temp) { - if (future.isDone() || future.isCancelled()) { - continue; + try { + for (Future future : temp) { + if (future.isDone() || future.isCancelled()) { + continue; + } + future.cancel(true); } - future.cancel(true); + } catch (Exception e) { + ALog.e(TAG, e); } + temp.clear(); mThreadTasks.remove(key); } @@ -96,11 +101,20 @@ public class ThreadTaskManager { * * @param task 线程任务 */ - public void retryThread(AbsThreadTask task) { + public synchronized void retryThread(AbsThreadTask task) { if (mExePool.isShutdown()) { ALog.e(TAG, "线程池已经关闭"); return; } + try { + if (task == null || task.isInterrupted()) { + ALog.e(TAG, "线程为空或线程已经中断"); + return; + } + } catch (Exception e) { + ALog.e(TAG, e); + return; + } mExePool.submit(task); } diff --git a/AriaFtpPlug/src/main/java/org/apache/commons/net/io/Util.java b/AriaFtpPlug/src/main/java/org/apache/commons/net/io/Util.java index 04fbdb0d..8b8fa789 100644 --- a/AriaFtpPlug/src/main/java/org/apache/commons/net/io/Util.java +++ b/AriaFtpPlug/src/main/java/org/apache/commons/net/io/Util.java @@ -92,7 +92,7 @@ public final class Util { byte[] buffer = new byte[bufferSize > 0 ? bufferSize : DEFAULT_COPY_BUFFER_SIZE]; try { - while ((numBytes = source.read(buffer)) != -1) { + while (!Thread.currentThread().isInterrupted() && (numBytes = source.read(buffer)) != -1) { // Technically, some read(byte[]) methods may return 0 and we cannot // accept that as an indication of EOF. diff --git a/DEV_LOG.md b/DEV_LOG.md index 1143fec3..ba49504a 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.4.12 + - fix bug https://github.com/AriaLyy/Aria/issues/286 + - 优化线程池任务 + v_3.4.11 - fix bug https://github.com/AriaLyy/Aria/issues/288 - fix bug https://github.com/AriaLyy/Aria/issues/282 diff --git a/README.md b/README.md index cf24cb27..22be89e0 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.4.11' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.11' +compile 'com.arialyy.aria:aria-core:3.4.12' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.12' ``` 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:'`替换为 ``` @@ -101,9 +101,9 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 - + v_3.4.11 - - fix bug https://github.com/AriaLyy/Aria/issues/288 - - fix bug https://github.com/AriaLyy/Aria/issues/282 + + v_3.4.12 + - fix bug https://github.com/AriaLyy/Aria/issues/286 + - 优化线程池任务 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/build.gradle b/app/build.gradle index 3f35f8e5..d0b770e4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.application' -//apply plugin: 'kotlin-android' -//apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' //apply plugin: 'kotlin-kapt' android { @@ -51,7 +51,7 @@ dependencies { compile 'com.arialyy.frame:MVVM2:2.2.0' compile project(':Aria') compile project(':AriaCompiler') - // compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // compile 'com.arialyy.aria:aria-core:3.3.16' // annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.16' debugCompile 'com.amitshekhar.android:debug-db:1.0.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 314d14ce..434990a3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,10 +14,11 @@ android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBar"> - - + + + diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index aacfdc1b..4e5da29d 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -35,7 +35,7 @@ 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; --> - + diff --git a/app/src/main/java/com/arialyy/simple/MainActivity.java b/app/src/main/java/com/arialyy/simple/MainActivity.java index 52291d32..36142640 100644 --- a/app/src/main/java/com/arialyy/simple/MainActivity.java +++ b/app/src/main/java/com/arialyy/simple/MainActivity.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; import butterknife.OnClick; +import com.arialyy.aria.core.Aria; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityMainBinding; import com.arialyy.simple.download.DownloadActivity; @@ -39,6 +40,7 @@ public class MainActivity extends BaseActivity { setSupportActionBar(mBar); mBar.setTitle("Aria Demo"); getSupportActionBar().setDisplayHomeAsUpEnabled(false); + } @Override protected int setLayoutId() { diff --git a/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt b/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt index 8a22289a..4848e007 100644 --- a/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt +++ b/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt @@ -41,12 +41,14 @@ class KotlinDownloadActivity : AppCompatActivity() { // setBtState(false) // } // binding.fileSize = target.getConvertFileSize() + Aria.get(this).downloadConfig.maxTaskNum = 2 Aria.download(this).register() } - @Download.onTaskRunning protected fun running(task: DownloadTask) { + @Download.onTaskRunning + protected fun running(task: DownloadTask) { Log.d(TAG, task.percent.toString() + "") - val len = task.fileSize +// val len = task.fileSize // if (len == 0L) { // binding.progress = 0 // } else { @@ -65,7 +67,7 @@ class KotlinDownloadActivity : AppCompatActivity() { private fun startD() { Aria.download(this) - .load(DOWNLOAD_URL, true) + .load(DOWNLOAD_URL) .addHeader("groupName", "value") .setDownloadPath(Environment.getExternalStorageDirectory().path + "/hhhhhhhh.apk") .start() diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 53c76670..38d01617 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -245,7 +245,7 @@ public class SingleTaskActivity extends BaseActivity { //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") //.useServerFileName(true) //.setRequestMode(RequestEnum.GET) - .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg3.apk") + .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg4.apk") //.resetState() .start(); //.add(); diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index 452d3a99..8f75bb19 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -47,7 +47,7 @@ public class DownloadGroupActivity extends BaseActivity getUrls() { List urls = new ArrayList<>(); - String[] str = getContext().getResources().getStringArray(R.array.group_url4); + String[] str = getContext().getResources().getStringArray(R.array.group_urls_1); Collections.addAll(urls, str); return urls; } diff --git a/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java b/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java index 39747303..fd585c27 100644 --- a/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java +++ b/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java @@ -82,9 +82,9 @@ public class TestFTPActivity extends BaseActivity { .loadFtp(FILE_PATH) .login("lao", "123456") .setUploadUrl(URL) - //.asFtps() - //.setStorePath("/mnt/sdcard/Download/server.crt") - //.setAlias("www.laoyuyu.me") + .asFtps() + .setStorePath("/mnt/sdcard/Download/server.crt") + .setAlias("www.laoyuyu.me") .start(); //Uri uri = Uri.parse("ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv"); //ALog.d(TAG, "sh = " + uri.getScheme() + ", user = " + uri.getUserInfo() + ", host = " + uri.getHost() + ", port = " + uri.getPort() + " remotePath = " + uri.getPath()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4ced4d1c..d1c46d05 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,7 +85,7 @@ - + 王者荣耀.apk 战斗吧剑灵.apk diff --git a/aria/src/main/java/com/arialyy/aria/core/Configuration.java b/aria/src/main/java/com/arialyy/aria/core/Configuration.java index 09cc56c8..7e518ed5 100644 --- a/aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -34,7 +34,7 @@ import java.util.Properties; * Created by lyy on 2016/12/8. * 信息配置 */ -class Configuration { +public class Configuration { static final String TAG = "Configuration"; static final String DOWNLOAD_CONFIG_FILE = "/Aria/DownloadConfig.properties"; static final String UPLOAD_CONFIG_FILE = "/Aria/UploadConfig.properties"; diff --git a/build.gradle b/build.gradle index 5cadcae4..c401c2cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { -// ext.kotlin_version = '1.1.51' + ext.kotlin_version = '1.1.51' repositories { jcenter() mavenCentral() @@ -9,7 +9,7 @@ buildscript { // classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.novoda:bintray-release:0.5.0' -// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.4.11' + publishVersion = '3.4.12' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'