org.infinispan.counter.configuration.CounterManagerConfiguration Maven / Gradle / Ivy
Show all versions of infinispan-clustered-counter Show documentation
package org.infinispan.counter.configuration;
import static org.infinispan.counter.logging.Log.CONTAINER;
import java.util.Collections;
import java.util.Map;
import org.infinispan.commons.configuration.BuiltBy;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
import org.infinispan.configuration.serializing.SerializedWith;
/**
* The {@link org.infinispan.counter.api.CounterManager} configuration.
*
* It configures the number of owners (number of copies in the cluster) of a counter and the {@link Reliability} mode.
*
* @author Pedro Ruivo
* @since 9.0
*/
@SerializedWith(CounterConfigurationSerializer.class)
@BuiltBy(CounterManagerConfigurationBuilder.class)
public class CounterManagerConfiguration extends ConfigurationElement {
static final AttributeDefinition RELIABILITY = AttributeDefinition
.builder("reliability", Reliability.AVAILABLE)
.validator(value -> {
if (value == null) {
throw CONTAINER.invalidReliabilityMode();
}
})
.immutable().build();
static final AttributeDefinition NUM_OWNERS = AttributeDefinition.builder(Attribute.NUM_OWNERS, 2)
.validator(value -> {
if (value < 1) {
throw CONTAINER.invalidNumOwners(value);
}
})
.immutable().build();
private final Map counters;
CounterManagerConfiguration(AttributeSet attributes, Map counters) {
super(Element.COUNTERS, attributes);
this.counters = counters;
}
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(CounterManagerConfiguration.class, NUM_OWNERS, RELIABILITY);
}
public int numOwners() {
return attributes.attribute(NUM_OWNERS).get();
}
public Reliability reliability() {
return attributes.attribute(RELIABILITY).get();
}
public Map counters() {
return Collections.unmodifiableMap(counters);
}
}