Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleCDCConsumer.java
/** Consumer of data change events. */
@IgniteExperimental
public interface CaptureDataChangeConsumer {
    /**
     * Starts the consumer.
     *
     * @param log Logger.
     */
    void start(IgniteLogger log);

    /**
     * Handles entry changes events.
     * If this method return {@code true} then current offset will be stored and ongoing notifications after CDC application fail/restart
     * will be started from it.
     *
     * @param events Entry change events.
     * @return {@code True} if current offset should be saved on the disk to continue from it in case any failures or restart.
     */
    boolean onChange(Iterator<ChangeEvent> events);

    /**
     * Stops the consumer.
     * This methods can be invoked only after {@link #start(IgniteLogger)}.
     */
    void stop();
}

/**
 * Event of single entry change.
 * Instance presents new value of modified entry.
 *
 * @see IgniteCDC
 * @see CaptureDataChangeConsumer
 */
@IgniteExperimental
public interface ChangeEvent extends Serializable {
    /**
     * @return Key for the changed entry.
     */
    public Object key();

    /**
     * @return Value for the changed entry or {@code null} in case of entry removal.
     */
    public @Nullable Object value();

    /**
     * @return {@code True} if event fired on primary node for partition containing this entry.
     * @see <a href="https://ignite.apache.org/docs/latest/configuring-caches/configuring-backups#configuring-partition-backups">Configuring partition backups.</a>
     */
    public boolean primary();

    /**
     * @return Partition number.
     */
    public int partition();

    /**
     * @return Order of the update operation.
     */
    public ChangeEventOrder order();

    /**
     * @return Operation type.
     */
    public ChangeEventType operation();

    /**
     * @return Cache ID.
     * @see org.apache.ignite.internal.util.typedef.internal.CU#cacheId(String)
     */
    public int cacheId();
}

/**
 * Entry event order.
 * Two concurrent updates of the same entry can be ordered based on {@link ChangeEventOrder} comparsion.
 * Greater value means that event occurs later.
 */
@IgniteExperimental
public interface ChangeEventOrder extends Comparable<ChangeEventOrder>, Serializable {
    /** @return topVer Topology version plus number of seconds from the start time of the first grid node. */
    public int topVer();

    /** @return nodeOrderDrId Node order and DR ID. */
    public int nodeOrderDrId();

    /** @return Data center id. */
    public byte dataCenterId();

    /** @return order Version order. */
    public long order();

    /** @return Replication version. */
    public ChangeEventOrder otherDcOrder();
}

/**
 * Type of operations.
 *
 * @see IgniteCDC
 * @see CaptureDataChangeConsumer
 * @see ChangeEvent
 */
@IgniteExperimental
public enum ChangeEventType {
    /** Update operation. */
    UPDATE,

    /** Delete operation. */
    DELETE
}

...