1 package saccubus.worker;
3 import java.util.concurrent.Callable;
6 * 途中経過を報告できるCallableです.
10 public abstract class Worker<T, V> implements Callable<T> {
12 private static int serialNumber = 0;
14 private final WorkerListener<T, V> listener;
16 public Worker(WorkerListener<T, V> listener) {
17 this.id = ++serialNumber;
18 this.listener = listener;
22 public final T call() throws Exception {
24 final T result = doInBackground();
25 if (listener != null) {
26 listener.done(result);
29 } catch (InterruptedException ex) {
30 if( listener != null){
34 } catch (Throwable th) {
42 protected abstract T doInBackground() throws Exception;
44 public final int getId() {
48 protected final void publish(V value) {
49 if (listener != null) {
50 listener.process(value);