use of org.apache.stanbol.entityhub.indexing.core.impl.IndexingDaemon.IndexingDaemonEventObject in project stanbol by apache.
the class IndexerImpl method startAndWait.
/**
* Internally used to start the indexing/post-processing daemons and wait
* until they have finished.
* @param activeIndexingDeamons the deamos to start
*/
private void startAndWait(final SortedSet<IndexingDaemon<?, ?>> activeIndexingDeamons) {
//We need an listener for the IndexingDaemons we are about to start!
final IndexingDaemonListener listener = new IndexingDaemonListener() {
@Override
public void indexingDaemonFinished(IndexingDaemonEventObject indexingDaemonEventObject) {
//looks like one has finished
IndexingDaemon<?, ?> indexingDaemon = indexingDaemonEventObject.getSource();
//handle the finished indexing daemon
handleFinishedIndexingDaemon(activeIndexingDeamons, indexingDaemon);
//finally remove the listener
indexingDaemon.removeIndexingDaemonListener(this);
}
};
//now start the IndexingDaemons in their own Threads
Set<IndexingDaemon<?, ?>> deamonCopy = new HashSet<IndexingDaemon<?, ?>>(activeIndexingDeamons);
for (IndexingDaemon<?, ?> deamon : deamonCopy) {
//add the listener
deamon.addIndexingDaemonListener(listener);
// create the thread
Thread thread = new Thread(deamon);
//ensure that the JVM can terminate
thread.setDaemon(true);
// set the name of the thread
thread.setName(deamon.getName());
//start the Thread
thread.start();
}
//now we need to wait until all Threads have finished ...
while (!activeIndexingDeamons.isEmpty()) {
synchronized (activeIndexingDeamons) {
try {
activeIndexingDeamons.wait();
} catch (InterruptedException e) {
//year ... looks like we are done
}
}
}
//done!
}
Aggregations