parent
432ae1c145
commit
7c4012c021
@ -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(); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
Loading…
Reference in new issue