修复重构loader后,http上传失败的问题

pull/617/head
laoyuyu 5 years ago
parent 432ae1c145
commit 7c4012c021
  1. 14
      Aria/src/main/java/com/arialyy/aria/core/common/HttpOption.java
  2. 3
      FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpSubDLoaderUtil.java
  3. 3
      HttpComponent/src/main/java/com/arialyy/aria/http/HttpRecordHandler.java
  4. 2
      HttpComponent/src/main/java/com/arialyy/aria/http/HttpTaskOption.java
  5. 8
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
  6. 5
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java
  7. 3
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDLoaderUtil.java
  8. 7
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpSubDLoaderUtil.java
  9. 94
      HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpULoader.java
  10. 8
      HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpULoaderUtil.java
  11. 16
      HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUThreadTaskAdapter.java
  12. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/event/EventMsgUtil.java
  13. 27
      PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java
  14. 4
      PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoaderUtil.java
  15. 3
      PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java
  16. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSubQueue.java
  17. 73
      PublicComponent/src/main/java/com/arialyy/aria/core/group/SubRecordHandler.java
  18. 3
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalLoader.java
  19. 4
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalLoaderUtil.java
  20. 17
      PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTask.java
  21. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadGroupTask.java
  22. 5
      PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadTask.java
  23. 5
      PublicComponent/src/main/java/com/arialyy/aria/core/task/UploadTask.java
  24. 8
      PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java
  25. 5
      app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java
  26. 16
      app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
  27. 2
      build.gradle
  28. 4
      py/upload.py

@ -35,6 +35,7 @@ public class HttpOption extends BaseOption {
private Proxy proxy; private Proxy proxy;
private boolean useServerFileName = false; private boolean useServerFileName = false;
private IHttpFileLenAdapter fileLenAdapter; private IHttpFileLenAdapter fileLenAdapter;
private String attachment;
public HttpOption() { public HttpOption() {
super(); super();
@ -84,6 +85,19 @@ public class HttpOption extends BaseOption {
return this; return this;
} }
/**
* 设置文件上传需要的key
*
* @param attachment 如果为空默认为"file"
*/
public HttpOption setAttachment(String attachment) {
if (TextUtils.isEmpty(attachment)) {
attachment = "file";
}
this.attachment = attachment;
return this;
}
/** /**
* 给url请求添加Header数据 * 给url请求添加Header数据
* 如果新的header数据和数据保存的不一致则更新数据库中对应的header数据 * 如果新的header数据和数据保存的不一致则更新数据库中对应的header数据

@ -18,6 +18,7 @@ package com.arialyy.aria.ftp.download;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.group.AbsSubDLoadUtil; import com.arialyy.aria.core.group.AbsSubDLoadUtil;
import com.arialyy.aria.core.group.SubRecordHandler;
import com.arialyy.aria.core.loader.LoaderStructure; import com.arialyy.aria.core.loader.LoaderStructure;
import com.arialyy.aria.core.loader.SubLoader; import com.arialyy.aria.core.loader.SubLoader;
@ -46,7 +47,7 @@ final class FtpSubDLoaderUtil extends AbsSubDLoadUtil {
@Override protected LoaderStructure buildLoaderStructure() { @Override protected LoaderStructure buildLoaderStructure() {
LoaderStructure structure = new LoaderStructure(); LoaderStructure structure = new LoaderStructure();
structure.addComponent(new FtpDRecordHandler(getWrapper())) structure.addComponent(new SubRecordHandler(getWrapper()))
.addComponent(new FtpDTTBuilder(getWrapper())) .addComponent(new FtpDTTBuilder(getWrapper()))
.addComponent(new FtpDFileInfoTask(getWrapper())); .addComponent(new FtpDFileInfoTask(getWrapper()));
structure.accept(getLoader()); structure.accept(getLoader());

@ -85,8 +85,7 @@ public final class HttpRecordHandler extends RecordHandler {
record.threadNum = threadNum; record.threadNum = threadNum;
int requestType = getWrapper().getRequestType(); int requestType = getWrapper().getRequestType();
if (requestType == ITaskWrapper.D_FTP || requestType == ITaskWrapper.D_FTP_DIR if (requestType == ITaskWrapper.D_HTTP || requestType == ITaskWrapper.DG_HTTP) {
|| requestType == ITaskWrapper.D_HTTP || requestType == ITaskWrapper.DG_HTTP) {
record.isBlock = Configuration.getInstance().downloadCfg.isUseBlock(); record.isBlock = Configuration.getInstance().downloadCfg.isUseBlock();
} else { } else {
record.isBlock = false; record.isBlock = false;

@ -101,7 +101,7 @@ public final class HttpTaskOption implements ITaskOption {
} }
public String getAttachment() { public String getAttachment() {
return attachment; return TextUtils.isEmpty(attachment) ? "file" : attachment;
} }
public void setAttachment(String attachment) { public void setAttachment(String attachment) {

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.http; package com.arialyy.aria.http.download;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.Uri; import android.net.Uri;
@ -30,6 +30,8 @@ import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.http.ConnectionHelp;
import com.arialyy.aria.http.HttpTaskOption;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -55,7 +57,7 @@ import java.util.UUID;
/** /**
* 下载文件信息获取 * 下载文件信息获取
*/ */
public final class HttpFileInfoTask implements IInfoTask, Runnable { final class HttpDFileInfoTask implements IInfoTask, Runnable {
private static final String TAG = "HttpFileInfoThread"; private static final String TAG = "HttpFileInfoThread";
private DownloadEntity mEntity; private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper; private DTaskWrapper mTaskWrapper;
@ -63,7 +65,7 @@ public final class HttpFileInfoTask implements IInfoTask, Runnable {
private Callback callback; private Callback callback;
private HttpTaskOption taskOption; private HttpTaskOption taskOption;
public HttpFileInfoTask(DTaskWrapper taskWrapper) { HttpDFileInfoTask(DTaskWrapper taskWrapper) {
this.mTaskWrapper = taskWrapper; this.mTaskWrapper = taskWrapper;
mEntity = taskWrapper.getEntity(); mEntity = taskWrapper.getEntity();
mConnectTimeOut = AriaConfig.getInstance().getDConfig().getConnectTimeOut(); mConnectTimeOut = AriaConfig.getInstance().getDConfig().getConnectTimeOut();

@ -25,7 +25,6 @@ import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.loader.ILoaderVisitor; import com.arialyy.aria.core.loader.ILoaderVisitor;
import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.http.HttpFileInfoTask;
import com.arialyy.aria.http.HttpTaskOption; import com.arialyy.aria.http.HttpTaskOption;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -98,7 +97,7 @@ public final class HttpDGInfoTask implements IInfoTask {
} }
} }
/*z /*
* 获取组合任务大小使用该方式获取到的组合任务大小子任务不需要再重新获取文件大小 * 获取组合任务大小使用该方式获取到的组合任务大小子任务不需要再重新获取文件大小
*/ */
private void getGroupSize() { private void getGroupSize() {
@ -106,7 +105,7 @@ public final class HttpDGInfoTask implements IInfoTask {
@Override public void run() { @Override public void run() {
for (DTaskWrapper dTaskWrapper : wrapper.getSubTaskWrapper()) { for (DTaskWrapper dTaskWrapper : wrapper.getSubTaskWrapper()) {
cloneHeader(dTaskWrapper); cloneHeader(dTaskWrapper);
HttpFileInfoTask infoTask = new HttpFileInfoTask(dTaskWrapper); HttpDFileInfoTask infoTask = new HttpDFileInfoTask(dTaskWrapper);
infoTask.setCallback(subCallback); infoTask.setCallback(subCallback);
mPool.execute(infoTask); mPool.execute(infoTask);
} }

@ -23,7 +23,6 @@ import com.arialyy.aria.core.loader.LoaderStructure;
import com.arialyy.aria.core.loader.NormalLoader; import com.arialyy.aria.core.loader.NormalLoader;
import com.arialyy.aria.core.loader.NormalThreadStateManager; import com.arialyy.aria.core.loader.NormalThreadStateManager;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.http.HttpFileInfoTask;
import com.arialyy.aria.http.HttpRecordHandler; import com.arialyy.aria.http.HttpRecordHandler;
import com.arialyy.aria.http.HttpTaskOption; import com.arialyy.aria.http.HttpTaskOption;
@ -45,7 +44,7 @@ public final class HttpDLoaderUtil extends AbsNormalLoaderUtil {
LoaderStructure structure = new LoaderStructure(); LoaderStructure structure = new LoaderStructure();
structure.addComponent(new HttpRecordHandler(getTaskWrapper())) structure.addComponent(new HttpRecordHandler(getTaskWrapper()))
.addComponent(new NormalThreadStateManager(getListener())) .addComponent(new NormalThreadStateManager(getListener()))
.addComponent(new HttpFileInfoTask((DTaskWrapper) getTaskWrapper())) .addComponent(new HttpDFileInfoTask((DTaskWrapper) getTaskWrapper()))
.addComponent(new HttpDTTBuilder(getTaskWrapper())); .addComponent(new HttpDTTBuilder(getTaskWrapper()));
structure.accept(getLoader()); structure.accept(getLoader());
return structure; return structure;

@ -18,10 +18,9 @@ package com.arialyy.aria.http.download;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.group.AbsSubDLoadUtil; import com.arialyy.aria.core.group.AbsSubDLoadUtil;
import com.arialyy.aria.core.group.SubRecordHandler;
import com.arialyy.aria.core.loader.LoaderStructure; import com.arialyy.aria.core.loader.LoaderStructure;
import com.arialyy.aria.core.loader.SubLoader; import com.arialyy.aria.core.loader.SubLoader;
import com.arialyy.aria.http.HttpFileInfoTask;
import com.arialyy.aria.http.HttpRecordHandler;
/** /**
* @Author lyy * @Author lyy
@ -48,9 +47,9 @@ final class HttpSubDLoaderUtil extends AbsSubDLoadUtil {
@Override protected LoaderStructure buildLoaderStructure() { @Override protected LoaderStructure buildLoaderStructure() {
LoaderStructure structure = new LoaderStructure(); LoaderStructure structure = new LoaderStructure();
structure.addComponent(new HttpRecordHandler(getWrapper())) structure.addComponent(new SubRecordHandler(getWrapper()))
.addComponent(new HttpDTTBuilder(getWrapper())) .addComponent(new HttpDTTBuilder(getWrapper()))
.addComponent(new HttpFileInfoTask(getWrapper())); .addComponent(new HttpDFileInfoTask(getWrapper()));
structure.accept(getLoader()); structure.accept(getLoader());
return structure; return structure;
} }

@ -0,0 +1,94 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.http.upload;
import android.os.Handler;
import android.os.Looper;
import com.arialyy.aria.core.inf.IThreadStateManager;
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.loader.AbsNormalLoader;
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.loader.IRecordHandler;
import com.arialyy.aria.core.loader.IThreadTaskBuilder;
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.task.IThreadTask;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.ALog;
import java.util.List;
final class HttpULoader extends AbsNormalLoader {
HttpULoader(UTaskWrapper wrapper, IEventListener listener) {
super(wrapper, listener);
}
@Override public void addComponent(IRecordHandler recordHandler) {
mRecordHandler = recordHandler;
}
/**
* @deprecated http 上传任务不需要设置这个
*/
@Deprecated
@Override public void addComponent(IInfoTask infoTask) {
}
@Override public void addComponent(IThreadStateManager threadState) {
mStateManager = threadState;
}
@Override public void addComponent(IThreadTaskBuilder builder) {
mTTBuilder = builder;
}
@Override protected void handleTask(Looper looper) {
mRecord = mRecordHandler.getRecord(getFileSize());
mStateManager.setLooper(mRecord, looper);
List<IThreadTask> tt = mTTBuilder.buildThreadTask(mRecord,
new Handler(looper, mStateManager.getHandlerCallback()));
if (tt == null || tt.isEmpty()) {
ALog.e(TAG, "创建线程任务失败");
getListener().onFail(false, new AriaIOException(TAG, "创建线程任务失败"));
return;
}
getListener().onStart(0);
ThreadTaskManager.getInstance().startThread(mTaskWrapper.getKey(), tt.get(0));
startTimer();
}
@Override public long getFileSize() {
return mTaskWrapper.getEntity().getFileSize();
}
@Override protected void checkComponent() {
if (mRecordHandler == null) {
throw new NullPointerException("任务记录组件为空");
}
if (mStateManager == null) {
throw new NullPointerException("任务状态管理组件为空");
}
if (mTTBuilder == null) {
throw new NullPointerException("线程任务组件为空");
}
}
@Override public long getCurrentProgress() {
return mStateManager.getCurrentProgress();
}
}

@ -15,15 +15,13 @@
*/ */
package com.arialyy.aria.http.upload; package com.arialyy.aria.http.upload;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.listener.IEventListener; import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.loader.AbsNormalLoader; import com.arialyy.aria.core.loader.AbsNormalLoader;
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil; import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
import com.arialyy.aria.core.loader.LoaderStructure; import com.arialyy.aria.core.loader.LoaderStructure;
import com.arialyy.aria.core.loader.NormalLoader;
import com.arialyy.aria.core.loader.NormalThreadStateManager; import com.arialyy.aria.core.loader.NormalThreadStateManager;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.http.HttpFileInfoTask;
import com.arialyy.aria.http.HttpRecordHandler; import com.arialyy.aria.http.HttpRecordHandler;
import com.arialyy.aria.http.HttpTaskOption; import com.arialyy.aria.http.HttpTaskOption;
@ -38,14 +36,14 @@ public final class HttpULoaderUtil extends AbsNormalLoaderUtil {
} }
@Override public AbsNormalLoader getLoader() { @Override public AbsNormalLoader getLoader() {
return mLoader == null ? new NormalLoader(getTaskWrapper(), getListener()) : mLoader; return mLoader == null ? new HttpULoader((UTaskWrapper) getTaskWrapper(), getListener())
: mLoader;
} }
@Override public LoaderStructure BuildLoaderStructure() { @Override public LoaderStructure BuildLoaderStructure() {
LoaderStructure structure = new LoaderStructure(); LoaderStructure structure = new LoaderStructure();
structure.addComponent(new HttpRecordHandler(getTaskWrapper())) structure.addComponent(new HttpRecordHandler(getTaskWrapper()))
.addComponent(new NormalThreadStateManager(getListener())) .addComponent(new NormalThreadStateManager(getListener()))
.addComponent(new HttpFileInfoTask((DTaskWrapper) getTaskWrapper()))
.addComponent(new HttpUTTBuilder(getTaskWrapper())); .addComponent(new HttpUTTBuilder(getTaskWrapper()));
structure.accept(getLoader()); structure.accept(getLoader());
return structure; return structure;

@ -18,6 +18,7 @@ package com.arialyy.aria.http.upload;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.http.BaseHttpThreadTaskAdapter; import com.arialyy.aria.http.BaseHttpThreadTaskAdapter;
@ -102,7 +103,7 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter {
} }
uploadFile(writer, mTaskOption.getAttachment(), uploadFile); uploadFile(writer, mTaskOption.getAttachment(), uploadFile);
complete(); getEntity().setResponseStr(finish(writer));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail(new TaskException(TAG, fail(new TaskException(TAG,
@ -193,11 +194,6 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter {
inputStream.close(); inputStream.close();
writer.append(LINE_END); writer.append(LINE_END);
writer.flush(); writer.flush();
//if (getState().isCancel) {
// getState().isRunning = false;
// return;
//}
//getState().isRunning = false;
} }
/** /**
@ -210,7 +206,7 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter {
writer.append(LINE_END).flush(); writer.append(LINE_END).flush();
writer.append(PREFIX).append(BOUNDARY).append(PREFIX).append(LINE_END); writer.append(PREFIX).append(BOUNDARY).append(PREFIX).append(LINE_END);
writer.close(); writer.flush();
int status = mHttpConn.getResponseCode(); int status = mHttpConn.getResponseCode();
@ -222,9 +218,11 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter {
} }
reader.close(); reader.close();
mHttpConn.disconnect(); mHttpConn.disconnect();
complete();
} else { } else {
ALog.e(TAG, "response msg: " + mHttpConn.getResponseMessage() + ",code: " + status); String msg = "response msg: " + mHttpConn.getResponseMessage() + ",code: " + status;
// fail(); ALog.e(TAG, msg);
fail(new AriaIOException(TAG, msg), false);
} }
writer.flush(); writer.flush();
writer.close(); writer.close();

@ -38,7 +38,7 @@ public class EventMsgUtil {
private Map<Object, List<EventMethodInfo>> mEventMethods = private Map<Object, List<EventMethodInfo>> mEventMethods =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
private ArrayBlockingQueue<Object> mEventQueue = new ArrayBlockingQueue<>(10); private ArrayBlockingQueue<Object> mEventQueue = new ArrayBlockingQueue<>(10);
private ExecutorService mPool = Executors.newFixedThreadPool(10); private ExecutorService mPool = Executors.newFixedThreadPool(5);
private EventMsgUtil() { private EventMsgUtil() {
ExecutorService pool = Executors.newSingleThreadExecutor(); ExecutorService pool = Executors.newSingleThreadExecutor();

@ -217,36 +217,14 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
@Override public void cancel() { @Override public void cancel() {
isCancel = true; isCancel = true;
closeTimer(); closeTimer();
onPreCancel();
mSubQueue.removeAllTask(); mSubQueue.removeAllTask();
mListener.onCancel(); mListener.onCancel();
} }
/**
* onCancel前的操作
*/
protected void onPreCancel() {
}
@Override public void stop() { @Override public void stop() {
isStop = true; isStop = true;
closeTimer();
if (onPreStop()) {
return;
}
mSubQueue.stopAllTask(); mSubQueue.stopAllTask();
} closeTimer();
/**
* onStop前的操作
*
* @return 返回{@code true}直接回调{@link IDGroupListener#onStop(long)}
*/
protected boolean onPreStop() {
return false;
} }
@Override public void run() { @Override public void run() {
@ -265,6 +243,9 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
closeTimer(); closeTimer();
Looper.prepare(); Looper.prepare();
Looper looper = Looper.myLooper(); Looper looper = Looper.myLooper();
if (looper == Looper.getMainLooper()) {
throw new IllegalThreadStateException("不能在主线程程序中调用Loader");
}
initState(looper); initState(looper);
getState().setSubSize(getWrapper().getSubTaskWrapper().size()); getState().setSubSize(getWrapper().getSubTaskWrapper().size());
if (getState().getCompleteNum() != 0 if (getState().getCompleteNum() != 0

@ -99,6 +99,8 @@ public abstract class AbsGroupLoaderUtil implements IUtil {
} }
buildLoaderStructure(); buildLoaderStructure();
new Thread(mLoader).start(); // MsgEvent 已经是在线程中使用了,不需要重开线程
mLoader.run();
//new Thread(mLoader).start();
} }
} }

@ -26,6 +26,7 @@ import com.arialyy.aria.core.loader.IRecordHandler;
import com.arialyy.aria.core.manager.ThreadTaskManager; import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.NetUtils; import com.arialyy.aria.util.NetUtils;
import java.io.File; import java.io.File;
@ -34,7 +35,7 @@ import java.io.File;
* 该调度器生命周期和{@link AbsGroupLoaderUtil}生命周期一致 * 该调度器生命周期和{@link AbsGroupLoaderUtil}生命周期一致
*/ */
final class SimpleSchedulers implements Handler.Callback { final class SimpleSchedulers implements Handler.Callback {
private static final String TAG = "SimpleSchedulers"; private final String TAG = CommonUtil.getClassName(this);
private SimpleSubQueue mQueue; private SimpleSubQueue mQueue;
private GroupRunState mGState; private GroupRunState mGState;
private String mKey; // 组合任务的key private String mKey; // 组合任务的key

@ -58,11 +58,7 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
return new SimpleSubQueue(); return new SimpleSubQueue();
} }
Map<String, AbsSubDLoadUtil> getExec() { synchronized AbsSubDLoadUtil getLoaderUtil(String key) {
return mExec;
}
AbsSubDLoadUtil getLoaderUtil(String key) {
AbsSubDLoadUtil sub = mExec.get(key); AbsSubDLoadUtil sub = mExec.get(key);
if (sub != null) { if (sub != null) {
return sub; return sub;

@ -0,0 +1,73 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.group;
import com.arialyy.aria.core.TaskRecord;
import com.arialyy.aria.core.ThreadRecord;
import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.common.RecordHelper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import java.util.ArrayList;
/**
* 子任务记录处理
*/
public class SubRecordHandler extends RecordHandler {
public SubRecordHandler(AbsTaskWrapper wrapper) {
super(wrapper);
}
@Override public void handlerTaskRecord(TaskRecord record) {
RecordHelper helper = new RecordHelper(getWrapper(), record);
helper.handleSingleThreadRecord();
}
@Override
public ThreadRecord createThreadRecord(TaskRecord record, int threadId, long startL, long endL) {
ThreadRecord tr;
tr = new ThreadRecord();
tr.taskKey = record.filePath;
tr.threadId = threadId;
tr.startLocation = startL;
tr.isComplete = false;
tr.threadType = getEntity().getTaskType();
tr.endLocation = getFileSize();
tr.blockLen = getFileSize();
return tr;
}
@Override public TaskRecord createTaskRecord(int threadNum) {
TaskRecord record = new TaskRecord();
record.fileName = getEntity().getFileName();
record.filePath = getEntity().getFilePath();
record.fileLength = getFileSize();
record.threadRecords = new ArrayList<>();
record.threadNum = threadNum;
record.isBlock = false;
record.taskType = getEntity().getTaskType();
record.isGroupRecord = true;
if (getEntity() instanceof DownloadEntity) {
record.dGroupHash = ((DownloadEntity) getEntity()).getGroupHash();
}
return record;
}
@Override public int initTaskThreadNum() {
return 1;
}
}

@ -123,6 +123,9 @@ public abstract class AbsNormalLoader implements ILoaderVisitor, ILoader {
} }
Looper.prepare(); Looper.prepare();
Looper looper = Looper.myLooper(); Looper looper = Looper.myLooper();
if (looper == Looper.getMainLooper()){
throw new IllegalThreadStateException("不能在主线程程序中调用Loader");
}
isRuning = true; isRuning = true;
resetState(); resetState();
onPostPre(); onPostPre();

@ -115,7 +115,9 @@ public abstract class AbsNormalLoaderUtil implements IUtil {
//} //}
BuildLoaderStructure(); BuildLoaderStructure();
new Thread(mLoader).start(); // MsgEvent 已经是在线程中使用了,不需要重开线程
mLoader.run();
//new Thread(mLoader).start();
onStart(); onStart();
} }

@ -26,6 +26,7 @@ import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ComponentUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -63,11 +64,9 @@ public abstract class AbsTask<TASK_WRAPPER extends AbsTaskWrapper>
return mOutHandler; return mOutHandler;
} }
protected abstract IUtil createUtil();
protected synchronized IUtil getUtil() { protected synchronized IUtil getUtil() {
if (mUtil == null) { if (mUtil == null) {
mUtil = createUtil(); mUtil = ComponentUtil.getInstance().buildUtil(mTaskWrapper, mListener);
} }
return mUtil; return mUtil;
} }
@ -214,8 +213,8 @@ public abstract class AbsTask<TASK_WRAPPER extends AbsTaskWrapper>
@Override public void start(int type) { @Override public void start(int type) {
mSchedulerType = type; mSchedulerType = type;
mUtil = createUtil(); mUtil = getUtil();
if (mUtil == null){ if (mUtil == null) {
ALog.e(TAG, "任务工具创建失败"); ALog.e(TAG, "任务工具创建失败");
return; return;
} }
@ -240,8 +239,8 @@ public abstract class AbsTask<TASK_WRAPPER extends AbsTaskWrapper>
} }
@Override public void stop(int type) { @Override public void stop(int type) {
mUtil = createUtil(); mUtil = getUtil();
if (mUtil == null){ if (mUtil == null) {
ALog.e(TAG, "任务工具创建失败"); ALog.e(TAG, "任务工具创建失败");
return; return;
} }
@ -255,8 +254,8 @@ public abstract class AbsTask<TASK_WRAPPER extends AbsTaskWrapper>
} }
@Override public void cancel(int type) { @Override public void cancel(int type) {
mUtil = createUtil(); mUtil = getUtil();
if (mUtil == null){ if (mUtil == null) {
ALog.e(TAG, "任务工具创建失败"); ALog.e(TAG, "任务工具创建失败");
return; return;
} }

@ -21,9 +21,7 @@ import android.text.TextUtils;
import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.IUtil;
import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.ComponentUtil; import com.arialyy.aria.util.ComponentUtil;
/** /**
@ -53,10 +51,6 @@ public class DownloadGroupTask extends AbsGroupTask<DGTaskWrapper> {
return DOWNLOAD_GROUP; return DOWNLOAD_GROUP;
} }
@Override protected synchronized IUtil createUtil() {
return ComponentUtil.getInstance().buildUtil(mTaskWrapper, mListener);
}
public static class Builder { public static class Builder {
DGTaskWrapper taskEntity; DGTaskWrapper taskEntity;
Handler outHandler; Handler outHandler;

@ -21,7 +21,6 @@ import android.os.Looper;
import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IUtil;
import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.util.ComponentUtil; import com.arialyy.aria.util.ComponentUtil;
@ -75,10 +74,6 @@ public class DownloadTask extends AbsTask<DTaskWrapper> {
return mTaskWrapper.getEntity().getFileName(); return mTaskWrapper.getEntity().getFileName();
} }
@Override protected synchronized IUtil createUtil() {
return ComponentUtil.getInstance().buildUtil(mTaskWrapper, mListener);
}
public static class Builder { public static class Builder {
DTaskWrapper taskEntity; DTaskWrapper taskEntity;
Handler outHandler; Handler outHandler;

@ -17,7 +17,6 @@ package com.arialyy.aria.core.task;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import com.arialyy.aria.core.inf.IUtil;
import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
@ -51,10 +50,6 @@ public class UploadTask extends AbsTask<UTaskWrapper> {
return mTaskWrapper.getEntity().getFileName(); return mTaskWrapper.getEntity().getFileName();
} }
@Override protected synchronized IUtil createUtil() {
return ComponentUtil.getInstance().buildUtil(mTaskWrapper, mListener);
}
public static class Builder { public static class Builder {
private Handler mOutHandler; private Handler mOutHandler;
private UTaskWrapper mTaskEntity; private UTaskWrapper mTaskEntity;

@ -98,7 +98,8 @@ public class ComponentUtil {
* *
* @return 返回下载工具创建失败返回null * @return 返回下载工具创建失败返回null
*/ */
public <T extends IUtil> T buildUtil(AbsTaskWrapper wrapper, IEventListener listener) { public synchronized <T extends IUtil> T buildUtil(AbsTaskWrapper wrapper,
IEventListener listener) {
int requestType = wrapper.getRequestType(); int requestType = wrapper.getRequestType();
String className = null; String className = null;
switch (requestType) { switch (requestType) {
@ -158,7 +159,7 @@ public class ComponentUtil {
* @param wrapperType 任务类型{@link ITaskWrapper} * @param wrapperType 任务类型{@link ITaskWrapper}
* @return 返回事件监听如果创建失败返回null * @return 返回事件监听如果创建失败返回null
*/ */
public <T extends IEventListener> T buildListener(int wrapperType, AbsTask task, public synchronized <T extends IEventListener> T buildListener(int wrapperType, AbsTask task,
Handler outHandler) { Handler outHandler) {
String className = null, errorStr = "请添加FTP插件"; String className = null, errorStr = "请添加FTP插件";
switch (wrapperType) { switch (wrapperType) {
@ -211,7 +212,8 @@ public class ComponentUtil {
* @param params 任务配置信息参数 * @param params 任务配置信息参数
* @return 构建失败返回null * @return 构建失败返回null
*/ */
public <T extends ITaskOption> T buildTaskOption(Class<T> clazz, TaskOptionParams params) { public synchronized <T extends ITaskOption> T buildTaskOption(Class<T> clazz,
TaskOptionParams params) {
List<Field> fields = CommonUtil.getAllFields(clazz); List<Field> fields = CommonUtil.getAllFields(clazz);
T taskOption = null; T taskOption = null;
try { try {

@ -59,8 +59,9 @@ public class HttpDownloadModule extends BaseViewModule {
//String url = "https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a9e671b9a551f3dedcb2bf64a4eff0ec/4610b912c8fcc3cef70d70409845d688d53f20f7.jpg"; //String url = "https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a9e671b9a551f3dedcb2bf64a4eff0ec/4610b912c8fcc3cef70d70409845d688d53f20f7.jpg";
//String filePath = AppUtil.getConfigValue(context, HTTP_PATH_KEY, defFilePath); //String filePath = AppUtil.getConfigValue(context, HTTP_PATH_KEY, defFilePath);
String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip"; String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip";
String filePath = "/mnt/sdcard/QQMusic-import-1.2.1.zip"; String filePath = "/mnt/sdcard/update.zip";
//String filePath = "/mnt/sdcard/update.zip"; //String url = "https://dhfspace.360drm.com/1_12809_1543904946_VID_20180808_212829.vep?e=1578554567&token=gUBmfZgZS5wy4wdQIDZG8UVxlNCyVSjvksIb13K5:WYSZRgmLbH1_9hjgqOAGmqR27JM=";
//String filePath = "/mnt/sdcard/sssss.zip";
singDownloadInfo = Aria.download(context).getFirstDownloadEntity(url); singDownloadInfo = Aria.download(context).getFirstDownloadEntity(url);
if (singDownloadInfo == null) { if (singDownloadInfo == null) {

@ -41,9 +41,9 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
private static final String TAG = "HttpUploadActivity"; private static final String TAG = "HttpUploadActivity";
HorizontalProgressBarWithNumber mPb; HorizontalProgressBarWithNumber mPb;
//private final String FILE_PATH = "/mnt/sdcard/ggsg14.apk"; private final String FILE_PATH = "/mnt/sdcard/QQMusic-import-1.2.1.zip";
private final String FILE_PATH = //private final String FILE_PATH =
Environment.getExternalStorageDirectory().getPath() + "/Download/QQMusic-import-1.2.1.zip"; // Environment.getExternalStorageDirectory().getPath() + "/Download/QQMusic-import-1.2.1.zip";
private UploadEntity mEntity; private UploadEntity mEntity;
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
@ -78,11 +78,13 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
void upload() { void upload() {
HttpOption option = new HttpOption(); HttpOption option = new HttpOption();
option.setRequestType(RequestEnum.POST) option.setRequestType(RequestEnum.POST);
.setParam("params", "bbbbbbbb"); option.setParam("params", "bbbbbbbb");
option.setAttachment("file");
Aria.upload(HttpUploadActivity.this).load(FILE_PATH) Aria.upload(HttpUploadActivity.this).load(FILE_PATH)
//.setUploadUrl("http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}") //.setUploadUrl("http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}")
.setUploadUrl("http://9.9.12.210:5000/upload/") .setUploadUrl("http://9.9.9.28:5000/upload/")
.ignoreFilePathOccupy()
//.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file") //.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file")
//.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933") //.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933")
.option(option) .option(option)
@ -124,7 +126,7 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
@Upload.onTaskRunning public void taskRunning(UploadTask task) { @Upload.onTaskRunning public void taskRunning(UploadTask task) {
getBinding().setSpeed(task.getConvertSpeed()); getBinding().setSpeed(task.getConvertSpeed());
getBinding().setProgress(task.getPercent()); getBinding().setProgress(task.getPercent());
L.d(TAG, "P => " + task.getPercent()); L.d(TAG, "running, P = " + task.getPercent());
} }
@Upload.onTaskComplete public void taskComplete(UploadTask task) { @Upload.onTaskComplete public void taskComplete(UploadTask task) {

@ -45,7 +45,7 @@ task clean(type: Delete) {
ext { ext {
versionCode = 383 versionCode = 383
versionName = '3.8.3_beta_1' versionName = '3.8.3_beta_2'
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = versionName publishVersion = versionName

@ -3,7 +3,7 @@ import os
from flask import Flask, request, url_for, send_from_directory from flask import Flask, request, url_for, send_from_directory
from werkzeug import secure_filename from werkzeug import secure_filename
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif', 'rar', 'apk']) ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif', 'rar', 'apk', 'zip'])
app = Flask(__name__) app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = '/Users/aria/temp/test/' app.config['UPLOAD_FOLDER'] = '/Users/aria/temp/test/'
@ -49,7 +49,7 @@ def upload_file():
file = request.files['file'] file = request.files['file']
print(file) print(file)
if file and allowed_file(file.filename): #if file and allowed_file(file.filename):
print('start save') print('start save')
filename = secure_filename(file.filename) filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

Loading…
Cancel
Save