private static int serialNumber = 0;
private final int id;
- private final WorkerListener<V> listener;
+ private final WorkerListener<T, V> listener;
- public Worker(WorkerListener<V> listener) {
+ public Worker(WorkerListener<T, V> listener) {
this.id = ++serialNumber;
this.listener = listener;
}
public final T call() throws Exception {
try {
final T result = doInBackground();
- // TODO
- publish(null);
+ if (listener != null) {
+ listener.done(result);
+ }
return result;
+ } catch (InterruptedException ex) {
+ if( listener != null){
+ listener.cancelled();
+ }
+ throw ex;
} catch (Throwable th) {
- // TODO
- publish(null);
+ if(listener != null){
+ listener.error(th);
+ }
throw th;
}
}
*
* @author yuki
*/
-public interface WorkerListener<V> {
+public interface WorkerListener<T, V> {
void process(V progress);
+
+ void cancelled();
+
+ void done(T result);
+
+ void error(Throwable th);
}
+++ /dev/null
-package saccubus.worker;
-
-/**
- *
- * @author yuki
- */
-public enum WorkerStatus {
-
- READY, PROGRESS, DONE
-}
import static org.apache.commons.io.FilenameUtils.getBaseName;
import static org.apache.commons.lang.StringUtils.*;
+import static saccubus.worker.convert.ConvertStatus.*;
import java.io.BufferedReader;
import java.io.File;
* @param output 変換後出力動画.
* @throws IOException 変換失敗.
*/
- public Convert(ConvertProfile profile, File video, File comment, WorkerListener<ConvertProgress> listener) {
+ public Convert(ConvertProfile profile, File video, File comment, WorkerListener<ConvertResult, ConvertProgress> listener) {
super(listener);
this.profile = profile;
this.videoFile = video;
if (profile.isCommentOverlay()) {
transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir());
final HideCondition hide = profile.getNgSetting();
- publish(new ConvertProgress("コメントの中間ファイルへの変換中"));
+ publish(new ConvertProgress(PROCESS, "コメントの中間ファイルへの変換中"));
ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.getWord());
}
checkStop();
- publish(new ConvertProgress("動画の変換を開始"));
+ publish(new ConvertProgress(PROCESS, "動画の変換を開始"));
final int code = convert(transformedComment, outputFile);
if (code != 0) {
throw new IOException("ffmpeg実行失敗: " + outputFile.getPath());
}
- publish(new ConvertProgress("変換が正常に終了しました。"));
+ publish(new ConvertProgress(PROCESS, "変換が正常に終了しました。"));
return new ConvertResult(true, outputFile.getName());
} finally {
if (transformedComment != null && transformedComment.exists()) {
String msg;
while ((msg = ebr.readLine()) != null) {
if (msg.startsWith("frame=")) {
- publish(new ConvertProgress(msg));
+ publish(new ConvertProgress(PROCESS, msg));
} else if (!msg.endsWith("No accelerated colorspace conversion found")) {
logger.log(Level.INFO, msg);
}
*/
public class ConvertProgress {
+ private final ConvertStatus status;
private final String message;
- ConvertProgress(String message) {
+ ConvertProgress(ConvertStatus status, String message) {
+ this.status = status;
this.message = message;
}
+ public ConvertStatus getStatus() {
+ return status;
+ }
+
public String getMessage() {
return message;
}
--- /dev/null
+package saccubus.worker.convert;
+
+/**
+ *
+ * @author yuki
+ */
+public enum ConvertStatus {
+
+ READY, PROCESS, DONE, CANCELLED, ERROR;
+}
package saccubus.worker.download;
+import static saccubus.worker.download.DownloadStatus.*;
+
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
* @param listener
* @param flag
*/
- public Download(DownloadProfile profile, String videoId, WorkerListener<DownloadProgress> listener) {
+ public Download(DownloadProfile profile, String videoId, WorkerListener<DownloadResult, DownloadProgress> listener) {
// TODO listener登録
super(listener);
this.videoId = videoId;
@Override
public DownloadResult doInBackground() throws Exception {
- publish(new DownloadProgress("ログイン中"));
+ publish(new DownloadProgress(PROCESS, "ログイン中"));
NicoHttpClient client = null;
nicobrowser.VideoInfo vi = null;
@Override
public void progress(long fileSize, long downloadSize) {
final double vol = (double) downloadSize / (double) fileSize * 100.0;
- publish(new DownloadProgress(String.format("ダウンロード%.2f%%", vol)));
+ publish(new DownloadProgress(PROCESS, String.format("ダウンロード%.2f%%", vol)));
}
});
*/
public class DownloadProgress {
+ private final DownloadStatus status;
private final String message;
- DownloadProgress(String message) {
+ DownloadProgress(DownloadStatus status, String message) {
+ this.status = status;
this.message = message;
}
+ public DownloadStatus getStatus() {
+ return status;
+ }
+
public String getMessage() {
return message;
}
--- /dev/null
+package saccubus.worker.download;
+
+/**
+ *
+ * @author yuki
+ */
+public enum DownloadStatus {
+
+ READY, PROCESS, DONE, CANCELLED, ERROR;
+}
import saccubus.worker.convert.ConvertProgress;
import saccubus.worker.download.DownloadProgress;
import saccubus.worker.WorkerListener;
+import saccubus.worker.convert.ConvertResult;
+import saccubus.worker.download.DownloadResult;
import saccubus.worker.profile.CommentProfile;
import saccubus.worker.profile.DownloadProfile;
import saccubus.worker.profile.GeneralProfile;
return menuBar;
}
- private class DownloadProgressListener implements WorkerListener<DownloadProgress> {
+ private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
@Override
public void process(DownloadProgress progress) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ @Override
+ public void cancelled() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void done(DownloadResult result) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void error(Throwable th) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
- private class ConvertProgressListener implements WorkerListener<ConvertProgress> {
+ private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
@Override
public void process(ConvertProgress progress) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ @Override
+ public void cancelled() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void done(ConvertResult result) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void error(Throwable th) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
package yukihane.inqubus.manager;
-import saccubus.worker.convert.ConvertProgress;
-import saccubus.worker.download.DownloadProgress;
-import saccubus.worker.WorkerListener;
import saccubus.worker.profile.ConvertProfile;
import saccubus.worker.profile.DownloadProfile;
private final int rowId;
private final DownloadProfile downloadProfile;
private final String videoId;
- private final WorkerListener<DownloadProgress> downloadProgressListener;
private final ConvertProfile convertProfile;
- private final WorkerListener<ConvertProgress> convertProgressListener;
- public Request(DownloadProfile download, String videoId, WorkerListener<DownloadProgress> downListener,
- ConvertProfile convert, WorkerListener<ConvertProgress> convListener) {
+ public Request(DownloadProfile download, String videoId, ConvertProfile convert) {
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;
}
-
- WorkerListener<DownloadProgress> getDownloadProgressListener() {
- return downloadProgressListener;
- }
-
- WorkerListener<ConvertProgress> getConvertProgressListener() {
- return convertProgressListener;
- }
}
return false;
}
- private class DownloadListener implements WorkerListener<DownloadProgress> {
+ private class DownloadListener implements WorkerListener<DownloadResult, DownloadProgress> {
private final int rowId;
clientListner.process(rowId, TaskKind.DOWNLOAD, TaskStatus.DOING, 0.0, "");
}
}
+
+ @Override
+ public void cancelled() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void done(DownloadResult result) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void error(Throwable th) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
- private class ConvertListener implements WorkerListener<ConvertProgress> {
+ private class ConvertListener implements WorkerListener<ConvertResult, ConvertProgress> {
private final int id;
clientListner.process(id, TaskKind.CONVERT, TaskStatus.DOING, 0.0, "");
}
}
+
+ @Override
+ public void cancelled() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void done(ConvertResult result) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void error(Throwable th) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
}