Search in sources :

Example 1 with ScopedState

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);
}
Also used : InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) LogFactory(org.infinispan.util.logging.LogFactory) CompletableFuture(java.util.concurrent.CompletableFuture) GlobalConfigurationManager(org.infinispan.globalstate.GlobalConfigurationManager) CompletionStages(org.infinispan.util.concurrent.CompletionStages) CONFIG(org.infinispan.util.logging.Log.CONFIG) Cache(org.infinispan.Cache) CacheContainerAdmin(org.infinispan.commons.api.CacheContainerAdmin) Start(org.infinispan.factories.annotations.Start) HashSet(java.util.HashSet) Scopes(org.infinispan.factories.scopes.Scopes) ScopedState(org.infinispan.globalstate.ScopedState) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) Map(java.util.Map) Log(org.infinispan.util.logging.Log) Scope(org.infinispan.factories.scopes.Scope) ConfigurationChangedEvent(org.infinispan.notifications.cachemanagerlistener.event.ConfigurationChangedEvent) EnumSet(java.util.EnumSet) ConfigurationManager(org.infinispan.configuration.ConfigurationManager) MethodHandles(java.lang.invoke.MethodHandles) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) Set(java.util.Set) Inject(org.infinispan.factories.annotations.Inject) CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier) CompletionStage(java.util.concurrent.CompletionStage) LocalConfigurationStorage(org.infinispan.globalstate.LocalConfigurationStorage) Configuration(org.infinispan.configuration.cache.Configuration) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager) Optional(java.util.Optional) BlockingManager(org.infinispan.util.concurrent.BlockingManager) ScopedState(org.infinispan.globalstate.ScopedState)

Example 2 with ScopedState

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) GlobalConfigurationManager(org.infinispan.globalstate.GlobalConfigurationManager) Cache(org.infinispan.Cache) ScopeFilter(org.infinispan.globalstate.ScopeFilter) AdvancedCache(org.infinispan.AdvancedCache) ScopedState(org.infinispan.globalstate.ScopedState) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Map(java.util.Map) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) Listener(org.infinispan.notifications.Listener) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) ConvertUtil.parsedConfigToConfig(org.infinispan.counter.configuration.ConvertUtil.parsedConfigToConfig) Collection(java.util.Collection) Utils.validateStrongCounterBounds(org.infinispan.counter.impl.Utils.validateStrongCounterBounds) CounterModuleLifecycle(org.infinispan.counter.impl.CounterModuleLifecycle) Collectors(java.util.stream.Collectors) CacheCollectors(org.infinispan.stream.CacheCollectors) Objects(java.util.Objects) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration) ComponentStatus(org.infinispan.lifecycle.ComponentStatus) CacheEntryCreated(org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated) Event(org.infinispan.notifications.cachelistener.event.Event) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration) CONTAINER(org.infinispan.counter.logging.Log.CONTAINER) BlockingManager(org.infinispan.util.concurrent.BlockingManager) Collections(java.util.Collections) ScopeFilter(org.infinispan.globalstate.ScopeFilter) ScopedState(org.infinispan.globalstate.ScopedState) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 3 with ScopedState

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()));
}
Also used : EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) ScopedState(org.infinispan.globalstate.ScopedState)

Example 4 with ScopedState

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)));
}
Also used : ResponseAssertion.assertThat(org.infinispan.rest.assertion.ResponseAssertion.assertThat) CompletionStages.join(org.infinispan.util.concurrent.CompletionStages.join) ResponseAssertion(org.infinispan.rest.assertion.ResponseAssertion) APPLICATION_XML(org.infinispan.commons.dataconversion.MediaType.APPLICATION_XML) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HTTP_20(org.infinispan.client.rest.configuration.Protocol.HTTP_20) RestClient(org.infinispan.client.rest.RestClient) GlobalConfigurationManager(org.infinispan.globalstate.GlobalConfigurationManager) PartitionHandling(org.infinispan.partitionhandling.PartitionHandling) Test(org.testng.annotations.Test) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) CONFIG_STATE_CACHE_NAME(org.infinispan.globalstate.GlobalConfigurationManager.CONFIG_STATE_CACHE_NAME) APPLICATION_XML_TYPE(org.infinispan.commons.dataconversion.MediaType.APPLICATION_XML_TYPE) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) TEXT_PLAIN_TYPE(org.infinispan.commons.dataconversion.MediaType.TEXT_PLAIN_TYPE) APPLICATION_OCTET_STREAM(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OCTET_STREAM) Collection(java.util.Collection) HTTP_11(org.infinispan.client.rest.configuration.Protocol.HTTP_11) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) PROTOBUF_METADATA_CACHE_NAME(org.infinispan.query.remote.client.ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME) CompletionStage(java.util.concurrent.CompletionStage) RestRawClient(org.infinispan.client.rest.RestRawClient) ResponseHeader(org.infinispan.rest.ResponseHeader) ConfigurationStorage(org.infinispan.globalstate.ConfigurationStorage) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager) SKIP_CACHE_LOAD(org.infinispan.context.Flag.SKIP_CACHE_LOAD) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SKIP_INDEXING(org.infinispan.context.Flag.SKIP_INDEXING) IntStream(java.util.stream.IntStream) Assert.assertNull(org.testng.Assert.assertNull) APPLICATION_YAML_TYPE(org.infinispan.commons.dataconversion.MediaType.APPLICATION_YAML_TYPE) KEY_CONTENT_TYPE_HEADER(org.infinispan.rest.RequestHeader.KEY_CONTENT_TYPE_HEADER) HashMap(java.util.HashMap) Yaml(org.yaml.snakeyaml.Yaml) MediaType(org.infinispan.commons.dataconversion.MediaType) ScopedState(org.infinispan.globalstate.ScopedState) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) VOLATILE(org.infinispan.commons.api.CacheContainerAdmin.AdminFlag.VOLATILE) CacheState(org.infinispan.globalstate.impl.CacheState) NodeList(org.w3c.dom.NodeList) RestResponse(org.infinispan.client.rest.RestResponse) APPLICATION_JSON(org.infinispan.commons.dataconversion.MediaType.APPLICATION_JSON) Assert.fail(org.testng.Assert.fail) Util(org.infinispan.commons.util.Util) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ACCEPT_HEADER(org.infinispan.rest.RequestHeader.ACCEPT_HEADER) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) Json(org.infinispan.commons.dataconversion.internal.Json) TEXT_PLAIN(org.infinispan.commons.dataconversion.MediaType.TEXT_PLAIN) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TimeUnit(java.util.concurrent.TimeUnit) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) APPLICATION_JSON_TYPE(org.infinispan.commons.dataconversion.MediaType.APPLICATION_JSON_TYPE) CommonsTestingUtil.tmpDirectory(org.infinispan.commons.test.CommonsTestingUtil.tmpDirectory) CacheMode(org.infinispan.configuration.cache.CacheMode) ProtobufMetadataManagerConstants(org.infinispan.query.remote.client.ProtobufMetadataManagerConstants) Element(org.w3c.dom.Element) Paths(java.nio.file.Paths) Closeable(java.io.Closeable) RestEntity(org.infinispan.client.rest.RestEntity) Configuration(org.infinispan.configuration.cache.Configuration) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) LOCAL_HEAP(org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) Collections(java.util.Collections) CacheState(org.infinispan.globalstate.impl.CacheState) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) ScopedState(org.infinispan.globalstate.ScopedState)

Aggregations

ScopedState (org.infinispan.globalstate.ScopedState)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 Map (java.util.Map)3 Cache (org.infinispan.Cache)3 GlobalConfigurationManager (org.infinispan.globalstate.GlobalConfigurationManager)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2 Collectors (java.util.stream.Collectors)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)2 LocalTopologyManager (org.infinispan.topology.LocalTopologyManager)2 BlockingManager (org.infinispan.util.concurrent.BlockingManager)2 CompletableFutures (org.infinispan.util.concurrent.CompletableFutures)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1