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 package ffx.potential.bonded;
39
40 import java.io.Serial;
41 import java.util.Enumeration;
42 import java.util.List;
43 import java.util.Objects;
44 import java.util.logging.Logger;
45 import javax.swing.tree.TreeNode;
46 import org.jogamp.java3d.BranchGroup;
47
48
49
50
51
52
53
54
55
56
57
58 public class ROLSP extends MSNode implements ROLS, Runnable {
59
60 @Serial
61 private static final long serialVersionUID = 1L;
62
63 private static final Logger logger = Logger.getLogger(ROLSP.class.getName());
64
65 public static boolean GO_PARALLEL;
66
67 public static int parallelNotDone = 0;
68
69 static {
70 try {
71 GO_PARALLEL = Boolean.parseBoolean(System.getProperty("ffx.lang.parallel", "false"));
72 } catch (Exception e) {
73 GO_PARALLEL = false;
74 }
75 }
76
77 private PARALLELMETHOD parallelMethod = PARALLELMETHOD.NONE;
78 private long startTime = 0;
79 private long threadTime = 0;
80 private RendererCache.ViewModel viewModel = null;
81 private List<BranchGroup> newShapes = null;
82
83
84 public ROLSP() {
85 super("Parallel Node");
86 }
87
88
89
90
91
92
93 @Override
94 public boolean equals(Object o) {
95 return this == o;
96 }
97
98
99 @Override
100 public int hashCode() {
101 MSNode child = (MSNode) getChildAt(0);
102 if (child == null) {
103 return Objects.hash("none");
104 }
105 return Objects.hash(child.hashCode());
106 }
107
108
109 @Override
110 public void run() {
111 switch (parallelMethod) {
112 case SETVIEW:
113 setView(viewModel, newShapes);
114 break;
115 default:
116 return;
117 }
118 threadTime = System.currentTimeMillis() - startTime;
119 logger.info("Start Time: " + startTime + " Total Time: " + threadTime);
120 parallelNotDone--;
121 }
122
123
124 @Override
125 public void setView(RendererCache.ViewModel viewModel, List<BranchGroup> newShapes) {
126
127 if (parallelMethod == PARALLELMETHOD.NONE) {
128 startTime = System.currentTimeMillis();
129 this.viewModel = viewModel;
130 this.newShapes = newShapes;
131 parallelMethod = PARALLELMETHOD.SETVIEW;
132 Thread thread = new Thread(this);
133 thread.setName(getParent().toString() + ": Parallel setView MSM");
134 thread.setPriority(Thread.MAX_PRIORITY);
135 parallelNotDone++;
136 thread.start();
137 } else if (parallelMethod == PARALLELMETHOD.SETVIEW) {
138
139
140 for (Enumeration<TreeNode> e = children(); e.hasMoreElements(); ) {
141 MSNode node = (MSNode) e.nextElement();
142 node.setView(viewModel, newShapes);
143 }
144 parallelMethod = PARALLELMETHOD.NONE;
145 } else {
146 logger.info(" Parallel setView method called by: " + parallelMethod);
147 }
148 }
149
150
151 @Override
152 public String toString() {
153 if (threadTime != 0) {
154 return "Parallel Node " + threadTime + " (msec)";
155 }
156 return "Parallel Node";
157 }
158
159 public enum PARALLELMETHOD {
160 SETVIEW,
161 NONE
162 }
163 }