} // removeSelf() /* **************************************************************************** * find() **************************************************************************** */ /** * Finds subsegments under this CacheNode. Will popluate oCachedDescriptors * along the way. * @param oAuth - The authority to search for * @param nNextSubsegment - The index of the next subsegment to search for * @param bCompleteChain - Whether or not a descriptor is necessary for all * subsegments in oAuth * @param oCachedDescriptors - If not null, stores descriptors found in the * cache, in the order of the subsegments. */ CacheResult find( XRIAuthority oAuth, int nNextSubsegment, bool bCompleteChain, Vector oCachedDescriptors) { // if there are no new subsegments to get, just return "this", we are done XRISubSegment oSubSegment = oAuth.getSubSegmentAt(nNextSubsegment); if (oSubSegment == null) { return new CacheResult(this, nNextSubsegment); } // also return if we can't find the next subsegment CacheNode oNode = find(oSubSegment.toString()); if (oNode == null) { return new CacheResult(this, nNextSubsegment); } // if the found node doesn't have a cached value, potentially bail if ( (oNode.moCacheValue == null) || (oNode.moCacheValue.getDescriptor() == null)) { if (bCompleteChain) { return new CacheResult(this, nNextSubsegment); } } else if (oCachedDescriptors != null) { oCachedDescriptors.add(oNode.moCacheValue.getDescriptor()); } // N O T E: The direcory metaphore used here allows for directories // to be "empty" (null moCacheValue) and still have subdirs. // // As we recurse up, if the returned CacheNode has an empty // moCacheValue, we'll return "this" unless they caller does not // allow partials. return oNode.find( oAuth, nNextSubsegment + 1, bCompleteChain, oCachedDescriptors); } // find()
} // find() /* **************************************************************************** * mkdir() **************************************************************************** */ /** * Creates an entry under this CacheNode for the given subsegments * @param oAuth - The authority to add * @param n - The index of the subsegment to start with * @param iTargetDepth - The index of the subsegment to stop at. * @return The final CacheNode created by this method */ CacheNode mkdir(XRIAuthority oAuth, int n, int iTargetDepth) { XRISubSegment oSubSegment = oAuth.getSubSegmentAt(n); if (oSubSegment == null) { return this; } CacheNode oNode = mkdir(oSubSegment.toString()); return ((n + 1) < iTargetDepth) ? oNode.mkdir(oAuth, n + 1, iTargetDepth) : oNode; } // mkdir()
} // stuff() /* **************************************************************************** * stuff() **************************************************************************** */ /** * Adds a descriptors associated with a subsegment to the cache. * @param oAuth - The Authority containing a subsegment whose descriptor is * provided * @param oDescriptor - The descriptor of the subsegment * @param nDepth - The index of the subsegment in oAuth */ synchronized void stuff( XRIAuthority oAuth, XRD oDescriptor, int nDepth) { // get the community node CacheNode oCommunityNode = moRootNode.mkdir(oAuth.getRootAuthority()); // if necessary, create a node for this authority path CacheNode oNode = oCommunityNode.mkdir(oAuth, 0, nDepth); // set the correct descriptor for the node oNode.moCacheValue = new CachedValue(oDescriptor, nDepth); trim(); } // stuff()
} // trim() // unstuff node and prune all the children of the node /* **************************************************************************** * prune() **************************************************************************** */ /** * Removes the Authority and all subsegments registered underneath it from * the cache. */ synchronized bool prune(XRIAuthority oAuth) { CacheNode oNode = findNode(oAuth, false, false, null); return (oNode == null) ? false : oNode.removeSelf(true); } // prune()
} // stuff() /* **************************************************************************** * stuff() **************************************************************************** */ /** * Adds the descriptors associated with an authority to the cache * @param oAuth - The Authority whose descriptors to store * @param oDescriptors - The descriptors of the subsegments in oAuth */ public void stuff(XRIAuthority oAuth, XRDS oDescriptors) { for (int i = 0; i < oDescriptors.getNumChildren(); i++) { stuff(oAuth, oDescriptors.getDescriptorAt(i), i); } } // stuff()
} // findNode() /* **************************************************************************** * stuff() **************************************************************************** */ /** * */ synchronized void stuff(XRIAuthority oAuth, XRD oDescriptor) { stuff(oAuth, oDescriptor, oAuth.getNumSubSegments()); } // stuff()
} // find() /* **************************************************************************** * findNode() **************************************************************************** */ /** * */ private CacheNode findNode( XRIAuthority oAuth, bool bPartial, bool bCompleteChain, Vector oCachedDescriptors) { // get the Node for the community root CacheNode oCommunityNode = moRootNode.find(oAuth.getRootAuthority()); if (oCommunityNode == null) { return null; } // if the found node doesn't have a cached value, potentially bail if ( (oCommunityNode.moCacheValue == null) || (oCommunityNode.moCacheValue.getDescriptor() == null)) { if (bCompleteChain) { return null; } } else if (oCachedDescriptors != null) { oCachedDescriptors.add(oCommunityNode.moCacheValue.getDescriptor()); } // find the deepest node that fits the bill CacheResult oDeepestNode = oCommunityNode.find(oAuth, 0, bCompleteChain, oCachedDescriptors); // return the node we found if we got everything, or we are in partial mode if (bPartial || (oDeepestNode.mnNumFound == oAuth.getNumSubSegments())) { return oDeepestNode.moLastCacheNode; } else { return null; } } // findNode()
} // find() /* **************************************************************************** * find() **************************************************************************** */ /** * Finds entries in the cache * @param oAuth the XRI Authority to look up * @param bPartial specifies whether or not to return partial hits * @param bCompleteChain specifies whether or not intermediate values must have a descriptor * @param oCachedDescriptors if not null, adds each descriptor that was * found for the authority to the end of the vector */ CachedValue find( XRIAuthority oAuth, bool bPartial, bool bCompleteChain, Vector oCachedDescriptors) { CacheNode oNode = findNode(oAuth, bPartial, bCompleteChain, oCachedDescriptors); return (oNode != null) ? oNode.moCacheValue : null; } // find()
} // getMaxSize() // use this methods to get a CacheValue based on the GCS Authority /* **************************************************************************** * find() **************************************************************************** */ /** * Finds entries in the cache * @param oAuth the XRI Authority to look up * @param bPartial specifies whether or not to return partial hits * found for the authority to the end of the vector */ CachedValue find(XRIAuthority oAuth, bool bPartial) { return find(oAuth, bPartial, false, null); } // find()