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

org.infinispan.counter.impl.function.RemoveFunction 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.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;
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy