980 cache.put(info.getNode(), info);
981 cacheQueue.addFirst(info);
982 }
983 } // for
984 } // synchronized
985
986 // wake up the worker
987 synchronized (cacheWorker) {
988 cacheWorker.notify();
989 }
990 }
991
992 /**
993 * Invalidate all collected node information.
994 * This is likely used when the internal contents of the parameters have
995 * changed. If the cache is not invalidated at certain points, rendering
996 * of the tree may be incorrect.
997 */
998 void invalidateNodeInfo() {
999 synchronized (htLock) {
1000 Enumeration e = cache.keys();
1001 while (e.hasMoreElements()) {
1002 (cache.get(e.nextElement())).invalidate();
1003 } // while
1004
1005 cache = new Hashtable<>();
1006 cacheQueue = new LinkedList<>();
1007 suspendedQueue = new LinkedList<>();
1008 }
1009
1010 // reprocess any needed nodes
1011 Iterator it = relevantNodes.iterator();
1012 while (it.hasNext()) {
1013 TT_TreeNode tn = (TT_TreeNode) it.next();
1014 if (tn instanceof TT_BasicNode) {
1015 getNodeInfo(((TT_BasicNode) tn).getTableNode(), false);
1016 }
1017 } // while
1018 }
1019
1020 /**
1021 * Invalidate any collected data about the given node.
1022 * This operation includes stopping any thread scanning for info and
1023 * removing the entry from the cache.
1024 *
1025 * @param node The node to invalidate in the cache. Must not be null.
1026 * @deprecated The cache will be smart enough to not need this.
1027 */
1028 void invalidateNodeInfo(TestResultTable.TreeNode node) {
1029 invalidateNodeInfo(new TestResultTable.TreeNode[]{node});
1030 }
1031
1032 /**
1033 * Trusting method which assumes that the given TRT is compatible with the
1320 }
1321 if (selection != null &&
1322 selection.getNode().isRoot() && // trying to avoid root
1323 (cacheQueue.size() > 0 || suspendedQueue.size() > 0)) {
1324 cacheQueue.addFirst(selection);
1325 return selectByQueuing();
1326 }
1327
1328 return selection;
1329 }
1330
1331 /**
1332 * Select the deepest node in the cacheQueue.
1333 */
1334 private TT_NodeCache selectByDepth() {
1335 // note must already have htLock
1336 // note with this algo., the suspend and cache queues are
1337 // basically equivalent
1338 TT_NodeCache selected = null;
1339 int depth = -1;
1340 LinkedList theList = cacheQueue;
1341 boolean notDone = true;
1342 int count = 0;
1343
1344 if (cacheQueue.size() == 0) {
1345 if (suspendedQueue.size() == 0) {
1346 notDone = false;
1347 } else {
1348 theList = suspendedQueue;
1349 }
1350 } else {
1351 }
1352
1353 while (notDone) {
1354 TT_NodeCache possible = (TT_NodeCache) (theList.get(count));
1355 int thisDepth = TestResultTable.getObjectPath(possible.getNode()).length;
1356
1357 if (thisDepth > depth) {
1358 theList.remove(count);
1359
1360 // requeue the last deepest node found
1361 if (selected != null) {
1362 cacheQueue.addFirst(selected);
1363 // adjust the counter since we just added one
1364 if (theList == cacheQueue) {
1365 count++;
1366 }
1367 }
1368 depth = thisDepth;
1369 selected = possible;
1370 }
1371
1372 count++;
1373 if (count >= theList.size()) {
1374 if (theList == suspendedQueue) {
|
980 cache.put(info.getNode(), info);
981 cacheQueue.addFirst(info);
982 }
983 } // for
984 } // synchronized
985
986 // wake up the worker
987 synchronized (cacheWorker) {
988 cacheWorker.notify();
989 }
990 }
991
992 /**
993 * Invalidate all collected node information.
994 * This is likely used when the internal contents of the parameters have
995 * changed. If the cache is not invalidated at certain points, rendering
996 * of the tree may be incorrect.
997 */
998 void invalidateNodeInfo() {
999 synchronized (htLock) {
1000 Enumeration<TestResultTable.TreeNode> e = cache.keys();
1001 while (e.hasMoreElements()) {
1002 (cache.get(e.nextElement())).invalidate();
1003 } // while
1004
1005 cache = new Hashtable<>();
1006 cacheQueue = new LinkedList<>();
1007 suspendedQueue = new LinkedList<>();
1008 }
1009
1010 // reprocess any needed nodes
1011 Iterator<TT_TreeNode> it = relevantNodes.iterator();
1012 while (it.hasNext()) {
1013 TT_TreeNode tn = it.next();
1014 if (tn instanceof TT_BasicNode) {
1015 getNodeInfo(((TT_BasicNode) tn).getTableNode(), false);
1016 }
1017 } // while
1018 }
1019
1020 /**
1021 * Invalidate any collected data about the given node.
1022 * This operation includes stopping any thread scanning for info and
1023 * removing the entry from the cache.
1024 *
1025 * @param node The node to invalidate in the cache. Must not be null.
1026 * @deprecated The cache will be smart enough to not need this.
1027 */
1028 void invalidateNodeInfo(TestResultTable.TreeNode node) {
1029 invalidateNodeInfo(new TestResultTable.TreeNode[]{node});
1030 }
1031
1032 /**
1033 * Trusting method which assumes that the given TRT is compatible with the
1320 }
1321 if (selection != null &&
1322 selection.getNode().isRoot() && // trying to avoid root
1323 (cacheQueue.size() > 0 || suspendedQueue.size() > 0)) {
1324 cacheQueue.addFirst(selection);
1325 return selectByQueuing();
1326 }
1327
1328 return selection;
1329 }
1330
1331 /**
1332 * Select the deepest node in the cacheQueue.
1333 */
1334 private TT_NodeCache selectByDepth() {
1335 // note must already have htLock
1336 // note with this algo., the suspend and cache queues are
1337 // basically equivalent
1338 TT_NodeCache selected = null;
1339 int depth = -1;
1340 LinkedList<TT_NodeCache> theList = cacheQueue;
1341 boolean notDone = true;
1342 int count = 0;
1343
1344 if (cacheQueue.size() == 0) {
1345 if (suspendedQueue.size() == 0) {
1346 notDone = false;
1347 } else {
1348 theList = suspendedQueue;
1349 }
1350 } else {
1351 }
1352
1353 while (notDone) {
1354 TT_NodeCache possible = (theList.get(count));
1355 int thisDepth = TestResultTable.getObjectPath(possible.getNode()).length;
1356
1357 if (thisDepth > depth) {
1358 theList.remove(count);
1359
1360 // requeue the last deepest node found
1361 if (selected != null) {
1362 cacheQueue.addFirst(selected);
1363 // adjust the counter since we just added one
1364 if (theList == cacheQueue) {
1365 count++;
1366 }
1367 }
1368 depth = thisDepth;
1369 selected = possible;
1370 }
1371
1372 count++;
1373 if (count >= theList.size()) {
1374 if (theList == suspendedQueue) {
|