use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class DefaultTakeOfflineManager method start.
@Start
public void start() {
String localSiteName = rpcManager.getTransport().localSiteName();
config.sites().allBackupsStream().filter(bc -> !localSiteName.equals(bc.site())).forEach(bc -> {
String siteName = bc.site();
OfflineStatus offline = new OfflineStatus(bc.takeOffline(), timeService, new Listener(siteName));
offlineStatus.put(siteName, offline);
});
}
use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class MaxIdlePessimisticTxTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Throwable {
ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true);
builder.transaction().lockingMode(LockingMode.PESSIMISTIC);
createCluster(builder, NUM_NODES);
cacheManagers.forEach(cm -> replaceComponent(cm, TimeService.class, timeService, true));
}
use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class IndexWorker method apply.
@Override
public Void apply(EmbeddedCacheManager embeddedCacheManager) {
AdvancedCache<Object, Object> cache = SecurityActions.getUnwrappedCache(embeddedCacheManager.getCache(cacheName)).getAdvancedCache();
DataConversion valueDataConversion = cache.getValueDataConversion();
AdvancedCache<Object, Object> reindexCache = cache.withStorageMediaType();
SearchMapping searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
TimeService timeService = ComponentRegistryUtils.getTimeService(cache);
MassIndexerProgressNotifier notifier = new MassIndexerProgressNotifier(searchMapping, timeService);
IndexUpdater indexUpdater = new IndexUpdater(searchMapping);
KeyPartitioner keyPartitioner = ComponentRegistryUtils.getKeyPartitioner(cache);
if (keys == null || keys.size() == 0) {
preIndex(cache, indexUpdater);
MassIndexerProgressState progressState = new MassIndexerProgressState(notifier);
if (!skipIndex) {
try (Stream<CacheEntry<Object, Object>> stream = reindexCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).cacheEntrySet().stream()) {
stream.forEach(entry -> {
Object key = entry.getKey();
Object value = valueDataConversion.extractIndexable(entry.getValue());
int segment = keyPartitioner.getSegment(key);
if (value != null && indexedTypes.contains(indexUpdater.toConvertedEntityJavaClass(value))) {
progressState.addItem(key, value, indexUpdater.updateIndex(key, value, segment));
}
});
}
}
postIndex(indexUpdater, progressState, notifier);
} else {
DataConversion keyDataConversion = cache.getKeyDataConversion();
Set<Class<?>> classSet = new HashSet<>();
for (Object key : keys) {
Object storedKey = keyDataConversion.toStorage(key);
Object unwrappedKey = keyDataConversion.extractIndexable(storedKey);
Object value = cache.get(key);
if (value != null) {
indexUpdater.updateIndex(unwrappedKey, value, keyPartitioner.getSegment(storedKey));
classSet.add(value.getClass());
}
}
indexUpdater.flush(classSet);
indexUpdater.refresh(classSet);
}
return null;
}
use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.
the class ContainerResourceTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Exception {
Util.recursiveFileRemove(PERSISTENT_LOCATION);
super.createCacheManagers();
cacheManagerClient = client.cacheManager("default");
adminCacheManagerClient = adminClient.cacheManager("default");
timeService = new ControlledTimeService();
cacheManagers.forEach(cm -> TestingUtil.replaceComponent(cm, TimeService.class, timeService, true));
}
use of org.infinispan.commons.time.TimeService in project keycloak by keycloak.
the class InfinispanUtil method setTimeServiceToKeycloakTime.
/**
* Replaces the {@link TimeService} in infinispan with the one that respects Keycloak {@link Time}.
* @param cacheManager
* @return Runnable to revert replacement of the infinispan time service
*/
public static Runnable setTimeServiceToKeycloakTime(EmbeddedCacheManager cacheManager) {
TimeService previousTimeService = replaceComponent(cacheManager, TimeService.class, KEYCLOAK_TIME_SERVICE, true);
AtomicReference<TimeService> ref = new AtomicReference<>(previousTimeService);
return () -> {
if (ref.get() == null) {
logger.warn("Calling revert of the TimeService when testing TimeService was already reverted");
return;
}
logger.info("Revert set KeycloakIspnTimeService to the infinispan cacheManager");
replaceComponent(cacheManager, TimeService.class, ref.getAndSet(null), true);
};
}
Aggregations