From: yukihane Date: Fri, 26 Aug 2011 08:00:12 +0000 (+0900) Subject: マネージャ実装 X-Git-Tag: test20110903_ver2.a.0~118^2~22 X-Git-Url: http://git.sourceforge.jp/view?p=coroid%2Finqubus.git;a=commitdiff_plain;h=aa6743a29aabff4ce973564def5b90494da483d2 マネージャ実装 --- diff --git a/frontend/src/yukihane/inqubus/gui/MainFrame.java b/frontend/src/yukihane/inqubus/gui/MainFrame.java index f246344..3b05f30 100644 --- a/frontend/src/yukihane/inqubus/gui/MainFrame.java +++ b/frontend/src/yukihane/inqubus/gui/MainFrame.java @@ -49,7 +49,9 @@ import org.apache.commons.lang.StringUtils; 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; @@ -567,6 +569,24 @@ public class MainFrame extends JFrame { return menuBar; } + private class DownloadProgressListener implements SaccubusListener { + + @Override + public void process(DownloadProgress progress) { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + private class ConvertProgressListener implements SaccubusListener { + + @Override + public void process(ConvertProgress progress) { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + + private class DownloadListTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; diff --git a/frontend/src/yukihane/inqubus/manager/Request.java b/frontend/src/yukihane/inqubus/manager/Request.java index 57bddb5..9833a16 100644 --- a/frontend/src/yukihane/inqubus/manager/Request.java +++ b/frontend/src/yukihane/inqubus/manager/Request.java @@ -1,9 +1,41 @@ 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; + } } diff --git a/frontend/src/yukihane/inqubus/manager/TaskManager.java b/frontend/src/yukihane/inqubus/manager/TaskManager.java index 6bdeb41..ea5d39f 100644 --- a/frontend/src/yukihane/inqubus/manager/TaskManager.java +++ b/frontend/src/yukihane/inqubus/manager/TaskManager.java @@ -1,7 +1,16 @@ 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; /** * @@ -13,14 +22,47 @@ public class TaskManager { // private final LinkedBlockingQueue convertTaskQueue = new LinkedBlockingQueue<>(); private final ExecutorService downloadExecutorService; private final ExecutorService convertExecutorService; + private final Map> downloadTargets = new HashMap<>(); + private final Map> 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 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 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 { + + private final Request request; + private final Future future; + + ManageTarget(Request request, Future future) { + this.request = request; + this.future = future; + } + + Future getFuture() { + return future; + } + + Request getRequest() { + return request; } }