use of org.infinispan.globalstate.ScopedState in project infinispan by infinispan.
the class GlobalConfigurationManagerImpl method createTemplate.
@Override
public CompletionStage<Void> createTemplate(String name, Configuration configuration, EnumSet<CacheContainerAdmin.AdminFlag> flags) {
Cache<ScopedState, Object> cache = getStateCache();
ScopedState key = new ScopedState(TEMPLATE_SCOPE, name);
return cache.containsKeyAsync(key).thenCompose(exists -> {
if (exists)
throw CONFIG.configAlreadyDefined(name);
return cache.putAsync(key, new CacheState(null, parserRegistry.serialize(name, configuration), flags));
}).thenApply(v -> null);
}
use of org.infinispan.globalstate.ScopedState in project infinispan by infinispan.
the class CounterConfigurationManager method start.
/**
* It checks for existing defined configurations in {@link CounterConfigurationStorage} and in the {@link Cache}.
* <p>
* If any is found, it starts the counter's {@link Cache}.
*/
public void start() {
this.stateCache = cacheManager.<ScopedState, CounterConfiguration>getCache(GlobalConfigurationManager.CONFIG_STATE_CACHE_NAME).getAdvancedCache();
listener = new CounterConfigurationListener();
Map<String, CounterConfiguration> persisted = storage.loadAll();
persisted.forEach((name, cfg) -> stateCache.putIfAbsent(stateKey(name), cfg));
counterCacheStarted.set(false);
stateCache.addListener(listener, new ScopeFilter(COUNTER_SCOPE), null);
if (!persisted.isEmpty() || stateCache.keySet().stream().anyMatch(scopedState -> COUNTER_SCOPE.equals(scopedState.getScope()))) {
// we have counter defined
startCounterCache();
}
}
use of org.infinispan.globalstate.ScopedState in project infinispan by infinispan.
the class CounterManagerImplTestStrategy method clearCaches.
private void clearCaches() {
// we need to cleanup other tests counter from the caches.
EmbeddedCacheManager cacheManager = cacheManagerSupplier.get();
cacheManager.getCache(CounterModuleLifecycle.COUNTER_CACHE_NAME).clear();
cacheManager.<ScopedState, Object>getCache(GlobalConfigurationManager.CONFIG_STATE_CACHE_NAME).keySet().removeIf(o -> CounterConfigurationManager.COUNTER_SCOPE.equals(o.getScope()));
}
use of org.infinispan.globalstate.ScopedState in project infinispan by infinispan.
the class CacheResourceV2Test method assertPersistence.
private void assertPersistence(String name, boolean persisted) {
EmbeddedCacheManager cm = cacheManagers.iterator().next();
Cache<ScopedState, CacheState> configCache = cm.getCache(CONFIG_STATE_CACHE_NAME);
assertEquals(persisted, configCache.entrySet().stream().anyMatch(e -> e.getKey().getName().equals(name) && !e.getValue().getFlags().contains(VOLATILE)));
}
Aggregations