* 動画を(コメント付きに)変換するワーカクラス.
* @author yuki
*/
-public class Convert extends SaccubusCallable<ConvertResult, ConvertProgress> {
+public class Convert extends Worker<ConvertResult, ConvertProgress> {
private static final Logger logger = Logger.getLogger(Convert.class.getName());
private final ConvertProfile profile;
private final File videoFile;
private final File commentFile;
+ public Convert(ConvertProfile profile, File video, File comment) {
+ this(profile, video, comment, null);
+ }
+
/**
* 変換ワーカコンストラクタ.
* @param profile 変換用プロファイル.
* @param output 変換後出力動画.
* @throws IOException 変換失敗.
*/
- public Convert(ConvertProfile profile, File video, File comment) {
- // TODO listener登録
- super(null);
+ public Convert(ConvertProfile profile, File video, File comment, SaccubusListener<ConvertProgress> listener) {
+ super(listener);
this.profile = profile;
this.videoFile = video;
this.commentFile = comment;
* @author 未入力
* @version 1.0
*/
-public class Download extends SaccubusCallable<DownloadResult, DownloadProgress> {
+public class Download extends Worker<DownloadResult, DownloadProgress> {
private static final Logger logger = Logger.getLogger(Download.class.getName());
private final DownloadProfile profile;
private final String videoId;
+ public Download(DownloadProfile profile, String videoId) {
+ this(profile, videoId, null);
+ }
+
/**
* コンバータを構築します.
* @param videoId 対象となる動画のID.
* @param listener
* @param flag
*/
- public Download(DownloadProfile profile, String videoId) {
+ public Download(DownloadProfile profile, String videoId, SaccubusListener<DownloadProgress> listener) {
// TODO listener登録
- super(null);
+ super(listener);
this.videoId = videoId;
this.profile = profile;
}
//// getStopFlag().finished();
// }
// }
-
// // TODO Runnableを実装しなくなったので削除する
// public void run() {
// try {
// }
// }
// }
-
/**
* HttpClientを生成し, ニコニコ動画サーバへログインします.
* @return 生成したHttpClientインスタンス.
+++ /dev/null
-package saccubus.worker;
-
-import java.util.concurrent.Callable;
-
-/**
- * 途中経過を報告できるCallableです.
- *
- * @author yuki
- */
-public abstract class SaccubusCallable<T, V> implements Callable<T> {
- private static int serialNumber = 0;
-
- private final int id;
- private final SaccubusListener<V> listener;
-
- public SaccubusCallable(SaccubusListener<V> listener) {
- this.id = ++serialNumber;
- this.listener = listener;
- }
-
- public final int getId() {
- return id;
- }
-
- protected final void publish(V value) {
- if (listener != null) {
- listener.process(value);
- }
- }
-
- public interface SaccubusListener<V> {
-
- void process(V progress);
- }
-}
import saccubus.util.WayBackTimeParser;
import saccubus.worker.ConvertProgress;
import saccubus.worker.DownloadProgress;
-import saccubus.worker.SaccubusCallable.SaccubusListener;
+import saccubus.worker.Worker.SaccubusListener;
import saccubus.worker.profile.CommentProfile;
import saccubus.worker.profile.DownloadProfile;
import saccubus.worker.profile.GeneralProfile;
import saccubus.worker.profile.VideoProfile;
import yukihane.Util;
import yukihane.inqubus.Config;
+import yukihane.inqubus.manager.TaskManager;
import yukihane.inqubus.model.Target;
import yukihane.inqubus.model.TargetsTableModel;
private static final String FILE_OUTPUTFIELD_TOOLTIP
= "ファイル命名規則入力します。";
private final TargetsTableModel targetModel = new TargetsTableModel();
+ private final TaskManager taskManager;
+ private final DownloadProgressListener downloadProgressListener = new DownloadProgressListener();
+ private final ConvertProgressListener convertProgressListener = new ConvertProgressListener();
/** Creates new form MainFrame */
public MainFrame() {
initInputPanel();
pnlMain.setTransferHandler(new DownloadListTransferHandler());
tblDisplay.setTransferHandler(new TableTransferHandler());
+
+ final Config p = Config.INSTANCE;
+ // TODO コンフィグからスレッド数
+ taskManager = new TaskManager(1, 1);
+
}
private class ApplyActionListener implements ActionListener {
package yukihane.inqubus.manager;
import java.io.File;
+import saccubus.worker.ConvertProgress;
+import saccubus.worker.DownloadProgress;
+import saccubus.worker.Worker.SaccubusListener;
import saccubus.worker.profile.ConvertProfile;
import saccubus.worker.profile.DownloadProfile;
* @author yuki
*/
public class Request {
- private static int serialId;
+ private static int serialId;
private final int rowId;
private final DownloadProfile downloadProfile;
private final String videoId;
+ private final SaccubusListener<DownloadProgress> downloadProgressListener;
private final ConvertProfile convertProfile;
+ private final SaccubusListener<ConvertProgress> convertProgressListener;
- public Request(DownloadProfile download, String videoId, ConvertProfile convert, File video, File comment) {
+ public Request(DownloadProfile download, String videoId, SaccubusListener<DownloadProgress> downListener,
+ ConvertProfile convert, SaccubusListener<ConvertProgress> convListener) {
this.rowId = ++serialId;
this.downloadProfile = download;
this.videoId = videoId;
+ this.downloadProgressListener = downListener;
this.convertProfile = convert;
+ this.convertProgressListener = convListener;
}
public ConvertProfile getConvertProfile() {
Integer getRowId() {
return rowId;
}
+
+ SaccubusListener<DownloadProgress> getDownloadProgressListener() {
+ return downloadProgressListener;
+ }
+
+ SaccubusListener<ConvertProgress> getConvertProgressListener() {
+ return convertProgressListener;
+ }
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import saccubus.worker.Convert;
import saccubus.worker.ConvertResult;
import saccubus.worker.Download;
*/
public class TaskManager {
-// private final LinkedBlockingQueue<DownloadTask> downloadTaskQueue = new LinkedBlockingQueue<>();
-// 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) {
+ public TaskManager(int maxDownload, int maxConvert) {
downloadExecutorService = Executors.newFixedThreadPool(maxDownload);
convertExecutorService = Executors.newFixedThreadPool(maxConvert);
}
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()));
+ final Download task = new Download(dp, request.getVideoId(),
+ request.getDownloadProgressListener());
+ final Future<DownloadResult> future = downloadExecutorService.submit(task);
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()));
+ final Convert task = new Convert(cp, dp.getVideoProfile().getLocalFile(), dp.getCommentProfile().
+ getLocalFile(), request.getConvertProgressListener());
+ final Future<ConvertResult> future = convertExecutorService.submit(task);
convertTargets.put(request.getRowId(), new ManageTarget<>(request, future));
return true;
}