Search in sources :

Example 1 with CounterManagerConfigurationBuilder

use of org.infinispan.counter.configuration.CounterManagerConfigurationBuilder in project infinispan by infinispan.

the class RestartCounterTest method configure.

@Override
protected GlobalConfigurationBuilder configure(int nodeId) {
    GlobalConfigurationBuilder builder = GlobalConfigurationBuilder.defaultClusteredBuilder();
    builder.globalState().enable().persistentLocation(Paths.get(PERSISTENT_FOLDER, Integer.toString(nodeId)).toString()).temporaryLocation(Paths.get(TEMP_PERSISTENT_FOLDER, Integer.toString(nodeId)).toString()).sharedPersistentLocation(Paths.get(SHARED_PERSISTENT_FOLDER, Integer.toString(nodeId)).toString());
    CounterManagerConfigurationBuilder counterBuilder = builder.addModule(CounterManagerConfigurationBuilder.class);
    defaultCounters.forEach(counterDefinition -> counterDefinition.define(counterBuilder));
    return builder;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)

Example 2 with CounterManagerConfigurationBuilder

use of org.infinispan.counter.configuration.CounterManagerConfigurationBuilder in project infinispan by infinispan.

the class ConfigurationTest method testStrongCounterUpperBound.

public void testStrongCounterUpperBound() {
    final GlobalConfigurationBuilder builder = defaultGlobalConfigurationBuilder(false);
    CounterManagerConfigurationBuilder counterBuilder = builder.addModule(CounterManagerConfigurationBuilder.class);
    counterBuilder.addStrongCounter().name("valid").initialValue(10).upperBound(10);
    // no exception!
    builder.build();
    counterBuilder.clearCounters();
    counterBuilder.addStrongCounter().name("valid").initialValue(10).upperBound(11);
    builder.build();
    counterBuilder.clearCounters();
    counterBuilder.addStrongCounter().name("invalid").initialValue(10).upperBound(9);
    assertCounterConfigurationException(builder);
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)

Example 3 with CounterManagerConfigurationBuilder

use of org.infinispan.counter.configuration.CounterManagerConfigurationBuilder in project infinispan by infinispan.

the class ConfigurationTest method testMissingCounterName.

public void testMissingCounterName() {
    final GlobalConfigurationBuilder builder = defaultGlobalConfigurationBuilder(false);
    CounterManagerConfigurationBuilder counterBuilder = builder.addModule(CounterManagerConfigurationBuilder.class);
    counterBuilder.addStrongCounter();
    assertCounterConfigurationException(builder);
    counterBuilder.clearCounters();
    counterBuilder.addWeakCounter();
    assertCounterConfigurationException(builder);
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)

Example 4 with CounterManagerConfigurationBuilder

use of org.infinispan.counter.configuration.CounterManagerConfigurationBuilder in project infinispan by infinispan.

the class ConfigurationTest method testInvalidNumOwner.

public void testInvalidNumOwner() {
    final GlobalConfigurationBuilder builder = defaultGlobalConfigurationBuilder(false);
    CounterManagerConfigurationBuilder counterBuilder = builder.addModule(CounterManagerConfigurationBuilder.class);
    counterBuilder.numOwner(0);
    assertCounterConfigurationException(builder);
    counterBuilder.numOwner(-1);
    assertCounterConfigurationException(builder);
    counterBuilder.numOwner(1);
    builder.build();
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)

Example 5 with CounterManagerConfigurationBuilder

use of org.infinispan.counter.configuration.CounterManagerConfigurationBuilder in project infinispan by infinispan.

the class CounterResource method createCounterConfiguration.

private CounterConfiguration createCounterConfiguration(String json) {
    try (ConfigurationReader reader = ConfigurationReader.from(json).withType(APPLICATION_JSON).build()) {
        ConfigurationBuilderHolder holder = invocationHelper.getParserRegistry().parse(reader, new ConfigurationBuilderHolder());
        CounterManagerConfigurationBuilder counterModule = holder.getGlobalConfigurationBuilder().module(CounterManagerConfigurationBuilder.class);
        CounterManagerConfiguration configuration = counterModule.create();
        return ConvertUtil.parsedConfigToConfig(configuration.counters().values().iterator().next());
    }
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder) ConfigurationReader(org.infinispan.commons.configuration.io.ConfigurationReader) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration)

Aggregations

CounterManagerConfigurationBuilder (org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)12 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)11 CounterManagerConfiguration (org.infinispan.counter.configuration.CounterManagerConfiguration)2 ConfigurationReader (org.infinispan.commons.configuration.io.ConfigurationReader)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 EmbeddedCounterManagerFactory.asCounterManager (org.infinispan.counter.EmbeddedCounterManagerFactory.asCounterManager)1 CounterManager (org.infinispan.counter.api.CounterManager)1 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)1