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

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

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

import java.io.IOException;
import java.io.ObjectInput;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;

import org.infinispan.functional.EntryView;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.marshall.exts.NoStateExternalizer;
import org.infinispan.counter.impl.entries.CounterValue;
import org.infinispan.counter.impl.externalizers.ExternalizerIds;

/**
 * Read function that returns the current counter's delta.
 * 

* Singleton class. Use {@link ReadFunction#getInstance()} to retrieve it. * * @author Pedro Ruivo * @since 9.0 */ public class ReadFunction implements Function, Long> { public static final AdvancedExternalizer EXTERNALIZER = new Externalizer(); private static final ReadFunction INSTANCE = new ReadFunction(); private ReadFunction() { } public static ReadFunction getInstance() { //noinspection unchecked return INSTANCE; } @Override public String toString() { return "ReadFunction{}"; } @Override public Long apply(EntryView.ReadEntryView view) { return view.find().map(CounterValue::getValue).orElse(null); } private static class Externalizer extends NoStateExternalizer { private Externalizer() { } @Override public Set> getTypeClasses() { return Collections.singleton(ReadFunction.class); } @Override public Integer getId() { return ExternalizerIds.READ_FUNCTION; } @Override public ReadFunction readObject(ObjectInput input) throws IOException, ClassNotFoundException { return INSTANCE; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy