use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class ConfigurationTest method testInvalidEqualsUpperAndLowerBoundInManager.
public void testInvalidEqualsUpperAndLowerBoundInManager() {
TestingUtil.withCacheManager(DefaultCacheManager::new, cacheManager -> {
CounterManager manager = asCounterManager(cacheManager);
CounterConfiguration cfg = CounterConfiguration.builder(CounterType.BOUNDED_STRONG).initialValue(10).lowerBound(10).upperBound(10).build();
expectException(CounterConfigurationException.class, () -> manager.defineCounter("invalid", cfg));
});
}
use of org.infinispan.counter.api.CounterConfiguration 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.counter.api.CounterConfiguration in project infinispan by infinispan.
the class EmbeddedCounterManager method removeCounter.
private void removeCounter(String counterName, boolean keepConfig) {
CounterConfiguration configuration = getConfiguration(counterName);
if (configuration == null) {
// counter not defined (cluster-wide). do nothing :)
return;
}
counters.compute(counterName, (name, counter) -> {
removeCounter(name, counter, configuration);
if (!keepConfig)
awaitCounterOperation(configurationManager.removeConfiguration(name));
return null;
});
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class EmbeddedCounterManager method createCounter.
private Object createCounter(String counterName) {
CounterConfiguration configuration = getConfiguration(counterName);
if (configuration == null) {
throw CONTAINER.undefinedCounter(counterName);
}
switch(configuration.type()) {
case WEAK:
// topology listener is used to compute the keys where this node is the primary owner
// adds are made on these keys to avoid contention and improve performance
notificationManager.registerTopologyListener(cache());
// the weak counter keeps a local value and, on each event, the local value is updated (reads are always local)
notificationManager.registerCounterValueListener(cache());
return createWeakCounter(counterName, configuration);
case BOUNDED_STRONG:
return createBoundedStrongCounter(counterName, configuration);
case UNBOUNDED_STRONG:
return createUnboundedStrongCounter(counterName, configuration);
default:
throw new IllegalStateException("[should never happen] unknown counter type: " + configuration.type());
}
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class ExpirationStrongCounterTest method testBoundedCounterNeverReached.
public void testBoundedCounterNeverReached() {
CounterConfiguration config = CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lifespan(EXPIRATION_MILLISECONDS).upperBound(30).build();
String counterName = "bounded-counter-2";
CounterManager counterManager = counterManager();
counterManager.defineCounter(counterName, config);
doTest(counterName, 30);
}
Aggregations