优化ttbuilder
This commit is contained in:
@@ -226,8 +226,8 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte
|
||||
FTPClient temp;
|
||||
if (urlEntity.isFtps) {
|
||||
FTPSClient sClient;
|
||||
SSLContext sslContext = SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath,
|
||||
urlEntity.protocol);
|
||||
SSLContext sslContext = SSLContextUtil.getSSLContext(
|
||||
urlEntity.idEntity.keyAlias, urlEntity.idEntity.storePath, urlEntity.protocol);
|
||||
if (sslContext == null) {
|
||||
sClient = new FTPSClient(urlEntity.protocol, urlEntity.isImplicit);
|
||||
} else {
|
||||
|
||||
@@ -147,8 +147,8 @@ public abstract class BaseFtpThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
FTPClient temp;
|
||||
if (urlEntity.isFtps) {
|
||||
FTPSClient sClient;
|
||||
SSLContext sslContext = SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath,
|
||||
urlEntity.protocol);
|
||||
SSLContext sslContext = SSLContextUtil.getSSLContext(
|
||||
urlEntity.idEntity.keyAlias, urlEntity.idEntity.storePath, urlEntity.protocol);
|
||||
if (sslContext == null) {
|
||||
sClient = new FTPSClient(urlEntity.protocol, urlEntity.isImplicit);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
///*
|
||||
// * 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.ftp.download;
|
||||
//
|
||||
//import com.arialyy.aria.core.TaskRecord;
|
||||
//import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
//import com.arialyy.aria.core.listener.IEventListener;
|
||||
//import com.arialyy.aria.core.loader.NormalTTBuilder;
|
||||
//import com.arialyy.aria.core.loader.IRecordHandler;
|
||||
//import com.arialyy.aria.core.loader.IThreadTaskBuilder;
|
||||
//import com.arialyy.aria.core.loader.NormalLoader;
|
||||
//import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
//import com.arialyy.aria.util.ALog;
|
||||
//import com.arialyy.aria.util.FileUtil;
|
||||
//import java.io.File;
|
||||
//import java.lang.reflect.InvocationHandler;
|
||||
//import java.lang.reflect.Method;
|
||||
//import java.lang.reflect.Proxy;
|
||||
//
|
||||
//final class FtpDLoader extends NormalLoader {
|
||||
// FtpDLoader(AbsTaskWrapper wrapper, IEventListener listener) {
|
||||
// super(wrapper, listener);
|
||||
// }
|
||||
//
|
||||
// @Override public void addComponent(IThreadTaskBuilder builder) {
|
||||
// mTTBuilder = (IThreadTaskBuilder) Proxy.newProxyInstance(getClass().getClassLoader(),
|
||||
// NormalTTBuilder.class.getInterfaces(), new InvocationHandler() {
|
||||
// NormalTTBuilder target = new NormalTTBuilder(mTaskWrapper);
|
||||
// @Override public Object invoke(Object proxy, Method method, Object[] args)
|
||||
// throws Exception {
|
||||
// if (method.getDeclaringClass() == Object.class) {
|
||||
// return method.invoke(this, args);
|
||||
// }
|
||||
//
|
||||
// //if (method.isDefault()) {
|
||||
// // Constructor<MethodHandles.Lookup>
|
||||
// // constructor =
|
||||
// // MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
|
||||
// // constructor.setAccessible(true);
|
||||
// // return constructor.newInstance(AbsNormalTTBuilder.class, -1 /* trusted */)
|
||||
// // .unreflectSpecial(method, AbsNormalTTBuilder.class)
|
||||
// // .bindTo(proxy)
|
||||
// // .invokeWithArguments(args);
|
||||
// //}
|
||||
//
|
||||
// String methodName = method.getName();
|
||||
// switch (methodName) {
|
||||
//
|
||||
// case "handleNewTask":
|
||||
// return handleNewTask((TaskRecord) args[0], (int) args[1]);
|
||||
// case "getAdapter":
|
||||
// return new FtpDThreadTaskAdapter((SubThreadConfig) args[0]);
|
||||
// }
|
||||
//
|
||||
// return method.invoke(target, args);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 处理新任务
|
||||
// */
|
||||
// private boolean handleNewTask(TaskRecord record, int totalThreadNum) {
|
||||
// File temp = new File(getEntity().getFilePath());
|
||||
// if (!record.isBlock) {
|
||||
// if (temp.exists()) {
|
||||
// FileUtil.deleteFile(temp);
|
||||
// }
|
||||
// //CommonUtil.createFile(mTempFile.getPath());
|
||||
// } else {
|
||||
// for (int i = 0; i < totalThreadNum; i++) {
|
||||
// File blockFile =
|
||||
// new File(String.format(IRecordHandler.SUB_PATH, temp.getPath(), i));
|
||||
// if (blockFile.exists()) {
|
||||
// ALog.d(TAG, String.format("分块【%s】已经存在,将删除该分块", i));
|
||||
// FileUtil.deleteFile(blockFile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
@@ -21,6 +21,7 @@ import com.arialyy.aria.core.loader.AbsNormalLoader;
|
||||
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
|
||||
import com.arialyy.aria.core.loader.LoaderStructure;
|
||||
import com.arialyy.aria.core.loader.NormalLoader;
|
||||
import com.arialyy.aria.core.loader.NormalTTBuilder;
|
||||
import com.arialyy.aria.core.loader.NormalThreadStateManager;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.ftp.FtpTaskOption;
|
||||
@@ -45,7 +46,7 @@ public final class FtpDLoaderUtil extends AbsNormalLoaderUtil {
|
||||
structure.addComponent(new FtpDRecordHandler((DTaskWrapper) getTaskWrapper()))
|
||||
.addComponent(new NormalThreadStateManager(getListener()))
|
||||
.addComponent(new FtpDFileInfoTask((DTaskWrapper) getTaskWrapper()))
|
||||
.addComponent(new FtpDTTBuilder(getTaskWrapper()));
|
||||
.addComponent(new NormalTTBuilder(getTaskWrapper(), new FtpDTTBuilderAdapter()));
|
||||
structure.accept(getLoader());
|
||||
return structure;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ import com.arialyy.aria.core.common.RecordHandler;
|
||||
import com.arialyy.aria.core.common.RecordHelper;
|
||||
import com.arialyy.aria.core.config.Configuration;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.loader.IRecordHandler;
|
||||
import com.arialyy.aria.core.wrapper.ITaskWrapper;
|
||||
import com.arialyy.aria.util.RecordUtil;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -31,9 +29,9 @@ import java.util.ArrayList;
|
||||
* @Author lyy
|
||||
* @Date 2019-09-19
|
||||
*/
|
||||
final class FtpDRecordHandler extends RecordHandler {
|
||||
public final class FtpDRecordHandler extends RecordHandler {
|
||||
|
||||
FtpDRecordHandler(DTaskWrapper wrapper) {
|
||||
public FtpDRecordHandler(DTaskWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@@ -76,35 +74,18 @@ final class FtpDRecordHandler extends RecordHandler {
|
||||
record.filePath = getEntity().getFilePath();
|
||||
record.threadRecords = new ArrayList<>();
|
||||
record.threadNum = threadNum;
|
||||
|
||||
int requestType = getWrapper().getRequestType();
|
||||
if (requestType == ITaskWrapper.D_FTP || requestType == ITaskWrapper.D_FTP_DIR) {
|
||||
record.isBlock = Configuration.getInstance().downloadCfg.isUseBlock();
|
||||
} else {
|
||||
record.isBlock = false;
|
||||
}
|
||||
record.isBlock = Configuration.getInstance().downloadCfg.isUseBlock();
|
||||
record.taskType = getWrapper().getEntity().getTaskType();
|
||||
record.isGroupRecord = getEntity().isGroupChild();
|
||||
if (record.isGroupRecord) {
|
||||
if (getEntity() instanceof DownloadEntity) {
|
||||
record.dGroupHash = ((DownloadEntity) getEntity()).getGroupHash();
|
||||
}
|
||||
}
|
||||
record.isGroupRecord = false;
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
@Override public int initTaskThreadNum() {
|
||||
int requestType = getWrapper().getRequestType();
|
||||
if (requestType == ITaskWrapper.D_FTP || requestType == ITaskWrapper.D_FTP_DIR) {
|
||||
int threadNum = Configuration.getInstance().downloadCfg.getThreadNum();
|
||||
return getFileSize() <= IRecordHandler.SUB_LEN
|
||||
|| getEntity().isGroupChild()
|
||||
|| threadNum == 1
|
||||
? 1
|
||||
: threadNum;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
int threadNum = Configuration.getInstance().downloadCfg.getThreadNum();
|
||||
return getFileSize() <= IRecordHandler.SUB_LEN
|
||||
|| threadNum == 1
|
||||
? 1
|
||||
: threadNum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,23 +17,14 @@ package com.arialyy.aria.ftp.download;
|
||||
|
||||
import com.arialyy.aria.core.TaskRecord;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilder;
|
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilderAdapter;
|
||||
import com.arialyy.aria.core.loader.IRecordHandler;
|
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.FileUtil;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @Author lyy
|
||||
* @Date 2019-09-19
|
||||
*/
|
||||
final class FtpDTTBuilder extends AbsNormalTTBuilder {
|
||||
|
||||
FtpDTTBuilder(AbsTaskWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
final class FtpDTTBuilderAdapter extends AbsNormalTTBuilderAdapter {
|
||||
|
||||
@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) {
|
||||
return new FtpDThreadTaskAdapter(config);
|
||||
@@ -20,6 +20,7 @@ import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
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.NormalTTBuilder;
|
||||
import com.arialyy.aria.core.loader.SubLoader;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,7 @@ final class FtpSubDLoaderUtil extends AbsSubDLoadUtil {
|
||||
@Override protected LoaderStructure buildLoaderStructure() {
|
||||
LoaderStructure structure = new LoaderStructure();
|
||||
structure.addComponent(new SubRecordHandler(getWrapper()))
|
||||
.addComponent(new FtpDTTBuilder(getWrapper()))
|
||||
.addComponent(new NormalTTBuilder(getWrapper(), new FtpDTTBuilderAdapter()))
|
||||
.addComponent(new FtpDFileInfoTask(getWrapper()));
|
||||
structure.accept(getLoader());
|
||||
return structure;
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
*/
|
||||
package com.arialyy.aria.ftp.upload;
|
||||
|
||||
import com.arialyy.aria.core.TaskRecord;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.listener.IEventListener;
|
||||
import com.arialyy.aria.core.loader.AbsNormalLoader;
|
||||
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
|
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilderAdapter;
|
||||
import com.arialyy.aria.core.loader.LoaderStructure;
|
||||
import com.arialyy.aria.core.loader.NormalTTBuilder;
|
||||
import com.arialyy.aria.core.loader.NormalThreadStateManager;
|
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.ftp.FtpTaskOption;
|
||||
@@ -44,7 +49,15 @@ public final class FtpULoaderUtil extends AbsNormalLoaderUtil {
|
||||
structure.addComponent(new FtpURecordHandler((UTaskWrapper) getTaskWrapper()))
|
||||
.addComponent(new NormalThreadStateManager(getListener()))
|
||||
.addComponent(new FtpUFileInfoTask((UTaskWrapper) getTaskWrapper()))
|
||||
.addComponent(new FtpUTTBuilder(getTaskWrapper()));
|
||||
.addComponent(new NormalTTBuilder(getTaskWrapper(), new AbsNormalTTBuilderAdapter() {
|
||||
@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) {
|
||||
return new FtpUThreadTaskAdapter(config);
|
||||
}
|
||||
|
||||
@Override public boolean handleNewTask(TaskRecord record, int totalThreadNum) {
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
structure.accept(getLoader());
|
||||
return structure;
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.ftp.upload;
|
||||
|
||||
import com.arialyy.aria.core.TaskRecord;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilder;
|
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* @Author lyy
|
||||
* @Date 2019-09-19
|
||||
*/
|
||||
final class FtpUTTBuilder extends AbsNormalTTBuilder {
|
||||
|
||||
FtpUTTBuilder(AbsTaskWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) {
|
||||
return new FtpUThreadTaskAdapter(config);
|
||||
}
|
||||
|
||||
@Override public boolean handleNewTask(TaskRecord record, int totalThreadNum) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user