use of org.apache.stanbol.entityhub.indexing.core.IndexingComponent in project stanbol by apache.
the class IndexerImpl method initialiseIndexing.
@Override
public void initialiseIndexing() {
synchronized (stateSync) {
//initialisation at the same time ...
if (getState() != State.UNINITIALISED) {
return;
}
setState(State.INITIALISING);
log.info("{}: initialisation started ...", name);
}
//add all IndexingSources that need to be initialised to a set
final Collection<IndexingComponent> toInitialise = new HashSet<IndexingComponent>();
//we need an simple listener that removes the IndexingSerouces from the
//above list
final IndexingSourceInitialiserListener listener = new IndexingSourceInitialiserListener() {
@Override
public void indexingSourceInitialised(IndexingSourceEventObject eventObject) {
//remove the IndexingSource from the toInitialise set
synchronized (toInitialise) {
toInitialise.remove(eventObject.getIndexingSource());
if (toInitialise.isEmpty()) {
//if no more left to initialise
//notify others about it
toInitialise.notifyAll();
}
}
//finally remove this listener
eventObject.getSource().removeIndexingSourceInitialiserListener(this);
}
};
//Indexing Sources in their own Thread
for (IndexingComponent source : indexingComponents) {
if (source.needsInitialisation()) {
//if it need to be initialised
// add it to the list
toInitialise.add(source);
//create an initialiser
IndexingSourceInitialiser initialiser = new IndexingSourceInitialiser(source);
//add the listener
initialiser.addIndexingSourceInitialiserListener(listener);
//create and init the Thread
Thread thread = new Thread(initialiser);
thread.setDaemon(true);
thread.start();
}
//else no initialisation is needed
}
//now wait until all IndexingSources are initialised!
while (!toInitialise.isEmpty()) {
synchronized (toInitialise) {
if (!toInitialise.isEmpty()) {
try {
toInitialise.wait();
} catch (InterruptedException e) {
//year looks like all IndexingSources are initialised!
}
}
}
}
//initialise the stream used to write the ids of indexed entities
try {
indexedEntityIdOutputStream = getEntityIdFileOutputStream();
} catch (IOException e) {
if (entityPostProcessors != null) {
throw new IllegalStateException("Unable to open stream for writing" + "the IDs of indexed Entities as required for post-" + "processing!", e);
} else {
log.warn("Unable to open stream for writing the Ids of indexed " + "Entities -> indexes entity Ids will not be available!", e);
}
}
log.info("initialisation completed for {}", name);
setState(State.INITIALISED);
}
Aggregations