use of org.infinispan.commons.time.TimeService 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.commons.time.TimeService in project infinispan by infinispan.
the class AbstractClusterMBeanTest method createManager.
private void createManager(String jmxDomain) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.clustering().cacheMode(CacheMode.REPL_SYNC).statistics().enable();
GlobalConfigurationBuilder gcb = GlobalConfigurationBuilder.defaultClusteredBuilder();
gcb.cacheContainer().statistics(true).metrics().accurateSize(true).metrics().accurateSize(true).jmx().enabled(true).domain(jmxDomain).mBeanServerLookup(mBeanServerLookup).serialization().addContextInitializer(TestDataSCI.INSTANCE);
gcb.addModule(TestGlobalConfigurationBuilder.class).testGlobalComponent(TimeService.class.getName(), timeService);
addClusterEnabledCacheManager(gcb, cb);
}
use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class PersistenceMockUtil method mockCache.
private static Cache mockCache(String nodeName, Configuration configuration, TimeService timeService, ClassAllowList allowList, ScheduledExecutorService timeoutScheduledExecutor) {
String cacheName = "mock-cache";
AdvancedCache cache = mock(AdvancedCache.class, RETURNS_DEEP_STUBS);
GlobalConfiguration gc = new GlobalConfigurationBuilder().transport().nodeName(nodeName).build();
Set<String> cachesSet = new HashSet<>();
EmbeddedCacheManager cm = mock(EmbeddedCacheManager.class);
when(cm.getCacheManagerConfiguration()).thenReturn(gc);
when(cm.getClassAllowList()).thenReturn(new ClassAllowList());
GlobalComponentRegistry gcr = new GlobalComponentRegistry(gc, cm, cachesSet, TestModuleRepository.defaultModuleRepository(), mock(ConfigurationManager.class));
BasicComponentRegistry gbcr = gcr.getComponent(BasicComponentRegistry.class);
gbcr.replaceComponent(TimeService.class.getName(), timeService, true);
gbcr.replaceComponent(KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR, timeoutScheduledExecutor, false);
ComponentRegistry registry = new ComponentRegistry(cacheName, configuration, cache, gcr, configuration.getClass().getClassLoader());
when(cache.getCacheManager().getGlobalComponentRegistry()).thenReturn(gcr);
when(cache.getClassLoader()).thenReturn(PersistenceMockUtil.class.getClassLoader());
when(cache.getCacheManager().getCacheManagerConfiguration()).thenReturn(gc);
when(cache.getCacheManager().getClassAllowList()).thenReturn(allowList);
when(cache.getName()).thenReturn(cacheName);
when(cache.getAdvancedCache()).thenReturn(cache);
when(cache.getComponentRegistry()).thenReturn(registry);
when(cache.getStatus()).thenReturn(ComponentStatus.RUNNING);
when(cache.getCacheConfiguration()).thenReturn(configuration);
return cache;
}
use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class TestInfinispanRegionFactory method createCacheManager.
@Override
protected EmbeddedCacheManager createCacheManager(Properties properties, ServiceRegistry serviceRegistry) {
// If the cache manager has been provided by calling setCacheManager, don't create a new one
EmbeddedCacheManager cacheManager = getCacheManager();
if (cacheManager != null) {
return cacheManager;
} else if (providedManager != null) {
cacheManager = providedManager;
} else {
ConfigurationBuilderHolder holder = DefaultCacheManagerProvider.loadConfiguration(serviceRegistry, properties);
configurationHook.amendConfiguration(holder);
cacheManager = new DefaultCacheManager(holder, true);
}
if (afterManagerCreated != null) {
afterManagerCreated.accept(cacheManager);
}
if (timeService != null) {
BasicComponentRegistry basicComponentRegistry = cacheManager.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class);
basicComponentRegistry.replaceComponent(TimeService.class.getName(), timeService, false);
basicComponentRegistry.rewire();
}
return cacheManager;
}
use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class EmbeddedTimeServiceTest method testExpired.
public void testExpired() {
TimeService timeService = new EmbeddedTimeService() {
@Override
public long time() {
return 10;
}
};
assertTrue(timeService.isTimeExpired(-1));
assertTrue(timeService.isTimeExpired(0));
assertTrue(timeService.isTimeExpired(9));
assertTrue(timeService.isTimeExpired(10));
assertFalse(timeService.isTimeExpired(11));
}
Aggregations