/** * Returns an List of URNs, from 'youngest' to 'oldest'. * @param max the maximum number of URNs you want returned. if you * want all, give Integer.MAX_VALUE. * @param request in case the query has meta-flags, you can give it to * me. null is fine though. * @return a List ordered by younger URNs. */ public List getFiles(final QueryRequest request, final int max) throws IllegalArgumentException { // if i'm using FM, always grab that lock first and then me. be quick // about it though :) synchronized (RouterService.getFileManager()) { synchronized (this) { if (max < 1) throw new IllegalArgumentException("bad max = " + max); List urnList = new ArrayList(); Iterator iter = TIME_TO_URNSET_MAP.entrySet().iterator(); final MediaType.Aggregator filter = (request == null ? null : MediaType.getAggregator(request)); // may be non-null at loop end List toRemove = null; // we bank on the fact that the TIME_TO_URNSET_MAP iterator returns the // entries in descending order.... while (iter.hasNext() && (urnList.size() < max)) { Map.Entry currEntry = (Map.Entry) iter.next(); Set urns = (Set) currEntry.getValue(); // only put as many as desired, and possibly filter results based // on what the query desires Iterator innerIter = urns.iterator(); while ((urnList.size() < max) && innerIter.hasNext()) { URN currURN = (URN) innerIter.next(); FileDesc fd = RouterService.getFileManager().getFileDescForUrn(currURN); // unfortunately fds can turn into ifds so ignore if ((fd == null) || (fd instanceof IncompleteFileDesc)) { if (toRemove == null) toRemove = new ArrayList(); toRemove.add(currURN); continue; } if (filter == null) urnList.add(currURN); else if (filter.allow(fd.getFileName())) urnList.add(currURN); } } // clear any ifd's or unshared files that may have snuck into structures if (toRemove != null) { Iterator removees = toRemove.iterator(); while (removees.hasNext()) { URN currURN = (URN) removees.next(); removeTime(currURN); } } return urnList; } } }
/** * Constructs a new <tt>Response</tt> instance from the data in the specified <tt>FileDesc</tt>. * * @param fd the <tt>FileDesc</tt> containing the data to construct this <tt>Response</tt> -- must * not be <tt>null</tt> */ public Response(FileDesc fd) { this( fd.getIndex(), fd.getFileSize(), fd.getFileName(), fd.getUrns(), null, new GGEPContainer( getAsEndpoints(RouterService.getAltlocManager().getDirect(fd.getSHA1Urn())), CreationTimeCache.instance().getCreationTimeAsLong(fd.getSHA1Urn())), null); }