/* **************************************************************************** * 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. */ internal CacheResult find( XRIAuthority oAuth, int nNextSubsegment, bool bCompleteChain, ArrayList 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); }
/* **************************************************************************** * 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 */ internal 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; }
/* **************************************************************************** * stuff() **************************************************************************** */ /** * */ void stuff(XRIAuthority oAuth, XRD oDescriptor) { lock (_lock) { stuff(oAuth, oDescriptor, oAuth.NumSubSegments); } }
/* **************************************************************************** * 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 */ void stuff( XRIAuthority oAuth, XRD oDescriptor, int nDepth) { lock (_lock) { // get the community node CacheNode oCommunityNode = moRootNode.mkdir(oAuth.RootAuthority); // 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(); } }
/* **************************************************************************** * findNode() **************************************************************************** */ /** * */ private CacheNode findNode( XRIAuthority oAuth, bool bPartial, bool bCompleteChain, ArrayList oCachedDescriptors) { // get the Node for the community root CacheNode oCommunityNode = moRootNode.find(oAuth.RootAuthority); 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.NumSubSegments)) { return oDeepestNode.moLastCacheNode; } else { return null; } }
// unstuff node and prune all the children of the node /* **************************************************************************** * prune() **************************************************************************** */ /** * Removes the Authority and all subsegments registered underneath it from * the cache. */ bool prune(XRIAuthority oAuth) { lock (_lock) { CacheNode oNode = findNode(oAuth, false, false, null); return (oNode == null) ? false : oNode.removeSelf(true); } }
/* **************************************************************************** * 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, ArrayList oCachedDescriptors) { CacheNode oNode = findNode(oAuth, bPartial, bCompleteChain, oCachedDescriptors); return (oNode != null) ? oNode.moCacheValue : null; }
// 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); }
/* **************************************************************************** * 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); } }
/** * Resets the internal XRD cache for this XRIAuthority * @param oAuth The XRIAuthority element to prune */ public void reset(XRIAuthority oAuth) { moBasicCache.prune(oAuth); moTrustedCache.prune(oAuth); }
/** * Sets the XRD for the final subsegment of the XRIAuthority. * The authority may contain multiple subgments. Each internal subsegment * will not be set. * @param oAuth The XRIAuthority element to set * @param oDesc The descriptor for the final subsegment in the oAuth * @deprecated */ public void set(XRIAuthority oAuth, XRD oDesc) { moBasicCache.stuff(oAuth, oDesc); moTrustedCache.stuff(oAuth, oDesc); }