OSDN Git Service

通知処理実装
authoryukihane <yukihane.feather@gmail.com>
Sat, 27 Aug 2011 15:04:20 +0000 (00:04 +0900)
committeryukihane <yukihane.feather@gmail.com>
Sat, 27 Aug 2011 15:04:20 +0000 (00:04 +0900)
frontend/src/yukihane/inqubus/manager/TaskManage.java
frontend/src/yukihane/inqubus/manager/TaskStatus.java

index d165824..b38531d 100644 (file)
@@ -25,7 +25,7 @@ public class TaskManage {
     private final ExecutorService convertExecutorService;
     private final Map<Integer, ManageTarget<DownloadResult>> downloadTargets = new HashMap<>();
     private final Map<Integer, ManageTarget<ConvertResult>> convertTargets = new HashMap<>();
-    private final TaskManageListener clientListner;
+    private final TaskManageListener clientListener;
 
     public TaskManage() {
         this(1, 1, null);
@@ -38,7 +38,7 @@ public class TaskManage {
     public TaskManage(int maxDownload, int maxConvert, TaskManageListener listener) {
         downloadExecutorService = Executors.newFixedThreadPool(maxDownload);
         convertExecutorService = Executors.newFixedThreadPool(maxConvert);
-        this.clientListner = listener;
+        this.clientListener = listener;
     }
 
     public synchronized boolean add(RequestProcess request) {
@@ -69,59 +69,77 @@ public class TaskManage {
             this.rowId = rowId;
         }
 
+        private void notify(TaskStatus status) {
+            notify(status, 0.0, "");
+        }
+
+        private void notify(TaskStatus status, double percentage, String message) {
+            if (clientListener == null) {
+                return;
+            }
+            clientListener.process(rowId, TaskKind.DOWNLOAD, status, percentage, message);
+        }
+
         @Override
         public void process(DownloadProgress progress) {
-            if (clientListner != null) {
-                // TODO
-                clientListner.process(rowId, TaskKind.DOWNLOAD, TaskStatus.DOING, 0.0, "");
-            }
+            // TOOD
+            notify(TaskStatus.DOING, 0.0, "");
         }
 
         @Override
         public void cancelled() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            notify(TaskStatus.CANCELLED);
         }
 
         @Override
         public void done(DownloadResult result) {
-            throw new UnsupportedOperationException("Not supported yet.");
+            notify(TaskStatus.DONE);
         }
 
         @Override
         public void error(Throwable th) {
-            throw new UnsupportedOperationException("Not supported yet.");
+            notify(TaskStatus.ERROR, 0.0, th.getMessage());
         }
     }
 
     private class ConvertListener implements WorkerListener<ConvertResult, ConvertProgress> {
 
-        private final int id;
+        private final int rowId;
+
+        private ConvertListener(int rowId) {
+            this.rowId = rowId;
+        }
 
-        private ConvertListener(int id) {
-            this.id = id;
+        private void notify(TaskStatus status) {
+            notify(status, 0.0, "");
+        }
+
+        private void notify(TaskStatus status, double percentage, String message) {
+            if (clientListener == null) {
+                return;
+            }
+            clientListener.process(rowId, TaskKind.DOWNLOAD, status, percentage, message);
         }
 
         @Override
         public void process(ConvertProgress progress) {
-            if (clientListner != null) {
-                // TODO
-                clientListner.process(id, TaskKind.CONVERT, TaskStatus.DOING, 0.0, "");
-            }
+            // TOOD
+            notify(TaskStatus.DOING, 0.0, "");
         }
 
         @Override
         public void cancelled() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            notify(TaskStatus.CANCELLED);
         }
 
         @Override
         public void done(ConvertResult result) {
-            throw new UnsupportedOperationException("Not supported yet.");
+            notify(TaskStatus.DONE);
         }
 
         @Override
         public void error(Throwable th) {
-            throw new UnsupportedOperationException("Not supported yet.");
+            notify(TaskStatus.ERROR, 0.0, th.getMessage());
         }
     }
 }
index 7a7735f..a8bb282 100644 (file)
@@ -6,7 +6,7 @@ package yukihane.inqubus.manager;
  */
 public enum TaskStatus {
 
-    READY("待機"), DOING("実行"), DONE("完了");
+    READY("待機"), DOING("実行"), DONE("完了"), CANCELLED("キャンセル"), ERROR("エラー");
     private final String text;
 
     private TaskStatus(String text) {