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