@Override public int removeAllByProfileHandle(final String profileHandle, final long timeout) throws IOException, SpaceExceededException { // first find a list of url hashes that shall be deleted final long terminate = timeout == Long.MAX_VALUE ? Long.MAX_VALUE : (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE; int count = 0; synchronized (this) { for (Index depthStack : this.depthStacks.values()) { final HandleSet urlHashes = new RowHandleSet(Word.commonHashLength, Base64Order.enhancedCoder, 100); final Iterator<Row.Entry> i = depthStack.rows(); Row.Entry rowEntry; Request crawlEntry; while (i.hasNext() && (System.currentTimeMillis() < terminate)) { rowEntry = i.next(); crawlEntry = new Request(rowEntry); if (crawlEntry.profileHandle().equals(profileHandle)) { urlHashes.put(crawlEntry.url().hash()); } if (System.currentTimeMillis() > terminate) break; } for (final byte[] urlhash : urlHashes) { depthStack.remove(urlhash); count++; } } } return count; }
/** * remove urls from the queue * * @param urlHashes, a list of hashes that shall be removed * @return number of entries that had been removed * @throws IOException */ @Override public synchronized int remove(final HandleSet urlHashes) throws IOException { int removedCounter = 0; for (Index depthStack : this.depthStacks.values()) { final int s = depthStack.size(); for (final byte[] urlhash : urlHashes) { final Row.Entry entry = depthStack.remove(urlhash); if (entry != null) removedCounter++; } if (removedCounter == 0) return 0; assert depthStack.size() + removedCounter == s : "urlFileIndex.size() = " + depthStack.size() + ", s = " + s; } return removedCounter; }