OSDN Git Service

状態遷移を適切なタイミングで行うように修正。
[coroid/inqubus.git] / frontend / src / saccubus / ConvertStopFlag.java
1 package saccubus;
2
3 /**
4  * <p>
5  * \83^\83C\83g\83\8b\82³\82«\82ã\82Î\82·
6  * </p>
7  * 
8  * <p>
9  * \90à\96¾: \83j\83R\83j\83R\93®\89æ\82Ì\93®\89æ\82ð\83R\83\81\83\93\83g\82Â\82«\82Å\95Û\91
10  * </p>
11  * 
12  * <p>
13  * \92\98\8dì\8c : Copyright (c) 2007 PSI
14  * </p>
15  * 
16  * <p>
17  * \89ï\8eÐ\96¼:
18  * </p>
19  * 
20  * @author \96¢\93ü\97Í
21  * @version 1.0
22  */
23 public class ConvertStopFlag {
24
25     public interface StateChangeListener {
26
27         void changeState(State s);
28     }
29
30     public enum State {
31
32         STOPPING, FINISHED;
33     }
34     private volatile boolean needStop = false;
35     private volatile boolean finished = false;
36     private final StateChangeListener listener;
37
38     public ConvertStopFlag(StateChangeListener listener) {
39         this.listener = listener;
40     }
41
42     public void requestStop() {
43         needStop = true;
44         listener.changeState(State.STOPPING);
45     }
46
47     public boolean needStop() {
48         return needStop;
49     }
50
51     public boolean isFinished() {
52         return finished;
53     }
54
55     public void finished() {
56         finished = true;
57         listener.changeState(State.FINISHED);
58     }
59 }