OSDN Git Service

d3c5e28e774ad5be648f11a47f923723003d6515
[coroid/inqubus.git] / frontend / src / saccubus / worker / Worker.java
1 package saccubus.worker;
2
3 import java.util.concurrent.Callable;
4
5 /**
6  * 途中経過を報告できるCallableです.
7  *
8  * @author yuki
9  */
10 public abstract class Worker<T, V> implements Callable<T> {
11
12     private static int serialNumber = 0;
13     private final int id;
14     private final WorkerListener<V> listener;
15
16     public Worker(WorkerListener<V> listener) {
17         this.id = ++serialNumber;
18         this.listener = listener;
19     }
20
21     public final int getId() {
22         return id;
23     }
24
25     protected final void publish(V value) {
26         if (listener != null) {
27             listener.process(value);
28         }
29     }
30 }