All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.counter.configuration.StrongCounterConfiguration Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev03
Show newest version
package org.infinispan.counter.configuration;

import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;

/**
 * {@link org.infinispan.counter.api.StrongCounter} configuration.
 *
 * @author Pedro Ruivo
 * @since 9.0
 */
public class StrongCounterConfiguration extends AbstractCounterConfiguration {

   static final AttributeDefinition LOWER_BOUND = AttributeDefinition.builder(Attribute.LOWER_BOUND, Long.MIN_VALUE)
         .immutable()
         .build();

   static final AttributeDefinition UPPER_BOUND = AttributeDefinition.builder(Attribute.UPPER_BOUND, Long.MAX_VALUE)
         .immutable()
         .build();

   static final AttributeDefinition LIFESPAN = AttributeDefinition.builder(Attribute.LIFESPAN, -1L)
         .immutable()
         .build();

   StrongCounterConfiguration(AttributeSet attributes) {
      super(attributes);
   }

   public static AttributeSet attributeDefinitionSet() {
      return new AttributeSet(StrongCounterConfiguration.class, AbstractCounterConfiguration.attributeDefinitionSet(),
            LOWER_BOUND, UPPER_BOUND, LIFESPAN);
   }

   @Override
   CounterConfigurationBuilder toBuilder(CounterManagerConfigurationBuilder manager) {
      StrongCounterConfigurationBuilder builder = new StrongCounterConfigurationBuilder(manager);
      builder.attributes.read(attributes, Combine.DEFAULT);
      return builder;
   }

   /**
    * @return {@code true} if the counter is bounded (lower and/or upper bound has been set), {@code false} otherwise.
    */
   public boolean isBound() {
      return attributes.attribute(LOWER_BOUND).isModified() || attributes.attribute(UPPER_BOUND).isModified();
   }

   public long lowerBound() {
      return attributes.attribute(LOWER_BOUND).get();
   }

   public long upperBound() {
      return attributes.attribute(UPPER_BOUND).get();
   }

   public long lifespan() {
      return attributes.attribute(LIFESPAN).get();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy