Cosmetic changes to IndexBuilder: add generic types, convert to new for-loops, remove compiler warnings.
This commit is contained in:
parent
c5b06b5379
commit
558ed44132
2 changed files with 37 additions and 46 deletions
|
@ -56,7 +56,7 @@ public class IndexController extends FreemarkerHttpServlet {
|
||||||
builder.doIndexRebuild();
|
builder.doIndexRebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IndexingException e) {
|
} catch (Exception e) {
|
||||||
log.error("Error rebuilding search index",e);
|
log.error("Error rebuilding search index",e);
|
||||||
body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage());
|
body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage());
|
||||||
return new ExceptionResponseValues(Template.ERROR_MESSAGE.toString(), body, e);
|
return new ExceptionResponseValues(Template.ERROR_MESSAGE.toString(), body, e);
|
||||||
|
|
|
@ -20,9 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The IndexBuilder is used to rebuild or update a search index.
|
* The IndexBuilder is used to rebuild or update a search index.
|
||||||
|
@ -59,7 +57,7 @@ public class IndexBuilder extends Thread {
|
||||||
|
|
||||||
public IndexBuilder(ServletContext context,
|
public IndexBuilder(ServletContext context,
|
||||||
IndexerIface indexer,
|
IndexerIface indexer,
|
||||||
List /*ObjectSourceIface*/ sources){
|
List<ObjectSourceIface> sources){
|
||||||
super("IndexBuilder");
|
super("IndexBuilder");
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
this.sourceList = sources;
|
this.sourceList = sources;
|
||||||
|
@ -71,7 +69,7 @@ public class IndexBuilder extends Thread {
|
||||||
|
|
||||||
protected IndexBuilder(){
|
protected IndexBuilder(){
|
||||||
//for testing only
|
//for testing only
|
||||||
this( null, null, Collections.emptyList());
|
this( null, null, Collections.<ObjectSourceIface>emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addObjectSource(ObjectSourceIface osi) {
|
public void addObjectSource(ObjectSourceIface osi) {
|
||||||
|
@ -87,7 +85,7 @@ public class IndexBuilder extends Thread {
|
||||||
return sourceList;
|
return sourceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void doIndexRebuild() throws IndexingException {
|
public synchronized void doIndexRebuild() {
|
||||||
//set flag for full index rebuild
|
//set flag for full index rebuild
|
||||||
this.reindexRequested = true;
|
this.reindexRequested = true;
|
||||||
//wake up
|
//wake up
|
||||||
|
@ -180,20 +178,15 @@ public class IndexBuilder extends Thread {
|
||||||
this.updatedInds = addDepResourceClasses(updatedInds);
|
this.updatedInds = addDepResourceClasses(updatedInds);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void indexRebuild() throws IndexingException {
|
protected void indexRebuild() {
|
||||||
log.info("Rebuild of search index is starting.");
|
log.info("Rebuild of search index is starting.");
|
||||||
|
|
||||||
Iterator<ObjectSourceIface> sources = sourceList.iterator();
|
List<Iterator<Individual>> listOfIterators = new LinkedList<Iterator<Individual>>();
|
||||||
List listOfIterators = new LinkedList();
|
for (ObjectSourceIface objectSource: sourceList) {
|
||||||
while (sources.hasNext()) {
|
if (objectSource != null) {
|
||||||
Object obj = sources.next();
|
listOfIterators.add(((objectSource)
|
||||||
if (obj != null && obj instanceof ObjectSourceIface)
|
|
||||||
listOfIterators.add((((ObjectSourceIface) obj)
|
|
||||||
.getAllOfThisTypeIterator()));
|
.getAllOfThisTypeIterator()));
|
||||||
else
|
}
|
||||||
log.warn("\tskipping object of class "
|
|
||||||
+ obj.getClass().getName() + "\n"
|
|
||||||
+ "\tIt doesn not implement ObjectSourceIface.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear out changed uris since we are doing a full index rebuild
|
// clear out changed uris since we are doing a full index rebuild
|
||||||
|
@ -202,28 +195,23 @@ public class IndexBuilder extends Thread {
|
||||||
if (listOfIterators.size() == 0)
|
if (listOfIterators.size() == 0)
|
||||||
log.warn("Warning: no ObjectSources found.");
|
log.warn("Warning: no ObjectSources found.");
|
||||||
|
|
||||||
doBuild(listOfIterators, Collections.EMPTY_LIST );
|
doBuild(listOfIterators, Collections.<Individual>emptyList() );
|
||||||
if( log != null ) //log might be null if system is shutting down.
|
if( log != null ) //log might be null if system is shutting down.
|
||||||
log.info("Rebuild of search index is complete.");
|
log.info("Rebuild of search index is complete.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updatedIndex() throws IndexingException{
|
protected void updatedIndex() {
|
||||||
log.debug("Starting updateIndex()");
|
log.debug("Starting updateIndex()");
|
||||||
long since = indexer.getModified() - 60000;
|
long since = indexer.getModified() - 60000;
|
||||||
|
|
||||||
Iterator<ObjectSourceIface> sources = sourceList.iterator();
|
|
||||||
List<Iterator<Individual>> listOfIterators =
|
List<Iterator<Individual>> listOfIterators =
|
||||||
new LinkedList<Iterator<Individual>>();
|
new LinkedList<Iterator<Individual>>();
|
||||||
|
|
||||||
while (sources.hasNext()) {
|
for (ObjectSourceIface objectSource: sourceList) {
|
||||||
Object obj = sources.next();
|
if (objectSource != null) {
|
||||||
if (obj != null && obj instanceof ObjectSourceIface)
|
listOfIterators.add(((objectSource)
|
||||||
listOfIterators.add((((ObjectSourceIface) obj)
|
|
||||||
.getUpdatedSinceIterator(since)));
|
.getUpdatedSinceIterator(since)));
|
||||||
else
|
}
|
||||||
log.warn("\tskipping object of class "
|
|
||||||
+ obj.getClass().getName() + "\n"
|
|
||||||
+ "\tIt doesn not implement " + "ObjectSourceIface.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
makeAddAndDeleteLists( getAndEmptyChangedUris());
|
makeAddAndDeleteLists( getAndEmptyChangedUris());
|
||||||
|
@ -266,16 +254,12 @@ public class IndexBuilder extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
//get an iterator for all of the sources of indexable objects
|
//get an iterator for all of the sources of indexable objects
|
||||||
Iterator sourceIters = sourceIterators.iterator();
|
for (Iterator<Individual> sourceIterator: sourceIterators) {
|
||||||
Object obj = null;
|
if (sourceIterator == null) {
|
||||||
while (sourceIters.hasNext()) {
|
log.warn("skipping null iterator");
|
||||||
obj = sourceIters.next();
|
} else {
|
||||||
if (obj == null || !(obj instanceof Iterator)) {
|
indexForSource(sourceIterator, newDocs);
|
||||||
log.warn("skipping object of class " + obj.getClass().getName()
|
|
||||||
+ "It doesn not implement Iterator.");
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
indexForSource((Iterator)obj, newDocs);
|
|
||||||
}
|
}
|
||||||
} catch (AbortIndexing abort){
|
} catch (AbortIndexing abort){
|
||||||
if( log != null)
|
if( log != null)
|
||||||
|
@ -376,25 +360,32 @@ public class IndexBuilder extends Thread {
|
||||||
public BuilderObjectSource( List<Individual> individuals){
|
public BuilderObjectSource( List<Individual> individuals){
|
||||||
this.individuals=individuals;
|
this.individuals=individuals;
|
||||||
}
|
}
|
||||||
public Iterator getAllOfThisTypeIterator() {
|
@Override
|
||||||
return new Iterator(){
|
public Iterator<Individual> getAllOfThisTypeIterator() {
|
||||||
final Iterator it = individuals.iterator();
|
return new Iterator<Individual>(){
|
||||||
|
final Iterator<Individual> it = individuals.iterator();
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return it.hasNext();
|
return it.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object next() {
|
@Override
|
||||||
|
public Individual next() {
|
||||||
return it.next();
|
return it.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove() { /* not implemented */}
|
public void remove() { /* not implemented */}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public Iterator getUpdatedSinceIterator(long msSinceEpoc) {
|
@Override
|
||||||
|
public Iterator<Individual> getUpdatedSinceIterator(long msSinceEpoc) {
|
||||||
return getAllOfThisTypeIterator();
|
return getAllOfThisTypeIterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AbortIndexing extends Exception { }
|
private class AbortIndexing extends Exception {
|
||||||
|
// Just a vanilla exception
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue