Package org.apache.ignite.internal.cdc

## Class WalRecordsConsumer<K,​V>

- java.lang.Object
- - org.apache.ignite.internal.cdc.WalRecordsConsumer<K,​V>

    public class WalRecordsConsumer<K,​V>
    extends Object

Transform `DataEntry` to `CdcEvent` and sends it to `CdcConsumer`.

See Also:
  `CdcMain`, `CdcConsumer`

### Nested Class Summary

Nested Classes
`static class` `WalRecordsConsumer.DataEntryIterator` Iterator over `DataEntry`.

### Field Summary

Fields
`static String` `EVTS_CNT` Events count metric name.
`static String` `LAST_EVT_TIME` Last event time metric name.

### Constructor Summary

Constructors
`WalRecordsConsumer​(CdcConsumer consumer, IgniteLogger log)`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `alive()` Checks that consumer still alive.
`CdcConsumer` `consumer()`
`void` `onCacheDestroyEvents​(Iterator<Integer> caches)` Handles destroy cache events.
`void` `onCacheEvents​(Iterator<CdcCacheEvent> cacheEvts)` Handles new cache events.
`void` `onMappings​(Iterator<TypeMapping> mappings)` Handles new mappings.
`boolean` `onRecords​(Iterator<DataEntry> entries, IgniteClosure<DataEntry,​CdcEvent> transform, @Nullable IgnitePredicate<? super DataEntry> filter)` Handles data entries.
`void` `onTypes​(Iterator<BinaryType> types)` Handles new binary types.
`void` `start​(MetricRegistryImpl cdcReg, MetricRegistryImpl cdcConsumerReg)` Starts the consumer.
`void` `stop()` Stops the consumer.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### EVTS_CNT

    public static final String EVTS_CNT

Events count metric name.

See Also:
  Constant Field Values

#### LAST_EVT_TIME

    public static final String LAST_EVT_TIME

Last event time metric name.

See Also:
  Constant Field Values

### Constructor Detail

#### WalRecordsConsumer

    public WalRecordsConsumer​(CdcConsumer consumer,
                              IgniteLogger log)

Parameters:
  `consumer` - User provided CDC consumer.
  `log` - Logger.

### Method Detail

#### onRecords

    public boolean onRecords​(Iterator<DataEntry> entries,
                             IgniteClosure<DataEntry,​CdcEvent> transform,
                             @Nullable
                             @Nullable IgnitePredicate<? super DataEntry> filter)

Handles data entries. If this method return `true` then current offset in WAL and `DataEntry` index inside `DataRecord` will be stored and WAL iteration will be started from it on CDC application fail/restart.

Parameters:
  `entries` - Data entries iterator.
  `transform` - Event transformer.
  `filter` - Optional event filter.
Returns:
  `True` if current offset in WAL should be commited.

#### onTypes

    public void onTypes​(Iterator<BinaryType> types)

Handles new binary types.

Parameters:
  `types` - Binary types iterator.

#### onMappings

    public void onMappings​(Iterator<TypeMapping> mappings)

Handles new mappings.

Parameters:
  `mappings` - Mappings iterator.

#### onCacheEvents

    public void onCacheEvents​(Iterator<CdcCacheEvent> cacheEvts)

Handles new cache events.

Parameters:
  `cacheEvts` - Cache events iterator.

#### onCacheDestroyEvents

    public void onCacheDestroyEvents​(Iterator<Integer> caches)

Handles destroy cache events.

Parameters:
  `caches` - Destroyed cache iterator.

#### start

    public void start​(MetricRegistryImpl cdcReg,
                      MetricRegistryImpl cdcConsumerReg)
               throws IgniteCheckedException

Starts the consumer.

Parameters:
  `cdcReg` - CDC metric registry.
  `cdcConsumerReg` - CDC consumer metric registry.
Throws:
  `IgniteCheckedException` - If failed.

#### stop

    public void stop()

Stops the consumer. This methods can be invoked only after `start(MetricRegistryImpl, MetricRegistryImpl)`.

#### alive

    public boolean alive()

Checks that consumer still alive. This method helps to determine `CdcConsumer` errors in case `CdcEvent` is rare or source cluster is down.

Returns:
  `True` in case consumer alive, `false` otherwise.

#### consumer

    public CdcConsumer consumer()

Returns:
  Change Data Capture Consumer.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`