in src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java [270:341]
public void run() {
logger.debug("Main background thread starts");
try {
this.init();
while (this.active) {
this.listener.start();
this.handleResourceUpdaters();
this.processUpdateInfos();
// merge potential new resources
this.mergeNewlyRegisteredResources();
synchronized ( this.resourcesLock ) {
if ( !this.satisfied ) {
logger.debug("Required services are not available yet.");
try {
logger.debug("wait() on resourcesLock");
this.resourcesLock.wait();
} catch (final InterruptedException ignore) {}
continue;
}
this.retryDuringTaskExecution = false;
}
// invoke transformers
this.transformResources();
// Compute tasks
final SortedSet<InstallTask> tasks = this.computeTasks();
// execute tasks and see if we have to stop processing
final ACTION action = this.executeTasks(tasks);
if ( action == ACTION.SLEEP ) {
synchronized ( this.resourcesLock ) {
// before we go to sleep, check if new resources arrived in the meantime
if ( !this.hasNewResources() && this.active && !this.retryDuringTaskExecution) {
// No tasks to execute - wait until new resources are
// registered
logger.debug("No more tasks to process, suspending listener and going idle");
this.listener.suspend();
try {
logger.debug("wait() on resourcesLock");
this.resourcesLock.wait();
} catch (final InterruptedException ignore) {}
if ( active ) {
logger.debug("Done wait()ing on resourcesLock, restarting listener");
this.listener.start();
} else {
logger.debug("Done wait()ing on resourcesLock, but active={}, listener won't be restarted now", active);
}
}
}
} else if ( action == ACTION.SHUTDOWN ) {
// stop processing
logger.debug("Action is SHUTDOWN, going inactive");
active = false;
}
}
this.listener.suspend();
} catch ( final Exception fatal) {
logger.error("An unexpected error occured in the installer task. Installer is stopped now!", fatal);
} finally {
this.backgroundThread = null;
}
logger.debug("Main background thread ends");
}