summaryrefslogtreecommitdiff
path: root/NET/worlds/console/StatRateNode.java
blob: 84e33dd765971cd63c99be962153e8f9995e2aa2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package NET.worlds.console;

import NET.worlds.core.Std;
import java.awt.List;

class StatRateNode extends StatMan implements MainCallback {
   private static StatRateNode _singleInstance = new StatRateNode();
   private int _lastTime;
   private static final int TITLE = 0;
   private static final int BLANK1 = 1;
   private static final int THREADS = 2;
   private int lastQueueLength;

   public static StatRateNode getNode() {
      return _singleInstance;
   }

   private StatRateNode() {
      StatisticsRoot.getNode().addChild(this);
   }

   @Override
   public String toString() {
      return "Active Threads";
   }

   @Override
   synchronized void grabList(List list) {
      super.grabList(list);
      Main.register(this);
   }

   @Override
   synchronized void releaseList(boolean terminalCallback) {
      if (!terminalCallback) {
         Main.unregister(this);
      }

      super.releaseList(terminalCallback);
   }

   @Override
   public synchronized void mainCallback() {
      int thisTime = Std.getFastTime();
      if (thisTime - this._lastTime > 1000) {
         this.updateList();
         this._lastTime = thisTime;
      }
   }

   @Override
   void createList() {
      this._grabbedList.add("Active Thread Statistics", 0);
      this._grabbedList.add("", 1);
      this.lastQueueLength = Main.queueLength();
      this._grabbedList.add("Number main threads: " + this.lastQueueLength, 2);
   }

   @Override
   void updateList() {
      if (Main.queueLength() != this.lastQueueLength) {
         this.lastQueueLength = Main.queueLength();
         this._grabbedList.replaceItem("Number main threads: " + this.lastQueueLength, 2);
      }
   }
}