OSDN Git Service

d266c93bb962a28fea5b4bbf57588daaef7a5e8b
[coroid/inqubus.git] / frontend / src / saccubus / worker / SaccubusCallable.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 SaccubusCallable<T, V> implements Callable<T> {
11     private static int serialNumber = 0;
12
13     private final int id;
14     private final SaccubusListener<V> listener;
15
16     public SaccubusCallable(SaccubusListener<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
31     public interface SaccubusListener<V> {
32
33         void process(V progress);
34     }
35 }