1 package org.woehlke.computer.kurzweil.tabs.randomwalk;
2
3 import lombok.Getter;
4 import lombok.extern.log4j.Log4j2;
5 import org.woehlke.computer.kurzweil.commons.tabs.TabController;
6
7
8
9
10
11
12
13
14
15
16
17 @Log4j2
18 @Getter
19
20
21
22
23
24
25
26 public class RandomWalkController extends Thread implements TabController, RandomWalk {
27
28 private static final long serialVersionUID = 3642865135701767557L;
29 private final RandomWalkContext tabCtx;
30 private final int threadSleepTime;
31
32 private Boolean goOn;
33
34 public RandomWalkController(
35 RandomWalkContext tabCtx
36 ) {
37 super("Random Walk-Controller");
38 this.tabCtx = tabCtx;
39 this.goOn = Boolean.TRUE;
40 this.threadSleepTime = tabCtx.getCtx().getProperties().getRandomwalk().getControl().getThreadSleepTime();;
41 }
42
43 public void run() {
44 log.info("run() - begin");
45 boolean doIt;
46 do {
47 synchronized (this.goOn) {
48 doIt = goOn.booleanValue();
49 }
50 synchronized (this.tabCtx) {
51
52 this.tabCtx.getTabModel().exec();
53 this.tabCtx.exec();
54 }
55 try { super.sleep( this.threadSleepTime ); }
56 catch (InterruptedException e) { log.info(e.getMessage()); }
57 }
58 while (doIt);
59 log.info("run() - finished");
60 }
61
62 public void exit() {
63 log.info("exit");
64 try {
65 synchronized (goOn) {
66 goOn = Boolean.FALSE;
67 }
68 log.info("join");
69 join();
70 log.info("joined");
71 } catch (InterruptedException e){
72 log.info(e.getMessage());
73 }
74 log.info("exited");
75 }
76
77 }