001package io.ebeanservice.docstore.api;
002
003import io.ebean.Transaction;
004import io.ebean.plugin.BeanType;
005
006import java.io.IOException;
007
008/**
009 * Processes index updates.
010 * <p>
011 * This involves sending updates directly to ElasticSearch via it's Bulk API or
012 * queuing events for future processing.
013 * </p>
014 */
015public interface DocStoreUpdateProcessor {
016
017  /**
018   * Create a processor to handle updates per bean via a findEach query.
019   */
020  <T> DocStoreQueryUpdate<T> createQueryUpdate(BeanType<T> beanType, int bulkBatchSize) throws IOException;
021
022  /**
023   * Process all the updates for a transaction.
024   * <p>
025   * Typically this makes calls to the Bulk API of the document store or simply adds entries
026   * to a queue for future processing.
027   * </p>
028   *
029   * @param docStoreUpdates The 'Bulk' and 'Queue' updates to the indexes for the transaction.
030   * @param bulkBatchSize   The batch size to use for Bulk API calls specified on the transaction.
031   *                        If this is 0 then the default batch size is used.
032   */
033  void process(DocStoreUpdates docStoreUpdates, int bulkBatchSize);
034
035  /**
036   * Create a document store transaction hinting at the batch size.
037   * <p>
038   * The batch size can be set via {@link Transaction#setDocStoreBatchSize(int)}
039   */
040  DocStoreTransaction createTransaction(int batchSize);
041
042  /**
043   * Perform commit/flush of the changes made via the document store transaction.
044   */
045  void commit(DocStoreTransaction docStoreTransaction);
046}