Search in sources :

Example 16 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class DynamicConfigYamlGenerator method cacheYamlGenerator.

public static void cacheYamlGenerator(Map<String, Object> parent, Config config) {
    if (config.getCacheConfigs().isEmpty()) {
        return;
    }
    Map<String, Object> child = new LinkedHashMap<>();
    for (CacheSimpleConfig subConfigAsObject : config.getCacheConfigs().values()) {
        Map<String, Object> subConfigAsMap = new LinkedHashMap<>();
        addNonNullToMap(subConfigAsMap, "key-type", wrapObjectWithMap("class-name", subConfigAsObject.getKeyType()));
        addNonNullToMap(subConfigAsMap, "value-type", wrapObjectWithMap("class-name", subConfigAsObject.getValueType()));
        addNonNullToMap(subConfigAsMap, "statistics-enabled", subConfigAsObject.isStatisticsEnabled());
        addNonNullToMap(subConfigAsMap, "management-enabled", subConfigAsObject.isManagementEnabled());
        addNonNullToMap(subConfigAsMap, "read-through", subConfigAsObject.isReadThrough());
        addNonNullToMap(subConfigAsMap, "write-through", subConfigAsObject.isWriteThrough());
        addNonNullToMap(subConfigAsMap, "cache-loader-factory", wrapObjectWithMap("class-name", subConfigAsObject.getCacheLoaderFactory()));
        addNonNullToMap(subConfigAsMap, "cache-writer-factory", wrapObjectWithMap("class-name", subConfigAsObject.getCacheWriterFactory()));
        addNonNullToMap(subConfigAsMap, "cache-loader", wrapObjectWithMap("class-name", subConfigAsObject.getCacheLoader()));
        addNonNullToMap(subConfigAsMap, "cache-writer", wrapObjectWithMap("class-name", subConfigAsObject.getCacheWriter()));
        addNonNullToMap(subConfigAsMap, "expiry-policy-factory", getExpiryPolicyFactoryConfigAsMap(subConfigAsObject.getExpiryPolicyFactoryConfig()));
        addNonNullToMap(subConfigAsMap, "cache-entry-listeners", getCacheSimpleEntryListenerConfigsAsList(subConfigAsObject.getCacheEntryListeners()));
        addNonNullToMap(subConfigAsMap, "in-memory-format", subConfigAsObject.getInMemoryFormat().name());
        addNonNullToMap(subConfigAsMap, "backup-count", subConfigAsObject.getBackupCount());
        addNonNullToMap(subConfigAsMap, "async-backup-count", subConfigAsObject.getAsyncBackupCount());
        addNonNullToMap(subConfigAsMap, "eviction", getEvictionConfigAsMap(subConfigAsObject.getEvictionConfig()));
        addNonNullToMap(subConfigAsMap, "wan-replication-ref", getWanReplicationRefAsMap(subConfigAsObject.getWanReplicationRef(), false));
        addNonNullToMap(subConfigAsMap, "split-brain-protection-ref", subConfigAsObject.getSplitBrainProtectionName());
        addNonNullToMap(subConfigAsMap, "partition-lost-listeners", getListenerConfigsAsList(subConfigAsObject.getPartitionLostListenerConfigs()));
        addNonNullToMap(subConfigAsMap, "merge-policy", getMergePolicyConfigAsMap(subConfigAsObject.getMergePolicyConfig()));
        addNonNullToMap(subConfigAsMap, "event-journal", getEventJournalConfigAsMap(subConfigAsObject.getEventJournalConfig()));
        addNonNullToMap(subConfigAsMap, "data-persistence", getDataPersistenceConfigAsMap(subConfigAsObject.getDataPersistenceConfig()));
        addNonNullToMap(subConfigAsMap, "merkle-tree", getMerkleTreeConfigAsMap(subConfigAsObject.getMerkleTreeConfig()));
        addNonNullToMap(subConfigAsMap, "disable-per-entry-invalidation-events", subConfigAsObject.isDisablePerEntryInvalidationEvents());
        child.put(subConfigAsObject.getName(), subConfigAsMap);
    }
    parent.put("cache", child);
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class DynamicConfigXmlGenerator method cacheXmlGenerator.

public static void cacheXmlGenerator(ConfigXmlGenerator.XmlGenerator gen, Config config) {
    for (CacheSimpleConfig c : config.getCacheConfigs().values()) {
        gen.open("cache", "name", c.getName());
        if (c.getKeyType() != null) {
            gen.node("key-type", null, "class-name", c.getKeyType());
        }
        if (c.getValueType() != null) {
            gen.node("value-type", null, "class-name", c.getValueType());
        }
        gen.node("statistics-enabled", c.isStatisticsEnabled()).node("management-enabled", c.isManagementEnabled()).node("read-through", c.isReadThrough()).node("write-through", c.isWriteThrough());
        checkAndFillCacheLoaderFactoryConfigXml(gen, c.getCacheLoaderFactory());
        checkAndFillCacheLoaderConfigXml(gen, c.getCacheLoader());
        checkAndFillCacheWriterFactoryConfigXml(gen, c.getCacheWriterFactory());
        checkAndFillCacheWriterConfigXml(gen, c.getCacheWriter());
        cacheExpiryPolicyFactoryConfigXmlGenerator(gen, c.getExpiryPolicyFactoryConfig());
        gen.open("cache-entry-listeners");
        for (CacheSimpleEntryListenerConfig el : c.getCacheEntryListeners()) {
            gen.open("cache-entry-listener", "old-value-required", el.isOldValueRequired(), "synchronous", el.isSynchronous()).node("cache-entry-listener-factory", null, "class-name", el.getCacheEntryListenerFactory()).node("cache-entry-event-filter-factory", null, "class-name", el.getCacheEntryEventFilterFactory()).close();
        }
        gen.close().node("in-memory-format", c.getInMemoryFormat()).node("backup-count", c.getBackupCount()).node("async-backup-count", c.getAsyncBackupCount());
        evictionConfigXmlGenerator(gen, c.getEvictionConfig());
        wanReplicationConfigXmlGenerator(gen, c.getWanReplicationRef());
        gen.node("split-brain-protection-ref", c.getSplitBrainProtectionName());
        cachePartitionLostListenerConfigXmlGenerator(gen, c.getPartitionLostListenerConfigs());
        gen.node("merge-policy", c.getMergePolicyConfig().getPolicy(), "batch-size", c.getMergePolicyConfig().getBatchSize());
        appendEventJournalConfig(gen, c.getEventJournalConfig());
        appendDataPersistenceConfig(gen, c.getDataPersistenceConfig());
        if (c.getMerkleTreeConfig().getEnabled() != null) {
            appendMerkleTreeConfig(gen, c.getMerkleTreeConfig());
        }
        gen.node("disable-per-entry-invalidation-events", c.isDisablePerEntryInvalidationEvents()).close();
    }
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) CacheSimpleEntryListenerConfig(com.hazelcast.config.CacheSimpleEntryListenerConfig)

Example 18 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class ClusterWideConfigurationService method registerConfigLocally.

/**
 * Register a dynamic configuration in a local member. When a dynamic configuration with the same name already
 * exists then this call has no effect.
 *
 * @param newConfig       Configuration to register.
 * @param configCheckMode behaviour when a config is detected
 * @throws UnsupportedOperationException when given configuration type is not supported
 * @throws InvalidConfigurationException when conflict is detected and configCheckMode is on THROW_EXCEPTION
 */
@SuppressWarnings("checkstyle:methodlength")
public void registerConfigLocally(IdentifiedDataSerializable newConfig, ConfigCheckMode configCheckMode) {
    IdentifiedDataSerializable currentConfig;
    if (newConfig instanceof MultiMapConfig) {
        MultiMapConfig multiMapConfig = (MultiMapConfig) newConfig;
        currentConfig = multiMapConfigs.putIfAbsent(multiMapConfig.getName(), multiMapConfig);
    } else if (newConfig instanceof MapConfig) {
        MapConfig newMapConfig = (MapConfig) newConfig;
        currentConfig = mapConfigs.putIfAbsent(newMapConfig.getName(), newMapConfig);
        if (currentConfig == null) {
            listener.onConfigRegistered(newMapConfig);
        }
    } else if (newConfig instanceof CardinalityEstimatorConfig) {
        CardinalityEstimatorConfig cardinalityEstimatorConfig = (CardinalityEstimatorConfig) newConfig;
        currentConfig = cardinalityEstimatorConfigs.putIfAbsent(cardinalityEstimatorConfig.getName(), cardinalityEstimatorConfig);
    } else if (newConfig instanceof RingbufferConfig) {
        RingbufferConfig ringbufferConfig = (RingbufferConfig) newConfig;
        currentConfig = ringbufferConfigs.putIfAbsent(ringbufferConfig.getName(), ringbufferConfig);
    } else if (newConfig instanceof ListConfig) {
        ListConfig listConfig = (ListConfig) newConfig;
        currentConfig = listConfigs.putIfAbsent(listConfig.getName(), listConfig);
    } else if (newConfig instanceof SetConfig) {
        SetConfig setConfig = (SetConfig) newConfig;
        currentConfig = setConfigs.putIfAbsent(setConfig.getName(), setConfig);
    } else if (newConfig instanceof ReplicatedMapConfig) {
        ReplicatedMapConfig replicatedMapConfig = (ReplicatedMapConfig) newConfig;
        currentConfig = replicatedMapConfigs.putIfAbsent(replicatedMapConfig.getName(), replicatedMapConfig);
    } else if (newConfig instanceof TopicConfig) {
        TopicConfig topicConfig = (TopicConfig) newConfig;
        currentConfig = topicConfigs.putIfAbsent(topicConfig.getName(), topicConfig);
    } else if (newConfig instanceof ExecutorConfig) {
        ExecutorConfig executorConfig = (ExecutorConfig) newConfig;
        currentConfig = executorConfigs.putIfAbsent(executorConfig.getName(), executorConfig);
    } else if (newConfig instanceof DurableExecutorConfig) {
        DurableExecutorConfig durableExecutorConfig = (DurableExecutorConfig) newConfig;
        currentConfig = durableExecutorConfigs.putIfAbsent(durableExecutorConfig.getName(), durableExecutorConfig);
    } else if (newConfig instanceof ScheduledExecutorConfig) {
        ScheduledExecutorConfig scheduledExecutorConfig = (ScheduledExecutorConfig) newConfig;
        currentConfig = scheduledExecutorConfigs.putIfAbsent(scheduledExecutorConfig.getName(), scheduledExecutorConfig);
    } else if (newConfig instanceof QueueConfig) {
        QueueConfig queueConfig = (QueueConfig) newConfig;
        currentConfig = queueConfigs.putIfAbsent(queueConfig.getName(), queueConfig);
    } else if (newConfig instanceof ReliableTopicConfig) {
        ReliableTopicConfig reliableTopicConfig = (ReliableTopicConfig) newConfig;
        currentConfig = reliableTopicConfigs.putIfAbsent(reliableTopicConfig.getName(), reliableTopicConfig);
    } else if (newConfig instanceof CacheSimpleConfig) {
        CacheSimpleConfig cacheSimpleConfig = (CacheSimpleConfig) newConfig;
        currentConfig = cacheSimpleConfigs.putIfAbsent(cacheSimpleConfig.getName(), cacheSimpleConfig);
        if (currentConfig == null) {
            listener.onConfigRegistered(cacheSimpleConfig);
        }
    } else if (newConfig instanceof FlakeIdGeneratorConfig) {
        FlakeIdGeneratorConfig config = (FlakeIdGeneratorConfig) newConfig;
        currentConfig = flakeIdGeneratorConfigs.putIfAbsent(config.getName(), config);
    } else if (newConfig instanceof PNCounterConfig) {
        PNCounterConfig config = (PNCounterConfig) newConfig;
        currentConfig = pnCounterConfigs.putIfAbsent(config.getName(), config);
    } else {
        throw new UnsupportedOperationException("Unsupported config type: " + newConfig);
    }
    checkCurrentConfigNullOrEqual(configCheckMode, currentConfig, newConfig);
    persist(newConfig);
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) QueueConfig(com.hazelcast.config.QueueConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) TopicConfig(com.hazelcast.config.TopicConfig) PNCounterConfig(com.hazelcast.config.PNCounterConfig) ExecutorConfig(com.hazelcast.config.ExecutorConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) FlakeIdGeneratorConfig(com.hazelcast.config.FlakeIdGeneratorConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) SetConfig(com.hazelcast.config.SetConfig) MapConfig(com.hazelcast.config.MapConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) ListConfig(com.hazelcast.config.ListConfig) CardinalityEstimatorConfig(com.hazelcast.config.CardinalityEstimatorConfig)

Example 19 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class CacheSplitBrainProtectionConfigTest method cacheConfigXmlTest.

@Test
public void cacheConfigXmlTest() throws IOException {
    final String cacheName = "configtestCache" + randomString();
    Config config = new XmlConfigBuilder(configUrl).build();
    CacheSimpleConfig cacheConfig1 = config.getCacheConfig(cacheName);
    final String splitBrainProtectionName = cacheConfig1.getSplitBrainProtectionName();
    assertEquals("cache-split-brain-protection", splitBrainProtectionName);
    SplitBrainProtectionConfig splitBrainProtectionConfig = config.getSplitBrainProtectionConfig(splitBrainProtectionName);
    assertEquals(3, splitBrainProtectionConfig.getMinimumClusterSize());
    assertEquals(SplitBrainProtectionOn.READ_WRITE, splitBrainProtectionConfig.getProtectOn());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class AdvancedCacheJournalTest method getConfig.

@Override
protected Config getConfig() {
    CacheSimpleConfig cacheConfig = new CacheSimpleConfig().setName("*");
    cacheConfig.getEvictionConfig().setSize(Integer.MAX_VALUE);
    cacheConfig.setEventJournalConfig(new EventJournalConfig().setEnabled(true));
    return super.getConfig().setProperty(ClusterProperty.PARTITION_COUNT.getName(), String.valueOf(PARTITION_COUNT)).addCacheConfig(cacheConfig);
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig)

Aggregations

CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)84 Test (org.junit.Test)41 Config (com.hazelcast.config.Config)40 QuickTest (com.hazelcast.test.annotation.QuickTest)37 EvictionConfig (com.hazelcast.config.EvictionConfig)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 BeforeClass (org.junit.BeforeClass)16 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)15 MapConfig (com.hazelcast.config.MapConfig)11 ClientConfig (com.hazelcast.client.config.ClientConfig)10 EventJournalConfig (com.hazelcast.config.EventJournalConfig)10 MergePolicyConfig (com.hazelcast.config.MergePolicyConfig)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 ExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig)9 QuorumConfig (com.hazelcast.config.QuorumConfig)9 CacheConfig (com.hazelcast.config.CacheConfig)8 TimedExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig)8 QueueConfig (com.hazelcast.config.QueueConfig)8 CacheSimpleEntryListenerConfig (com.hazelcast.config.CacheSimpleEntryListenerConfig)7 CardinalityEstimatorConfig (com.hazelcast.config.CardinalityEstimatorConfig)7