org.infinispan.counter.impl.function.BaseFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infinispan-clustered-counter Show documentation
Show all versions of infinispan-clustered-counter Show documentation
Infinispan Clustered Counter module
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();
}