use of org.infinispan.util.concurrent.NonBlockingManager in project keycloak by keycloak.
the class PersistenceManagerImpl method start.
@Override
@Start
public void start() {
enabled = configuration.persistence().usingStores();
if (!enabled)
return;
preloaded = false;
segmentCount = configuration.clustering().hash().numSegments();
isInvalidationCache = configuration.clustering().cacheMode().isInvalidation();
long stamp = lock.writeLock();
try {
Completable storeStartup = Flowable.fromIterable(configuration.persistence().stores()).concatMapSingle(storeConfiguration -> {
NonBlockingStore<?, ?> actualStore = storeFromConfiguration(storeConfiguration);
NonBlockingStore<?, ?> nonBlockingStore;
if (storeConfiguration.async().enabled()) {
nonBlockingStore = new AsyncNonBlockingStore<>(actualStore);
} else {
nonBlockingStore = actualStore;
}
InitializationContextImpl ctx = new InitializationContextImpl(storeConfiguration, cache.wired(), keyPartitioner, persistenceMarshaller, timeService, byteBufferFactory, marshallableEntryFactory, nonBlockingExecutor, globalConfiguration, blockingManager, nonBlockingManager);
CompletionStage<Void> stage = nonBlockingStore.start(ctx).whenComplete((ignore, t) -> {
// On exception, just put a status with only the store - this way we can still invoke stop on it later
if (t != null) {
stores.add(new StoreStatus(nonBlockingStore, null, null));
}
});
return Completable.fromCompletionStage(stage).toSingle(() -> new StoreStatus(nonBlockingStore, storeConfiguration, updateCharacteristics(nonBlockingStore, nonBlockingStore.characteristics(), storeConfiguration)));
}).doOnNext(stores::add).delay(status -> {
if (status.config.purgeOnStartup()) {
return Flowable.fromCompletable(Completable.fromCompletionStage(status.store.clear()));
}
return Flowable.empty();
}).ignoreElements();
long interval = configuration.persistence().availabilityInterval();
if (interval > 0) {
storeStartup = storeStartup.doOnComplete(() -> availabilityTask = nonBlockingManager.scheduleWithFixedDelay(this::pollStoreAvailability, interval, interval, MILLISECONDS));
}
// Blocks here waiting for stores and availability task to start if needed
storeStartup.blockingAwait();
allSegmentedOrShared = allStoresSegmentedOrShared();
} catch (Throwable t) {
log.debug("PersistenceManagerImpl encountered an exception during startup of stores", t);
throw t;
} finally {
lock.unlockWrite(stamp);
}
}
Aggregations