use of org.infinispan.factories.annotations.Start 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);
}
}
use of org.infinispan.factories.annotations.Start in project keycloak by keycloak.
the class PersistenceManagerImpl method preload.
@Override
public CompletionStage<Void> preload() {
long stamp = acquireReadLock();
NonBlockingStore<Object, Object> nonBlockingStore = getStoreLocked(status -> status.config.preload());
if (nonBlockingStore == null) {
releaseReadLock(stamp);
return CompletableFutures.completedNull();
}
Publisher<MarshallableEntry<Object, Object>> publisher = nonBlockingStore.publishEntries(IntSets.immutableRangeSet(segmentCount), null, true);
long start = timeService.time();
final long maxEntries = getMaxEntries();
final long flags = getFlagsForStateInsertion();
AdvancedCache<?, ?> tmpCache = this.cache.wired().withStorageMediaType();
DataConversion keyDataConversion = tmpCache.getKeyDataConversion();
DataConversion valueDataConversion = tmpCache.getValueDataConversion();
return Flowable.fromPublisher(publisher).doFinally(() -> releaseReadLock(stamp)).take(maxEntries).concatMapSingle(me -> preloadEntry(flags, me, keyDataConversion, valueDataConversion)).count().toCompletionStage().thenAccept(insertAmount -> {
this.preloaded = insertAmount < maxEntries;
log.debugf("Preloaded %d keys in %s", insertAmount, Util.prettyPrintTime(timeService.timeDuration(start, MILLISECONDS)));
});
}
use of org.infinispan.factories.annotations.Start in project infinispan by infinispan.
the class KafkaEventSenderImpl method start.
@Start
void start() {
Properties kafkaProperties = new Properties();
CloudEventsGlobalConfiguration cloudEventsGlobalConfiguration = globalConfiguration.module(CloudEventsGlobalConfiguration.class);
kafkaProperties.setProperty("bootstrap.servers", cloudEventsGlobalConfiguration.bootstrapServers());
kafkaProperties.setProperty("acks", String.valueOf(cloudEventsGlobalConfiguration.acks()));
kafkaProperties.setProperty("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
kafkaProperties.setProperty("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
producer = new KafkaProducer<>(kafkaProperties);
connect(cloudEventsGlobalConfiguration);
}
use of org.infinispan.factories.annotations.Start in project infinispan by infinispan.
the class JGroupsTransport method start.
@Start
@Override
public void start() {
if (running)
throw new IllegalStateException("Two or more cache managers are using the same JGroupsTransport instance");
probeHandler.updateThreadPool(nonBlockingExecutor);
props = TypedProperties.toTypedProperties(configuration.transport().properties());
requests = new RequestRepository();
String stack = configuration.transport().stack();
if (stack != null) {
CLUSTER.startingJGroupsChannel(configuration.transport().clusterName(), configuration.transport().stack());
} else {
CLUSTER.startingJGroupsChannel(configuration.transport().clusterName());
}
initChannel();
channel.setUpHandler(channelCallbacks);
setXSiteViewListener(channelCallbacks);
startJGroupsChannelIfNeeded();
waitForInitialNodes();
channel.getProtocolStack().getTransport().registerProbeHandler(probeHandler);
RELAY2 relay2 = findRelay2();
if (relay2 != null) {
localSite = XSiteNamedCache.cachedString(relay2.site());
}
running = true;
}
use of org.infinispan.factories.annotations.Start in project infinispan by infinispan.
the class StateReceiverImpl method start.
@Start
public void start() {
cacheNotifier.addListener(this);
stateReceiverExecutor = new LimitedExecutor("StateReceiver-" + cacheName, nonBlockingExecutor, 1);
}
Aggregations