public DiscoveryTreeNode fromCache(VersionedCache other) { this.cacheVersion = other.cacheVersion(); this.name = other.name(); this.data(other.data()); return this; } }
protected DiscoveryTreeNode getOrCreateRoot(VersionedCache inputCache) { DiscoveryTreeNode tmpRoot = root; if (isMatch(tmpRoot, inputCache)) { return tmpRoot; } synchronized (lock) { if (isExpired(root, inputCache)) { // not initialized or inputCache newer than root, create new root root = new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion()); return root; } if (root.isSameVersion(inputCache)) { // reuse root directly return root; } } // root newer than inputCache, it's a minimal probability event: // 1) thread 1, use v1 inputCache, run into getOrCreateRoot, but did not run any code yet, suspend and switch to thread 2 // 2) thread 2, use v2 inputCache, v2 > v1, create new root // 3) thread 1 go on, then root is newer than inputCache // but if create old children in new version root, it's a wrong logic // so just create a temporary root for the inputCache, DO NOT assign to root return new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion()); }
public DiscoveryTreeNode fromCache(VersionedCache other) { this.cacheVersion = other.cacheVersion(); this.name = other.name(); this.data(other.data()); return this; } }
protected DiscoveryTreeNode getOrCreateRoot(VersionedCache inputCache) { DiscoveryTreeNode tmpRoot = root; if (isMatch(tmpRoot, inputCache)) { return tmpRoot; } synchronized (lock) { if (isExpired(root, inputCache)) { // not initialized or inputCache newer than root, create new root root = new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion()); return root; } if (root.isSameVersion(inputCache)) { // reuse root directly return root; } } // root newer than inputCache, it's a minimal probability event: // 1) thread 1, use v1 inputCache, run into getOrCreateRoot, but did not run any code yet, suspend and switch to thread 2 // 2) thread 2, use v2 inputCache, v2 > v1, create new root // 3) thread 1 go on, then root is newer than inputCache // but if create old children in new version root, it's a wrong logic // so just create a temporary root for the inputCache, DO NOT assign to root return new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion()); }