@Override public void rollback() throws IOException { if (index instanceof Index.Transactional) { ((Index.Transactional)index).rollback(); } }
@Override public void commit() throws IOException { if (index instanceof Index.Transactional) { ((Index.Transactional)index).commit(); } }
@Override public boolean isValid() { try { return index.getStatus(true) != Index.Status.INVALID; } catch (IOException ex) { return false; } }
synchronized void store() { if (unsavedQueue.isEmpty()) { return; } long start = System.currentTimeMillis(); StoreQueueEntry entry = unsavedQueue.poll(); while (entry != null) { final CndTextIndexKey key = entry.key; // use unitID+fileID for primary key, otherwise indexed files from different projects overwrite each others IndexDocument doc = IndexManager.createDocument(toPrimaryKey(key)); for (CharSequence id : entry.ids) { doc.addPair(TextIndexStorageManager.FIELD_IDS, id.toString(), true, false); } index.addDocument(doc); entry = unsavedQueue.poll(); } try { index.store(false); } catch (Exception ex) { Exceptions.printStackTrace(ex); } LOG.log(Level.FINE, "Cnd Text Index store took {0}ms", System.currentTimeMillis() - start); }
protected final boolean isLowMemory(final boolean[] tryToFree) { final LowMemoryWatcher lm = LowMemoryWatcher.getInstance(); boolean ilm = lm.isLowMemory(); if (ilm && tryToFree != null && tryToFree[0]) { lm.free(); ilm = lm.isLowMemory(); tryToFree[0] = false; } return ilm; }
@Override public void unitRemoved(int unitId) { if (unitId < 0) { return; } try { String unitPrefix = toPrimaryKeyPrefix(unitId); Collection<? extends IndexDocument> queryRes = index.query(TextIndexStorageManager.FIELD_UNIT_ID, unitPrefix, Queries.QueryKind.EXACT, "_sn"); // NOI18N TreeSet<String> keys = new TreeSet<String>(); for (IndexDocument doc : queryRes) { keys.add(doc.getPrimaryKey()); } for (String pk : keys) { index.removeDocument(pk); } } catch (IOException ex) { ex.printStackTrace(System.err); } catch (InterruptedException ex) { // don't report interrupted exception } }
@Override public R next() { return fnc.convert(from.next()); }
@CheckForNull @Override public Void convert(@NonNull final Index.WithTermFrequencies.TermFreq param) throws Stop { final Term term = param.getTerm(); if (fieldName != term.field()) { throw new Stop(); } final int docCount = param.getFreq(); final String encBinName = term.text(); final String binName = encBinName.substring( 0, encBinName.length() - postfixLen); final int dotIndex = binName.lastIndexOf('.'); //NOI18N final String pkgName = dotIndex == -1 ? "" : binName.substring(0, dotIndex); //NOI18N final Integer typeCount = typeFreq.get(binName); final Integer pkgCount = pkgFreq.get(pkgName); typeFreq.put(binName, typeCount == null ? docCount : docCount + typeCount); pkgFreq.put(pkgName, pkgCount == null ? docCount : docCount + pkgCount); return null; } }
protected final void freeMemory(final boolean freeCaches) { final LowMemoryWatcher lm = LowMemoryWatcher.getInstance(); lm.free(freeCaches); }
@Override public Collection<CndTextIndexKey> query(final CharSequence text) { // force store store(); try { // load light weight document with primary key field _sn only // it's enough to restore CndTextIndexKey, but reduces memory by not loading FIELD_IDS set Collection<? extends IndexDocument> queryRes = index.query(TextIndexStorageManager.FIELD_IDS, text.toString(), Queries.QueryKind.EXACT, "_sn"); // NOI18N HashSet<CndTextIndexKey> res = new HashSet<CndTextIndexKey>(queryRes.size()); for (IndexDocument doc : queryRes) { res.add(fromPrimaryKey(doc.getPrimaryKey())); } LOG.log(Level.FINE, "Cnd Text Index query for {0}:\n\t{1}", new Object[]{text, res}); return res; } catch (Exception ex) { //Exceptions.printStackTrace(ex); } return Collections.<CndTextIndexKey>emptyList(); }
public static FieldSelector declaredTypesFieldSelector ( final boolean includeSource, final boolean includeSimpleName) { return includeSource ? includeSimpleName ? Queries.createFieldSelector(FIELD_PACKAGE_NAME, FIELD_BINARY_NAME, FIELD_SIMPLE_NAME, FIELD_SOURCE) : Queries.createFieldSelector(FIELD_PACKAGE_NAME, FIELD_BINARY_NAME, FIELD_SOURCE) : includeSimpleName ? Queries.createFieldSelector(FIELD_PACKAGE_NAME, FIELD_BINARY_NAME, FIELD_SIMPLE_NAME) : Queries.createFieldSelector(FIELD_PACKAGE_NAME, FIELD_BINARY_NAME); }
@Override public boolean isValid() { try { return index.getStatus() != Index.Status.INVALID; } catch (IOException ex) { //Exceptions.printStackTrace(ex); } return false; }
@Override protected final void close () throws IOException { this.index.close(); }
@Override public void clear() throws IOException { resetPkgCache(); index.clear(); }
@Override public void deleteAndStore(List<Pair<Pair<BinaryName,String>, Object[]>> refs, Set<Pair<String, String>> toDelete) throws IOException { resetPkgCache(); index.store(refs, toDelete, DocumentUtil.documentConvertor(), DocumentUtil.queryClassConvertor(), true); } }
@Override public void deleteAndFlush(List<Pair<Pair<BinaryName, String>, Object[]>> refs, Set<Pair<String, String>> toDelete) throws IOException { resetPkgCache(); if (index instanceof Index.Transactional) { ((Index.Transactional)index).txStore(refs, toDelete, DocumentUtil.documentConvertor(), DocumentUtil.queryClassConvertor()); } else { // fallback to the old behaviour deleteAndStore(refs, toDelete); } }
BinaryAnalyser (final @NonNull ClassIndexImpl.Writer writer, final @NonNull File cacheRoot) { Parameters.notNull("writer", writer); //NOI18N Parameters.notNull("cacheRoot", cacheRoot); //NOI18N this.writer = writer; this.cacheRoot = cacheRoot; this.lmListener = LowMemoryWatcher.getInstance(); this.cfg = Config.getDefault(); }
@NonNull FragmentBuilder append(@NonNull final CharSequence text) { for (int i = 0; i < sbs.length; i++) { sbs[i].append(FILTERS.get(i).convert(text)); } return this; }
static FieldSelector sourceNameFieldSelector () { return Queries.createFieldSelector(FIELD_SOURCE); }
ClassFileProcessor( @NonNull final ClassFile classFile, @NonNull final Config.IdentLevel idLvl) { this.classFile = classFile; this.className = CONVERTOR.convert(classFile.getName ()); this.idLvl = idLvl; }