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