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