in src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java [461:552]
protected final void start(final BundleContext bundleContext, final Config config) {
// already setup ?
if (this.bundleContext != null) {
log.debug("start: Repository already started and registered");
return;
}
this.bundleContext = bundleContext;
this.defaultWorkspace = config.defaultWorkspace;
this.disableLoginAdministrative = config.disableLoginAdministrative;
this.startupThreadMaxWaitCount = config.startupThreadMaxWaitCount;
this.startupThreadWaitMillis = config.startupThreadWaitMillis;
this.mountTracker = new ServiceTracker<>(this.bundleContext, RepositoryMount.class, null);
this.mountTracker.open();
this.repoInitializerTracker = new ServiceTracker<SlingRepositoryInitializer, SlingRepositoryInitializerInfo>(bundleContext, SlingRepositoryInitializer.class,
new ServiceTrackerCustomizer<SlingRepositoryInitializer, SlingRepositoryInitializerInfo>() {
@Override
public SlingRepositoryInitializerInfo addingService(final ServiceReference<SlingRepositoryInitializer> reference) {
final SlingRepositoryInitializer service = bundleContext.getService(reference);
if ( service != null ) {
final SlingRepositoryInitializerInfo info = new SlingRepositoryInitializerInfo(service, reference);
synchronized ( repoInitLock ) {
if ( masterSlingRepository != null ) {
log.debug("Executing {}", info.initializer);
try {
info.initializer.processRepository(masterSlingRepository);
} catch (final Exception e) {
log.error("Exception in a SlingRepositoryInitializer: " + info.initializer, e);
}
}
}
return info;
}
return null;
}
@Override
public void modifiedService(final ServiceReference<SlingRepositoryInitializer> reference,
final SlingRepositoryInitializerInfo service) {
// nothing to do
}
@Override
public void removedService(final ServiceReference<SlingRepositoryInitializer> reference,
final SlingRepositoryInitializerInfo service) {
bundleContext.ungetService(reference);
}
});
this.repoInitializerTracker.open();
// If allowLoginAdministrativeForBundle is overridden we assume we don't need
// a LoginAdminAllowList service - that's the case if the derived class
// implements its own strategy and the LoginAdminAllowList interface is
// not exported by this bundle anyway, so cannot be implemented differently.
boolean enableAllowlist = !isAllowLoginAdministrativeForBundleOverridden();
final CountDownLatch waitForAllowList = new CountDownLatch(enableAllowlist ? 1 : 0);
if (enableAllowlist) {
allowListTracker = new ServiceTracker<LoginAdminAllowList, LoginAdminAllowList>(bundleContext, LoginAdminAllowList.class, null) {
@Override
public LoginAdminAllowList addingService(final ServiceReference<LoginAdminAllowList> reference) {
try {
return super.addingService(reference);
} finally {
waitForAllowList.countDown();
}
}
};
allowListTracker.open();
}
// start repository asynchronously to allow LoginAdminAllowList to become available
// NOTE: making this conditional allows tests to register a mock allow list before
// activating the RepositoryManager, so they don't need to deal with async startup
startupThread = new Thread("Apache Sling Repository Startup Thread #" + startupCounter.incrementAndGet()) {
@Override
public void run() {
try {
waitForAllowList.await();
initializeAndRegisterRepositoryService();
} catch (InterruptedException e) {
log.warn("Interrupted while waiting for the {} service, cancelling repository initialisation. {}", LoginAdminAllowList.class.getSimpleName(), INTERRUPTED_EXCEPTION_NOTE, e);
Thread.currentThread().interrupt();
}
}
};
startupThread.start();
}