@Override public String getName() { return getRootNode().getName(); }
@Override public int getNodeCount() { return getRootNode().getNodeCount(); }
@Override public void release() { getRootNode().release(); }
public NonConcurrentTreeNode getOrCreateNode(final NonConcurrentTreeNode parent, final String child, final DataTreeNodeInitializer creator) { parent.requireNodeDB(); CacheKey key = new CacheKey(parent.nodeDB(), child); DBKey dbkey = key.dbkey(); NonConcurrentTreeNode node = source.get(dbkey); if (node != null) { node.initNode(this, dbkey, key.name); return node; } else { // create a new node NonConcurrentTreeNode newNode = new NonConcurrentTreeNode(); newNode.init(this, dbkey, key.name); if (creator != null) { creator.onNewNode(newNode); } source.put(dbkey, newNode); parent.updateNodeCount(1); return newNode; } }
@Test public void recursiveDelete() throws Exception { log.info("recursiveDelete"); File dir = makeTemporaryDirectory(); try { NonConcurrentTree tree = new TreeBuilder(dir).singleThreadedTree(); NonConcurrentTreeNode root = tree.getRootNode(); NonConcurrentTreeNode parent = tree.getOrCreateNode(root, "0", null); for (int j = 0; j < TreeCommonParameters.cleanQMax; j++) { NonConcurrentTreeNode child = tree.getOrCreateNode(parent, Integer.toString(j), null); assertNotNull(child); assertEquals(Integer.toString(j), child.getName()); parent.release(); parent = child; } parent.release(); tree.deleteNode(root, "0"); assertEquals(0, root.getNodeCount()); tree.close(false, close); } finally { if (dir != null) { LessFiles.deleteDir(dir); } } }
@Test public void maximumNodeIdentifier() throws Exception { File dir = makeTemporaryDirectory(); try { NonConcurrentTree tree = new TreeBuilder(dir).singleThreadedTree(); NonConcurrentTreeNode root = tree.getRootNode(); for (int i = 0; i < 1000; i++) { NonConcurrentTreeNode node = tree.getOrCreateNode(root, Integer.toString(i), null); assertNotNull(node); assertEquals(Integer.toString(i), node.getName()); NonConcurrentTreeNode child = tree.getOrCreateNode(node, Integer.toString(i), null); child.release(); node.release(); } assertTrue(tree.setNextNodeDB(Integer.MAX_VALUE)); for (int i = 1000; i < 2000; i++) { NonConcurrentTreeNode node = tree.getOrCreateNode(root, Integer.toString(i), null); assertNotNull(node); assertEquals(Integer.toString(i), node.getName()); NonConcurrentTreeNode child = tree.getOrCreateNode(node, Integer.toString(i), null); child.release(); node.release(); } tree.close(false, close); } finally { if (dir != null) { LessFiles.deleteDir(dir); } } }
public static NonConcurrentTreeNode getTreeRoot(NonConcurrentTree tree) { NonConcurrentTreeNode node = new NonConcurrentTreeNode(); node.tree = tree; node.nodedb = 1L; return node; }
protected synchronized void markAlias() { bitSet(ALIAS); }
@Override public long getCounter() { return getRootNode().getCounter(); }
@Override public Map<String, TreeNodeData> getDataMap() { return getRootNode().getDataMap(); }
@Override public boolean deleteNode(String node) { return getRootNode().deleteNode(node); }
@Override public DataTreeNodeActor getData(String key) { return getRootNode().getData(key); }
@Test public void getOrCreateOneThread() throws Exception { log.info("getOrCreateOneThread"); File dir = makeTemporaryDirectory(); try { NonConcurrentTree tree = new NonConcurrentTree(dir, 100, 100, NonConcurrentPage.NonConcurrentPageFactory.singleton); NonConcurrentTreeNode root = tree.getRootNode(); for (int i = 0; i < 1000; i++) { NonConcurrentTreeNode node = tree.getOrCreateNode(root, Integer.toString(i), null); assertNotNull(node); assertEquals(Integer.toString(i), node.getName()); } for (int i = 0; i < 1000; i++) { NonConcurrentTreeNode node = tree.getNode(root, Integer.toString(i), true); assertNotNull(node); assertEquals(Integer.toString(i), node.getName()); } tree.close(false, close); } finally { if (dir != null) { LessFiles.deleteDir(dir); } } }
NonConcurrentTreeNode node = tree.getOrCreateNode(root, Integer.toString(i), null); assertNotNull(node); assertEquals(Integer.toString(i), node.getName()); NonConcurrentTreeNode child = tree.getOrCreateNode(node, Integer.toString(i), null); assertNotNull(child);