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);
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) {
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());
}
}
}