+package saccubus.worker;
+
+import java.util.concurrent.Callable;
+
+/**
+ * 途中経過を報告できるCallableです.
+ *
+ * @author yuki
+ */
+public abstract class Worker<T, V> implements Callable<T> {
+ private static int serialNumber = 0;
+
+ private final int id;
+ private final WorkerListener<V> listener;
+
+ public Worker(WorkerListener<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 WorkerListener<V> {
+
+ void process(V progress);
+ }
+}