Interface CacheEntryProcessor<K,V,R>

Type Parameters:
K - the type of the key
V - the type of the value
R - the type of the result returned by the processor
All Known Subinterfaces:
ReadOnlyCacheEntryProcessor<K,V,R>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CacheEntryProcessor<K,V,R>
Processes map entries in-place with strong atomicity guarantees.

Each processor execution is atomic with respect to the target entry: the full read-process-write sequence is serialized with concurrent mutations on that key while the processor is executing.

Usage:

  CacheEntryProcessorinvalid input: '<'String, Integer, Integer> incrementer = entry -> {
      int value = entry.value() != null ? entry.value() : 0;
      entry.setValue(value + 1);
      return value + 1;
  };
  Integer result = map.processEntry("counter", incrementer);
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents a mutable entry in the map during processing.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable R
    Process the given entry atomically.
  • Method Details

    • process

      @Nullable R process(CacheEntryProcessor.Entry<K,V> entry)
      Process the given entry atomically.
      Parameters:
      entry - the entry to process (mutable view into the map, must not be null)
      Returns:
      the result of processing