final Config p = Config.INSTANCE;
// TODO コンフィグからスレッド数
- taskManager = new TaskManage(1, 1, new GuiTaskManageListener());
+ // TODO downloadの連続処理時待ち時間設定も必要...
+ taskManager = new TaskManage(1, 2, new GuiTaskManageListener());
}
private class GuiTaskManageListener implements TaskManageListener {
package yukihane.inqubus.manager;
+import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
@Override
public void done(DownloadResult result) {
super.done(result);
- // TODO 変換が必要なら変換キューに入れる
+ synchronized (TaskManage.this) {
+ final ManageTarget<DownloadResult> mt = downloadTargets.remove(Integer.valueOf(getRowId()));
+ final RequestProcess request = mt.getRequest();
+ if (request.getConvertProfile().isConvert()) {
+ final DownloadProfile dp = request.getDownloadProfile();
+ final File video = (dp.getVideoProfile().isDownload()) ? result.getDownloadVideo() : dp.
+ getVideoProfile().getLocalFile();
+ final File comment = (dp.getCommentProfile().isDownload()) ? result.getDownloadComment() : dp.
+ getCommentProfile().getLocalFile();
+ final ConvertProfile cp = request.getConvertProfile();
+ final Convert task = new Convert(cp, video, comment, new ConvertListener(getRowId()));
+ final Future<ConvertResult> future = convertExecutorService.submit(task);
+ convertTargets.put(request.getRowId(), new ManageTarget<>(request, future));
+ }
+ // TODO 変換が必要なら変換キューに入れる
+ }
+
}
@Override
protected TaskKind getKind() {
return TaskKind.CONVERT;
}
+
+ @Override
+ public void done(ConvertResult result) {
+ super.done(result);
+ synchronized (TaskManage.this) {
+ convertTargets.remove(getRowId());
+ }
+ }
}
abstract class TaskManageInnerListener<T, V extends PercentageReportable & MessageReportable> implements WorkerListener<T, V> {
this.rowId = rowId;
}
+ protected int getRowId() {
+ return rowId;
+ }
+
private void notify(TaskStatus status) {
notify(status, 0.0, "");
}