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

org.infinispan.counter.impl.function.BaseFunction Maven / Gradle / Ivy

The newest version!
package org.infinispan.counter.impl.function;

import java.util.Optional;
import java.util.function.Function;

import org.infinispan.counter.impl.entries.CounterKey;
import org.infinispan.counter.impl.entries.CounterValue;
import org.infinispan.functional.impl.CounterConfigurationMetaParam;
import org.infinispan.counter.logging.Log;
import org.infinispan.functional.EntryView;

/**
 * A base function to update an existing counter.
 *
 * @author Pedro Ruivo
 * @since 9.0
 */
abstract class BaseFunction implements
      Function, R> {

   @Override
   public final R apply(EntryView.ReadWriteEntryView entryView) {
      Optional value = entryView.find();
      if (!value.isPresent()) {
         return null;
      }
      Optional metadata = entryView.findMetaParam(CounterConfigurationMetaParam.class);
      if (!metadata.isPresent()) {
         throw getLog().metadataIsMissing(entryView.key().getCounterName());
      }
      return apply(entryView, metadata.get());
   }

   abstract R apply(EntryView.ReadWriteEntryView entryView, CounterConfigurationMetaParam metadata);

   protected abstract Log getLog();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy