public void reset() { this.tabs = null; for (NodeCache current : this.children.values()) { current.reset(); } this.children.clear(); }
/** * This method returns the tabs for a given node from the cache. Tabs are cached per * sessionTreeNode. If the tabs don't exist in the cache, they are created. * * @param node INode for which to retrieve tabs. * @return List of tabs. */ private static List<IDetailTab> getTabs(INode node) { if (_logger.isDebugEnabled()) { _logger.debug("Loading tabs for: " + node.getUniqueIdentifier()); } NodeCache nodeCache = _sessionTabCache.get(node.getSession()); if (nodeCache == null) { // create cache nodeCache = new NodeCache(); _sessionTabCache.put(node.getSession(), nodeCache); } nodeCache = findNodeCache(node, nodeCache); List<IDetailTab> tabs = nodeCache.getTabs(); if (tabs == null) { // create tabs & store for later tabs = createTabs(node); nodeCache.setTabs(tabs); } // display parent details if we have nothing for this node.. if ((tabs == null || tabs.size() == 0) && node.getParent() != null) { return getTabs(node.getParent()); } return tabs; }
@Test public void testCache() throws Exception { NodeCache c = new NodeCache( "D:\\rubydev\\workspace\\TwitterCrawler\\neo\\src\\test\\org\\alpengeist\\cache.csv"); c.writeCache( new File( "D:\\rubydev\\workspace\\TwitterCrawler\\neo\\src\\test\\org\\alpengeist\\cache_out.csv")); }
/** * Clear the detail tab cache for a given node. * * @param node INode to remove from cache. */ public static void clearCacheForNode(INode node) { if (_logger.isDebugEnabled()) { _logger.debug("Clearing tab cache for: " + node.getUniqueIdentifier()); } NodeCache nodeCache = _sessionTabCache.get(node.getSession()); if (nodeCache != null) { nodeCache = findNodeCache(node, nodeCache); nodeCache.reset(); } }
/** 监测节点的 创建, 更新 */ @Test public void testWatcherNode() throws Exception { // 节点事件监听 final NodeCache watcher = new NodeCache(client, ZK_PATH + "/node"); watcher .getListenable() .addListener( new NodeCacheListener() { @Override public void nodeChanged() throws Exception { System.out.println( "NodeCache changed, data is: " + new String(watcher.getCurrentData().getData())); } }); watcher.start(false); Thread.sleep(Integer.MAX_VALUE); }
/** * Get all of the paths through which the specified node is accessible, including all paths based * upon the node's {@link CachedNode#getParentKey(NodeCache) parent} (which can potentially have * multiple paths) and upon the node's {@link CachedNode#getAdditionalParentKeys(NodeCache) * additional parents} (which each can potentially have multiple paths). * * @param node the node for which the paths are to be returned; may not be null * @return the paths for the node; never null but possibly empty */ public Iterable<Path> getPaths(CachedNode node) { NodeKey key = node.getKey(); List<Path> pathList = paths.get(key); if (pathList == null) { // Compute the node's path ... Segment nodeSegment = node.getSegment(cache); NodeKey parentKey = node.getParentKey(cache); if (parentKey == null) { // This is the root node ... pathList = Collections.singletonList(node.getPath(cache)); } else { // This is not the root node, so add a path for each of the parent's valid paths ... CachedNode parent = cache.getNode(parentKey); if (parent == null && removedCache != null) { // This is a removed node, so check the removed cache ... parent = removedCache.getNode(parentKey); } pathList = new LinkedList<Path>(); for (Path parentPath : getPaths(parent)) { Path path = pathFactory.create(parentPath, nodeSegment); pathList.add(path); } // Get the additional parents ... Set<NodeKey> additionalParentKeys = getAdditionalParentKeys(node, cache); // There is at least one additional parent ... for (NodeKey additionalParentKey : additionalParentKeys) { parent = cache.getNode(additionalParentKey); for (Path parentPath : getPaths(parent)) { Path path = pathFactory.create(parentPath, nodeSegment); pathList.add(path); } } } assert pathList != null; pathList = Collections.unmodifiableList(pathList); paths.put(key, pathList); } return pathList; }
private static NodeCache findNodeCache(INode pNode, NodeCache pNodeCache) { NodeCache found = pNode.getParent() == null ? pNodeCache : findNodeCache(pNode.getParent(), pNodeCache); return found.getChild(pNode); }