org.infinispan.counter.impl.function.RemoveFunction 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.io.IOException;
import java.io.ObjectInput;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.marshall.exts.NoStateExternalizer;
import org.infinispan.counter.impl.entries.CounterKey;
import org.infinispan.counter.impl.entries.CounterValue;
import org.infinispan.counter.impl.externalizers.ExternalizerIds;
import org.infinispan.functional.EntryView;
/**
* It removes the {@link CounterValue} from the cache.
*
* @author Pedro Ruivo
* @since 9.2
*/
public class RemoveFunction implements
Function, Void> {
public static final AdvancedExternalizer EXTERNALIZER = new Externalizer();
private static final RemoveFunction INSTANCE = new RemoveFunction();
private RemoveFunction() {
}
public static RemoveFunction getInstance() {
//noinspection unchecked
return INSTANCE;
}
@Override
public String toString() {
return "RemoveFunction{}";
}
@Override
public Void apply(EntryView.ReadWriteEntryView entry) {
if (entry.find().isPresent()) {
entry.remove();
}
return null;
}
private static class Externalizer extends NoStateExternalizer {
@Override
public RemoveFunction readObject(ObjectInput input) throws IOException, ClassNotFoundException {
return RemoveFunction.getInstance();
}
@Override
public Set> getTypeClasses() {
return Collections.singleton(RemoveFunction.class);
}
@Override
public Integer getId() {
return ExternalizerIds.REMOVE_FUNCTION;
}
}
}