/** * Index a document from a Reader, using the specified type of DocIndexer * * <p>Catches and reports any errors that occur. * * @param documentName some (preferably unique) name for this document (for example, the file name * or path) * @param reader where to index from * @throws Exception */ public void index(String documentName, Reader reader) throws Exception { try { indexReader(documentName, reader); } catch (InputFormatException e) { listener.errorOccurred(e.getMessage(), "reader", new File(documentName), null); if (continueAfterInputError) { System.err.println("Parsing " + documentName + " failed:"); e.printStackTrace(); System.err.println("(continuing indexing)"); } else { // Don't continue; re-throw the exception so we eventually abort System.err.println("Input error while processing " + documentName); if (rethrowInputError) throw e; e.printStackTrace(); } } catch (Exception e) { listener.errorOccurred(e.getMessage(), "reader", new File(documentName), null); if (continueAfterInputError) { System.err.println("Parsing " + documentName + " failed:"); e.printStackTrace(); System.err.println("(continuing indexing)"); } else { System.err.println("Exception while processing " + documentName); if (rethrowInputError) throw e; e.printStackTrace(); } } }
/** * Notifies all registered indexers that the indexed information of all artifacts with the given * IDs have been updated. * * @param delta the updated artifact IDs */ public void notifyListeners(Set<ID> delta) { if (allListeners.isEmpty() || delta.isEmpty()) { return; } Object last = super.lastCallee; if (checkForInvokationLoop()) { activeListeners.add((IndexListener) last); return; } boolean goOn; do { goOn = false; Set<IndexListener> toNotify; toNotify = new LinkedHashSet<IndexListener>(); toNotify.addAll(activeListeners); toNotify.addAll(allListeners); for (IndexListener listener : toNotify) { if (super.wasCalledBefore(listener)) { continue; } listener.indexChanged(delta); if (super.thisCausedInvokationLoop()) { goOn = true; break; } } } while (goOn); }
/** * Get our index listener, or create a console reporting listener if none was set yet. * * <p>Also reports the creation of the Indexer and start of indexing, if it hadn't been reported * already. * * @return the listener */ public IndexListener getListener() { if (listener == null) { listener = new IndexListenerReportConsole(); } if (!createAndIndexStartReported) { createAndIndexStartReported = true; listener.indexerCreated(this); listener.indexStart(); } return listener; }
private void markAsBroken() { if (!isBroken) { myListener.indexIsBroken(this); } isBroken = true; }