Interface EntryTransformer

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 EntryTransformer
A functional interface for transforming key-value entries from GridGain 8 cluster to a format suitable for GridGain 9.

This interface defines a transformation operation that accepts binary-serialized key and value objects and produces a Result.

An example implementation which converts every column to string representation:


 class StringifyTransformer implements EntryTransformer {
     @Override
     public Result transform(BinaryObjectReader keyReader, @Nullable BinaryObjectReader valueReader) {
         // Skip entries of unwanted type.
         if (valueReader != null && !"org.myValue".equals(valueReader.typeName())) {
             return Result.skip();
         }

         Tuple key = Tuple.create();

         for (String fieldName : keyReader.fieldNames()) {
             key.set(fieldName, "" + keyReader.readField(fieldName));
         }

         // If value reader is not presented, then this event belongs to a Remove operation.
         // Let's remove this entry from GG9 cluster as well.
         if (valueReader == null) {
             return Result.remove(key);
         }

         Tuple value = Tuple.create();
         for (String fieldName : valueReader.fieldNames()) {
             value.set(fieldName, "" + valueReader.readField(fieldName));
         }

         return Result.upsert(key, value);
     }
 }
 

Lifecycle: Transformer is created by factory class specified in mapping configuration during connector startup once per mapping. The same instance of transformer will be reused to process all batches from related cache as per mapping configuration.

Thread Safety: Implementations are expected to be thread-safe as the same instance of transformer may be used by different threads to process incoming batches.

Exception Handling: Implementations should be designed to handle errors gracefully. If any exception is thrown from the transform(org.gridgain.dr.conversion.BinaryObjectReader, org.gridgain.dr.conversion.BinaryObjectReader) method during execution, the result of the transformation operation, and therefore of the replication is undefined.

  • Method Details

    • transform

      Result transform(BinaryObjectReader keyReader, @Nullable @Nullable BinaryObjectReader valueReader)
      Transforms a key-value entry.

      This method receives binary object readers for both the key and value components of an GridGain 8 entry. The key reader is always non-null, while the value reader may be null for removed entries (e.g. tombstones).

      If key and/or value part of GridGain 8 entry is simple object (like in case of IgniteCache<Long, String> for example), then BinaryObjectReader with single field will be created. For key part the field name will be _key, for value part the field name will be _val.

      Implementations can:

      • Extract and process fields from the key and value using BinaryObjectReader.readField(String).
      • Filter entries by returning appropriate Result states.
      • Transform the entry data into a different format.
      • Perform validation or enrichment operations.

      Exception Behavior: If this method throws any exception during execution, the result of the transformation is undefined.

      Parameters:
      keyReader - the binary reader for the entry's key, never null.
      valueReader - The binary reader for the entry's value, may be null if the entry represents a deletion.
      Returns:
      The transformation result, should not be null.