import org.apache.commons.lang.builder.ToStringBuilder;
import saccubus.MainFrame_AboutBox;
import saccubus.util.WayBackTimeParser;
-import saccubus.worker.Download;
+import saccubus.worker.ConvertProgress;
+import saccubus.worker.DownloadProgress;
+import saccubus.worker.SaccubusCallable.SaccubusListener;
import saccubus.worker.profile.CommentProfile;
import saccubus.worker.profile.DownloadProfile;
import saccubus.worker.profile.GeneralProfile;
return menuBar;
}
+ private class DownloadProgressListener implements SaccubusListener<DownloadProgress> {
+
+ @Override
+ public void process(DownloadProgress progress) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+
+ private class ConvertProgressListener implements SaccubusListener<ConvertProgress> {
+
+ @Override
+ public void process(ConvertProgress progress) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+
+
+
private class DownloadListTransferHandler extends TransferHandler {
private static final long serialVersionUID = 1L;
package yukihane.inqubus.manager;
+import java.io.File;
+import saccubus.worker.profile.ConvertProfile;
+import saccubus.worker.profile.DownloadProfile;
+
/**
*
* @author yuki
*/
-public interface Request {
+public class Request {
+ private static int serialId;
+
+ private final int rowId;
+ private final DownloadProfile downloadProfile;
+ private final String videoId;
+ private final ConvertProfile convertProfile;
+
+ public Request(DownloadProfile download, String videoId, ConvertProfile convert, File video, File comment) {
+ this.rowId = ++serialId;
+ this.downloadProfile = download;
+ this.videoId = videoId;
+ this.convertProfile = convert;
+ }
+
+ public ConvertProfile getConvertProfile() {
+ return convertProfile;
+ }
+
+ public DownloadProfile getDownloadProfile() {
+ return downloadProfile;
+ }
+
+ public String getVideoId() {
+ return videoId;
+ }
+ Integer getRowId() {
+ return rowId;
+ }
}
package yukihane.inqubus.manager;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import saccubus.worker.Convert;
+import saccubus.worker.ConvertResult;
+import saccubus.worker.Download;
+import saccubus.worker.DownloadResult;
+import saccubus.worker.profile.ConvertProfile;
+import saccubus.worker.profile.DownloadProfile;
/**
*
// private final LinkedBlockingQueue<ConvertTask> convertTaskQueue = new LinkedBlockingQueue<>();
private final ExecutorService downloadExecutorService;
private final ExecutorService convertExecutorService;
+ private final Map<Integer, ManageTarget<DownloadResult>> downloadTargets = new HashMap<>();
+ private final Map<Integer, ManageTarget<ConvertResult>> convertTargets = new HashMap<>();
private TaskManager(int maxDownload, int maxConvert) {
downloadExecutorService = Executors.newFixedThreadPool(maxDownload);
convertExecutorService = Executors.newFixedThreadPool(maxConvert);
}
- public void add(Request task) {
- // TODO タスク種判断
- // TODO タスク追加
+ public synchronized boolean add(Request request) {
+ final DownloadProfile dp = request.getDownloadProfile();
+ final ConvertProfile cp = request.getConvertProfile();
+ if (dp != null && !dp.getVideoProfile().isDownload() && !dp.getCommentProfile().isDownload()) {
+ final Future<DownloadResult> future = downloadExecutorService.submit(new Download(dp, request.getVideoId()));
+ downloadTargets.put(request.getRowId(), new ManageTarget<>(request, future));
+ return true;
+
+ } else if (cp != null && cp.isConvert()) {
+ final Future<ConvertResult> future = convertExecutorService.submit(new Convert(cp, dp.getVideoProfile().
+ getLocalFile(), dp.getCommentProfile().getLocalFile()));
+ convertTargets.put(request.getRowId(), new ManageTarget<>(request, future));
+ return true;
+ }
+ return false;
+ }
+}
+
+class ManageTarget<T> {
+
+ private final Request request;
+ private final Future<T> future;
+
+ ManageTarget(Request request, Future<T> future) {
+ this.request = request;
+ this.future = future;
+ }
+
+ Future<T> getFuture() {
+ return future;
+ }
+
+ Request getRequest() {
+ return request;
}
}