修复组合任务在获取子任务信息的过程中,手动停止或删除,没有回调的问题
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.arialyy.aria.sftp;
|
||||
|
||||
import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.loader.IInfoTask;
|
||||
import com.arialyy.aria.core.loader.ILoaderVisitor;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
@@ -32,9 +33,10 @@ import java.io.UnsupportedEncodingException;
|
||||
*/
|
||||
public abstract class AbsSFtpInfoTask<WP extends AbsTaskWrapper> implements IInfoTask {
|
||||
protected String TAG = CommonUtil.getClassName(this);
|
||||
protected Callback callback;
|
||||
private Callback callback;
|
||||
private WP wrapper;
|
||||
private SFtpTaskOption option;
|
||||
private boolean isStop = false, isCancel = false;
|
||||
|
||||
public AbsSFtpInfoTask(WP wp) {
|
||||
this.wrapper = wp;
|
||||
@@ -44,6 +46,28 @@ public abstract class AbsSFtpInfoTask<WP extends AbsTaskWrapper> implements IInf
|
||||
protected abstract void getFileInfo(Session session)
|
||||
throws JSchException, UnsupportedEncodingException, SftpException;
|
||||
|
||||
@Override public void stop() {
|
||||
isStop = true;
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
isCancel = true;
|
||||
}
|
||||
|
||||
protected void handleFail(AriaException e, boolean needRetry) {
|
||||
if (isStop || isCancel){
|
||||
return;
|
||||
}
|
||||
callback.onFail(getWrapper().getEntity(), e, needRetry);
|
||||
}
|
||||
|
||||
protected void onSucceed(CompleteInfo info){
|
||||
if (isStop || isCancel){
|
||||
return;
|
||||
}
|
||||
callback.onSucceed(getWrapper().getKey(), info);
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
try {
|
||||
FtpUrlEntity entity = option.getUrlEntity();
|
||||
|
||||
@@ -39,7 +39,7 @@ final class SFtpDInfoTask extends AbsSFtpInfoTask<DTaskWrapper> {
|
||||
}
|
||||
|
||||
@Override protected void getFileInfo(Session session) throws JSchException,
|
||||
UnsupportedEncodingException, SftpException {
|
||||
UnsupportedEncodingException {
|
||||
SFtpTaskOption option = (SFtpTaskOption) getWrapper().getTaskOption();
|
||||
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
|
||||
channel.connect(1000);
|
||||
@@ -60,10 +60,9 @@ final class SFtpDInfoTask extends AbsSFtpInfoTask<DTaskWrapper> {
|
||||
getWrapper().getEntity().setFileSize(attr.getSize());
|
||||
CompleteInfo info = new CompleteInfo();
|
||||
info.code = 200;
|
||||
callback.onSucceed(getWrapper().getKey(), info);
|
||||
onSucceed(info);
|
||||
} else {
|
||||
callback.onFail(getWrapper().getEntity(),
|
||||
new AriaSFTPException(String.format("文件不存在,remotePath:%s", remotePath)), false);
|
||||
handleFail(new AriaSFTPException(String.format("文件不存在,remotePath:%s", remotePath)), false);
|
||||
}
|
||||
channel.disconnect();
|
||||
}
|
||||
|
||||
@@ -64,6 +64,6 @@ final class SFtpUInfoTask extends AbsSFtpInfoTask<UTaskWrapper> {
|
||||
info.code = isComplete ? ISCOMPLETE : 200;
|
||||
info.obj = attr;
|
||||
channel.disconnect();
|
||||
callback.onSucceed(getWrapper().getKey(), info);
|
||||
onSucceed(info);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user