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

org.infinispan.counter.impl.function.AddFunction 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.io.ObjectOutput;
import java.util.Collections;
import java.util.Set;

import org.infinispan.commons.logging.LogFactory;
import org.infinispan.commons.marshall.AdvancedExternalizer;
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.impl.CounterConfigurationMetaParam;
import org.infinispan.counter.logging.Log;
import org.infinispan.functional.EntryView.ReadWriteEntryView;

/**
 * The adding function to update the {@link CounterValue}.
 *
 * @author Pedro Ruivo
 * @since 9.0
 */
public final class AddFunction extends BaseFunction {

   public static final AdvancedExternalizer EXTERNALIZER = new Externalizer();
   private static final Log log = LogFactory.getLog(AddFunction.class, Log.class);
   private final long delta;

   public AddFunction(long delta) {
      this.delta = delta;
   }

   @Override
   CounterValue apply(ReadWriteEntryView entry, CounterConfigurationMetaParam metadata) {
      return FunctionHelper.add(entry, entry.get(), metadata, delta);
   }

   @Override
   protected Log getLog() {
      return log;
   }

   private static class Externalizer implements AdvancedExternalizer {

      @Override
      public Set> getTypeClasses() {
         return Collections.singleton(AddFunction.class);
      }

      @Override
      public Integer getId() {
         return ExternalizerIds.ADD_FUNCTION;
      }

      @Override
      public void writeObject(ObjectOutput output, AddFunction object) throws IOException {
         output.writeLong(object.delta);
      }

      @Override
      public AddFunction readObject(ObjectInput input) throws IOException, ClassNotFoundException {
         return new AddFunction(input.readLong());
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy