修复kotlin设置配置文件ide报错的问题 https://github.com/AriaLyy/Aria/issues/286

pull/330/head
laoyuyu 6 years ago
parent 6d5398de40
commit 7f975b2e91
  1. 15
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 31
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/common/BandwidthLimiter.java
  4. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  5. 14
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  6. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  7. 20
      Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java
  8. 2
      AriaFtpPlug/src/main/java/org/apache/commons/net/io/Util.java
  9. 3
      DEV_LOG.md
  10. 10
      README.md
  11. 6
      app/build.gradle
  12. 5
      app/src/main/AndroidManifest.xml
  13. 2
      app/src/main/assets/aria_config.xml
  14. 2
      app/src/main/java/com/arialyy/simple/MainActivity.java
  15. 8
      app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt
  16. 2
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  17. 4
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  18. 2
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  19. 6
      app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java
  20. 2
      app/src/main/res/values/strings.xml
  21. 2
      aria/src/main/java/com/arialyy/aria/core/Configuration.java
  22. 6
      build.gradle

@ -42,8 +42,7 @@ import java.util.TimerTask;
* Created by AriaL on 2017/7/1.
* 任务处理器
*/
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
implements Runnable {
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
private static final String STATE = "_state_";
private static final String RECORD = "_record_";
/**
@ -104,13 +103,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
}
@Override public void run() {
if (mConstance.isRunning) {
return;
}
startFlow();
}
/**
* 重置任务状态
*/
@ -280,7 +272,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
* 直接调用的时候会自动启动线程执行
*/
public void start() {
new Thread(this).start();
if (mConstance.isRunning) {
return;
}
startFlow();
}
public void resume() {

@ -15,7 +15,6 @@
*/
package com.arialyy.aria.core.common;
import android.os.Build;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
@ -29,8 +28,6 @@ import com.arialyy.aria.util.NetUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -58,7 +55,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
private int mFailTimes = 0;
private Timer mFailTimer;
private long mLastSaveTime;
private ExecutorService mConfigThreadPool;
protected int mConnectTimeOut; //连接超时时间
@ -126,10 +122,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
/**
* 设置最大下载速度
*
* @param speed 单位为kb
*/
public void setMaxSpeed(int speed){
if (mSpeedBandUtil != null){
public void setMaxSpeed(int speed) {
if (mSpeedBandUtil != null) {
mSpeedBandUtil.setMaxRate(speed / mThreadNum);
}
}
@ -166,6 +163,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
return STATE.isRunning;
}
public boolean isInterrupted() {
return Thread.currentThread().isInterrupted();
}
/**
* 获取线程配置信息
*/
@ -173,10 +174,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
return mConfig;
}
private boolean filterVersion() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
@Override protected void finalize() throws Throwable {
super.finalize();
if (mConfigThreadPool != null) {
@ -333,10 +330,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* @param needRetry 是否可以重试
*/
private void retryThis(boolean needRetry) {
if (mFailTimer != null) {
mFailTimer.purge();
mFailTimer.cancel();
}
if (!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry) {
ALog.w(TAG, String.format("任务【%s】thread__%s__重试失败,网络未连接", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID));
@ -345,19 +338,9 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|| isNotNetRetry) && !isBreak()) {
ALog.w(TAG,
String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
mFailTimer = new Timer(true);
mFailTimer.schedule(new TimerTask() {
@Override public void run() {
if (isBreak()) {
handleFailState(false);
return;
}
mFailTimes++;
handleRetryRecord();
ThreadTaskManager.getInstance().retryThread(AbsThreadTask.this);
//AbsThreadTask.this.run();
}
}, 3000);
} else {
handleFailState(!isBreak());
}

@ -84,7 +84,7 @@ public class BandwidthLimiter {
this.bytesWillBeSentOrReceive += len;
/* We have sent CHUNK_LENGTH bytes */
while (this.bytesWillBeSentOrReceive > CHUNK_LENGTH) {
while (!Thread.currentThread().isInterrupted() && this.bytesWillBeSentOrReceive > CHUNK_LENGTH) {
long nowTick = System.nanoTime();
long missedTime = this.timeCostPerChunk
- (nowTick - this.lastPieceSentOrReceiveTick);

@ -266,8 +266,8 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> 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;
}

@ -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<String> 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<String> 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;
}

@ -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<DownloadEntity, DownloadTaskEnt
isBlock = STATE.TASK_RECORD.isBlock;
}
@Override public DownloadTaskEntity call(){
@Override public DownloadTaskEntity call() {
if (getThreadRecord().isComplete) {
handleComplete();
return mTaskEntity;
@ -68,7 +67,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
try {
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
URL url = new URL(CommonUtil.convertUrl(mConfig.URL + 1));
conn = ConnectionHelp.handleConnection(url, mTaskEntity);
if (mConfig.SUPPORT_BP) {
ALog.d(TAG,

@ -57,7 +57,7 @@ public class ThreadTaskManager {
* @param key 任务对应的key{@link AbsTaskEntity#getKey()}
* @param threadTask 线程任务{@link AbsThreadTask}
*/
public void startThread(String key, AbsThreadTask threadTask) {
public synchronized void startThread(String key, AbsThreadTask threadTask) {
if (mExePool.isShutdown()) {
ALog.e(TAG, "线程池已经关闭");
return;
@ -76,18 +76,23 @@ public class ThreadTaskManager {
*
* @param key 任务对应的key{@link AbsTaskEntity#getKey()}
*/
public void stopTaskThread(String key) {
public synchronized void stopTaskThread(String key) {
if (mExePool.isShutdown()) {
ALog.e(TAG, "线程池已经关闭");
return;
}
Set<Future> temp = mThreadTasks.get(getKey(key));
try {
for (Future future : temp) {
if (future.isDone() || future.isCancelled()) {
continue;
}
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);
}

@ -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.

@ -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

@ -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:<last-version>'`替换为
```
@ -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)

@ -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'

@ -14,10 +14,11 @@
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".MainActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".test.TestFTPDirActivity"-->
<!--android:name=".test.TestFTPActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".download.SingleTaskActivity"-->
<!--android:name=".test.TestFTPActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"-->
<activity
android:name=".download.SingleTaskActivity"
android:label="@string/app_name">

@ -35,7 +35,7 @@
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式;
-->
<threadNum value="3"/>
<threadNum value="1"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/>

@ -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<ActivityMainBinding> {
setSupportActionBar(mBar);
mBar.setTitle("Aria Demo");
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override protected int setLayoutId() {

@ -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()

@ -245,7 +245,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.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();

@ -47,7 +47,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
super.init(savedInstanceState);
Aria.download(this).register();
setTitle("任务组");
mUrls = getModule(GroupModule.class).getUrls1();
mUrls = getModule(GroupModule.class).getUrls();
DownloadGroupTaskEntity entity = Aria.download(this).getGroupTask(mUrls);
if (entity != null && entity.getEntity() != null) {
DownloadGroupEntity groupEntity = entity.getEntity();
@ -91,7 +91,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
.setGroupAlias("任务组测试")
//.setSubFileName(getModule(GroupModule.class).getSubName2())
.setSubFileName(getModule(GroupModule.class).getSubName())
.updateUrls(temp)
//.updateUrls(temp)
.start();
break;
case R.id.stop:

@ -32,7 +32,7 @@ public class GroupModule extends BaseModule {
public List<String> getUrls() {
List<String> 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;
}

@ -82,9 +82,9 @@ public class TestFTPActivity extends BaseActivity<ActivityTestBinding> {
.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());

@ -85,7 +85,7 @@
</string-array>
<string-array name="group_names">
<!--<item>王者荣耀.apk</item>-->
<item>王者荣耀.apk</item>
<item>战斗吧剑灵.apk</item>
<!--<item>天魔幻想.apk</item>-->
</string-array>

@ -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";

@ -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 下载框架'

Loading…
Cancel
Save