All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arakelian.elastic.model.ImmutableBulkIndexerConfig Maven / Gradle / Ivy

package com.arakelian.elastic.model;

import com.arakelian.elastic.bulk.BulkOperationFactory;
import com.arakelian.elastic.bulk.event.IndexerListener;
import com.arakelian.retry.Retryer;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link BulkIndexerConfig}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableBulkIndexerConfig.builder()}. */ @Generated(from = "BulkIndexerConfig", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableBulkIndexerConfig extends BulkIndexerConfig { private final int automaticFlushMillis; private final BulkOperationFactory bulkOperationFactory; private final IndexerListener listener; private final int maxBulkOperationBytes; private final int maxBulkOperations; private final int maximumThreads; private final int maxPartialRetries; private final int partialRetryDelayMillis; private final int queueSize; private final Retryer retryer; private final int shutdownTimeout; private final TimeUnit shutdownTimeoutUnit; private final boolean blockingQueue; private ImmutableBulkIndexerConfig(ImmutableBulkIndexerConfig.Builder builder) { this.bulkOperationFactory = builder.bulkOperationFactory; if (builder.automaticFlushMillisIsSet()) { initShim.automaticFlushMillis(builder.automaticFlushMillis); } if (builder.listener != null) { initShim.listener(builder.listener); } if (builder.maxBulkOperationBytesIsSet()) { initShim.maxBulkOperationBytes(builder.maxBulkOperationBytes); } if (builder.maxBulkOperationsIsSet()) { initShim.maxBulkOperations(builder.maxBulkOperations); } if (builder.maximumThreadsIsSet()) { initShim.maximumThreads(builder.maximumThreads); } if (builder.maxPartialRetriesIsSet()) { initShim.maxPartialRetries(builder.maxPartialRetries); } if (builder.partialRetryDelayMillisIsSet()) { initShim.partialRetryDelayMillis(builder.partialRetryDelayMillis); } if (builder.queueSizeIsSet()) { initShim.queueSize(builder.queueSize); } if (builder.retryer != null) { initShim.retryer(builder.retryer); } if (builder.shutdownTimeoutIsSet()) { initShim.shutdownTimeout(builder.shutdownTimeout); } if (builder.shutdownTimeoutUnit != null) { initShim.shutdownTimeoutUnit(builder.shutdownTimeoutUnit); } if (builder.blockingQueueIsSet()) { initShim.blockingQueue(builder.blockingQueue); } this.automaticFlushMillis = initShim.getAutomaticFlushMillis(); this.listener = initShim.getListener(); this.maxBulkOperationBytes = initShim.getMaxBulkOperationBytes(); this.maxBulkOperations = initShim.getMaxBulkOperations(); this.maximumThreads = initShim.getMaximumThreads(); this.maxPartialRetries = initShim.getMaxPartialRetries(); this.partialRetryDelayMillis = initShim.getPartialRetryDelayMillis(); this.queueSize = initShim.getQueueSize(); this.retryer = initShim.getRetryer(); this.shutdownTimeout = initShim.getShutdownTimeout(); this.shutdownTimeoutUnit = initShim.getShutdownTimeoutUnit(); this.blockingQueue = initShim.isBlockingQueue(); this.initShim = null; } private static final byte STAGE_INITIALIZING = -1; private static final byte STAGE_UNINITIALIZED = 0; private static final byte STAGE_INITIALIZED = 1; @SuppressWarnings("Immutable") private transient volatile InitShim initShim = new InitShim(); @Generated(from = "BulkIndexerConfig", generator = "Immutables") private final class InitShim { private byte automaticFlushMillisBuildStage = STAGE_UNINITIALIZED; private int automaticFlushMillis; int getAutomaticFlushMillis() { if (automaticFlushMillisBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (automaticFlushMillisBuildStage == STAGE_UNINITIALIZED) { automaticFlushMillisBuildStage = STAGE_INITIALIZING; this.automaticFlushMillis = ImmutableBulkIndexerConfig.super.getAutomaticFlushMillis(); automaticFlushMillisBuildStage = STAGE_INITIALIZED; } return this.automaticFlushMillis; } void automaticFlushMillis(int automaticFlushMillis) { this.automaticFlushMillis = automaticFlushMillis; automaticFlushMillisBuildStage = STAGE_INITIALIZED; } private byte listenerBuildStage = STAGE_UNINITIALIZED; private IndexerListener listener; IndexerListener getListener() { if (listenerBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (listenerBuildStage == STAGE_UNINITIALIZED) { listenerBuildStage = STAGE_INITIALIZING; this.listener = Objects.requireNonNull(ImmutableBulkIndexerConfig.super.getListener(), "listener"); listenerBuildStage = STAGE_INITIALIZED; } return this.listener; } void listener(IndexerListener listener) { this.listener = listener; listenerBuildStage = STAGE_INITIALIZED; } private byte maxBulkOperationBytesBuildStage = STAGE_UNINITIALIZED; private int maxBulkOperationBytes; int getMaxBulkOperationBytes() { if (maxBulkOperationBytesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (maxBulkOperationBytesBuildStage == STAGE_UNINITIALIZED) { maxBulkOperationBytesBuildStage = STAGE_INITIALIZING; this.maxBulkOperationBytes = ImmutableBulkIndexerConfig.super.getMaxBulkOperationBytes(); maxBulkOperationBytesBuildStage = STAGE_INITIALIZED; } return this.maxBulkOperationBytes; } void maxBulkOperationBytes(int maxBulkOperationBytes) { this.maxBulkOperationBytes = maxBulkOperationBytes; maxBulkOperationBytesBuildStage = STAGE_INITIALIZED; } private byte maxBulkOperationsBuildStage = STAGE_UNINITIALIZED; private int maxBulkOperations; int getMaxBulkOperations() { if (maxBulkOperationsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (maxBulkOperationsBuildStage == STAGE_UNINITIALIZED) { maxBulkOperationsBuildStage = STAGE_INITIALIZING; this.maxBulkOperations = ImmutableBulkIndexerConfig.super.getMaxBulkOperations(); maxBulkOperationsBuildStage = STAGE_INITIALIZED; } return this.maxBulkOperations; } void maxBulkOperations(int maxBulkOperations) { this.maxBulkOperations = maxBulkOperations; maxBulkOperationsBuildStage = STAGE_INITIALIZED; } private byte maximumThreadsBuildStage = STAGE_UNINITIALIZED; private int maximumThreads; int getMaximumThreads() { if (maximumThreadsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (maximumThreadsBuildStage == STAGE_UNINITIALIZED) { maximumThreadsBuildStage = STAGE_INITIALIZING; this.maximumThreads = ImmutableBulkIndexerConfig.super.getMaximumThreads(); maximumThreadsBuildStage = STAGE_INITIALIZED; } return this.maximumThreads; } void maximumThreads(int maximumThreads) { this.maximumThreads = maximumThreads; maximumThreadsBuildStage = STAGE_INITIALIZED; } private byte maxPartialRetriesBuildStage = STAGE_UNINITIALIZED; private int maxPartialRetries; int getMaxPartialRetries() { if (maxPartialRetriesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (maxPartialRetriesBuildStage == STAGE_UNINITIALIZED) { maxPartialRetriesBuildStage = STAGE_INITIALIZING; this.maxPartialRetries = ImmutableBulkIndexerConfig.super.getMaxPartialRetries(); maxPartialRetriesBuildStage = STAGE_INITIALIZED; } return this.maxPartialRetries; } void maxPartialRetries(int maxPartialRetries) { this.maxPartialRetries = maxPartialRetries; maxPartialRetriesBuildStage = STAGE_INITIALIZED; } private byte partialRetryDelayMillisBuildStage = STAGE_UNINITIALIZED; private int partialRetryDelayMillis; int getPartialRetryDelayMillis() { if (partialRetryDelayMillisBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (partialRetryDelayMillisBuildStage == STAGE_UNINITIALIZED) { partialRetryDelayMillisBuildStage = STAGE_INITIALIZING; this.partialRetryDelayMillis = ImmutableBulkIndexerConfig.super.getPartialRetryDelayMillis(); partialRetryDelayMillisBuildStage = STAGE_INITIALIZED; } return this.partialRetryDelayMillis; } void partialRetryDelayMillis(int partialRetryDelayMillis) { this.partialRetryDelayMillis = partialRetryDelayMillis; partialRetryDelayMillisBuildStage = STAGE_INITIALIZED; } private byte queueSizeBuildStage = STAGE_UNINITIALIZED; private int queueSize; int getQueueSize() { if (queueSizeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (queueSizeBuildStage == STAGE_UNINITIALIZED) { queueSizeBuildStage = STAGE_INITIALIZING; this.queueSize = ImmutableBulkIndexerConfig.super.getQueueSize(); queueSizeBuildStage = STAGE_INITIALIZED; } return this.queueSize; } void queueSize(int queueSize) { this.queueSize = queueSize; queueSizeBuildStage = STAGE_INITIALIZED; } private byte retryerBuildStage = STAGE_UNINITIALIZED; private Retryer retryer; Retryer getRetryer() { if (retryerBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (retryerBuildStage == STAGE_UNINITIALIZED) { retryerBuildStage = STAGE_INITIALIZING; this.retryer = Objects.requireNonNull(ImmutableBulkIndexerConfig.super.getRetryer(), "retryer"); retryerBuildStage = STAGE_INITIALIZED; } return this.retryer; } void retryer(Retryer retryer) { this.retryer = retryer; retryerBuildStage = STAGE_INITIALIZED; } private byte shutdownTimeoutBuildStage = STAGE_UNINITIALIZED; private int shutdownTimeout; int getShutdownTimeout() { if (shutdownTimeoutBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (shutdownTimeoutBuildStage == STAGE_UNINITIALIZED) { shutdownTimeoutBuildStage = STAGE_INITIALIZING; this.shutdownTimeout = ImmutableBulkIndexerConfig.super.getShutdownTimeout(); shutdownTimeoutBuildStage = STAGE_INITIALIZED; } return this.shutdownTimeout; } void shutdownTimeout(int shutdownTimeout) { this.shutdownTimeout = shutdownTimeout; shutdownTimeoutBuildStage = STAGE_INITIALIZED; } private byte shutdownTimeoutUnitBuildStage = STAGE_UNINITIALIZED; private TimeUnit shutdownTimeoutUnit; TimeUnit getShutdownTimeoutUnit() { if (shutdownTimeoutUnitBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (shutdownTimeoutUnitBuildStage == STAGE_UNINITIALIZED) { shutdownTimeoutUnitBuildStage = STAGE_INITIALIZING; this.shutdownTimeoutUnit = Objects.requireNonNull(ImmutableBulkIndexerConfig.super.getShutdownTimeoutUnit(), "shutdownTimeoutUnit"); shutdownTimeoutUnitBuildStage = STAGE_INITIALIZED; } return this.shutdownTimeoutUnit; } void shutdownTimeoutUnit(TimeUnit shutdownTimeoutUnit) { this.shutdownTimeoutUnit = shutdownTimeoutUnit; shutdownTimeoutUnitBuildStage = STAGE_INITIALIZED; } private byte blockingQueueBuildStage = STAGE_UNINITIALIZED; private boolean blockingQueue; boolean isBlockingQueue() { if (blockingQueueBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (blockingQueueBuildStage == STAGE_UNINITIALIZED) { blockingQueueBuildStage = STAGE_INITIALIZING; this.blockingQueue = ImmutableBulkIndexerConfig.super.isBlockingQueue(); blockingQueueBuildStage = STAGE_INITIALIZED; } return this.blockingQueue; } void blockingQueue(boolean blockingQueue) { this.blockingQueue = blockingQueue; blockingQueueBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (automaticFlushMillisBuildStage == STAGE_INITIALIZING) attributes.add("automaticFlushMillis"); if (listenerBuildStage == STAGE_INITIALIZING) attributes.add("listener"); if (maxBulkOperationBytesBuildStage == STAGE_INITIALIZING) attributes.add("maxBulkOperationBytes"); if (maxBulkOperationsBuildStage == STAGE_INITIALIZING) attributes.add("maxBulkOperations"); if (maximumThreadsBuildStage == STAGE_INITIALIZING) attributes.add("maximumThreads"); if (maxPartialRetriesBuildStage == STAGE_INITIALIZING) attributes.add("maxPartialRetries"); if (partialRetryDelayMillisBuildStage == STAGE_INITIALIZING) attributes.add("partialRetryDelayMillis"); if (queueSizeBuildStage == STAGE_INITIALIZING) attributes.add("queueSize"); if (retryerBuildStage == STAGE_INITIALIZING) attributes.add("retryer"); if (shutdownTimeoutBuildStage == STAGE_INITIALIZING) attributes.add("shutdownTimeout"); if (shutdownTimeoutUnitBuildStage == STAGE_INITIALIZING) attributes.add("shutdownTimeoutUnit"); if (blockingQueueBuildStage == STAGE_INITIALIZING) attributes.add("blockingQueue"); return "Cannot build BulkIndexerConfig, attribute initializers form cycle " + attributes; } } /** * Returns the number of milliseconds to wait before automatically flushing the bulk queue. If * this is zero or negative, the bulk queue is never automatically flushed. * @return number of milliseconds to wait before automatically flushing the bulk queue. */ @Override public int getAutomaticFlushMillis() { InitShim shim = this.initShim; return shim != null ? shim.getAutomaticFlushMillis() : this.automaticFlushMillis; } /** * @return The value of the {@code bulkOperationFactory} attribute */ @Override public BulkOperationFactory getBulkOperationFactory() { return bulkOperationFactory; } /** * @return The value of the {@code listener} attribute */ @Override public IndexerListener getListener() { InitShim shim = this.initShim; return shim != null ? shim.getListener() : this.listener; } /** * Returns the maximum size of a bulk operation (in bytes) * @return maximum size of a bulk operation */ @Override public int getMaxBulkOperationBytes() { InitShim shim = this.initShim; return shim != null ? shim.getMaxBulkOperationBytes() : this.maxBulkOperationBytes; } /** * Returns the maximum size of a bulk operation (in documents) * @return maximum size of a batch operation (in documents) */ @Override public int getMaxBulkOperations() { InitShim shim = this.initShim; return shim != null ? shim.getMaxBulkOperations() : this.maxBulkOperations; } /** * @return The value of the {@code maximumThreads} attribute */ @Override public int getMaximumThreads() { InitShim shim = this.initShim; return shim != null ? shim.getMaximumThreads() : this.maximumThreads; } /** * Returns the fixed number of times to perform partial retries. * @return the fixed number of times to perform partial retries. */ @Override public int getMaxPartialRetries() { InitShim shim = this.initShim; return shim != null ? shim.getMaxPartialRetries() : this.maxPartialRetries; } /** * Returns the fixed delay before attempting partial retries. * @return the fixed delay before attempting partial retries. */ @Override public int getPartialRetryDelayMillis() { InitShim shim = this.initShim; return shim != null ? shim.getPartialRetryDelayMillis() : this.partialRetryDelayMillis; } /** * @return The value of the {@code queueSize} attribute */ @Override public int getQueueSize() { InitShim shim = this.initShim; return shim != null ? shim.getQueueSize() : this.queueSize; } /** * Returns a retryer, which executes a call to Elastic, and retries it until it succeeds, or a * stop strategy decides to stop retrying. * @return a retryer, which executes a call to Elastic, and retries it until it succeeds, or a * stop strategy decides to stop retrying. */ @Override public Retryer getRetryer() { InitShim shim = this.initShim; return shim != null ? shim.getRetryer() : this.retryer; } /** * @return The value of the {@code shutdownTimeout} attribute */ @Override public int getShutdownTimeout() { InitShim shim = this.initShim; return shim != null ? shim.getShutdownTimeout() : this.shutdownTimeout; } /** * @return The value of the {@code shutdownTimeoutUnit} attribute */ @Override public TimeUnit getShutdownTimeoutUnit() { InitShim shim = this.initShim; return shim != null ? shim.getShutdownTimeoutUnit() : this.shutdownTimeoutUnit; } /** * Returns true if caller should block when indexer queue is full. * @return true if caller should block when indexer queue is full. */ @Override public boolean isBlockingQueue() { InitShim shim = this.initShim; return shim != null ? shim.isBlockingQueue() : this.blockingQueue; } /** * This instance is equal to all instances of {@code ImmutableBulkIndexerConfig} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableBulkIndexerConfig && equalTo((ImmutableBulkIndexerConfig) another); } private boolean equalTo(ImmutableBulkIndexerConfig another) { return automaticFlushMillis == another.automaticFlushMillis && maxBulkOperationBytes == another.maxBulkOperationBytes && maxBulkOperations == another.maxBulkOperations && maximumThreads == another.maximumThreads && maxPartialRetries == another.maxPartialRetries && partialRetryDelayMillis == another.partialRetryDelayMillis && queueSize == another.queueSize && shutdownTimeout == another.shutdownTimeout && shutdownTimeoutUnit.equals(another.shutdownTimeoutUnit) && blockingQueue == another.blockingQueue; } /** * Computes a hash code from attributes: {@code automaticFlushMillis}, {@code maxBulkOperationBytes}, {@code maxBulkOperations}, {@code maximumThreads}, {@code maxPartialRetries}, {@code partialRetryDelayMillis}, {@code queueSize}, {@code shutdownTimeout}, {@code shutdownTimeoutUnit}, {@code blockingQueue}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + automaticFlushMillis; h += (h << 5) + maxBulkOperationBytes; h += (h << 5) + maxBulkOperations; h += (h << 5) + maximumThreads; h += (h << 5) + maxPartialRetries; h += (h << 5) + partialRetryDelayMillis; h += (h << 5) + queueSize; h += (h << 5) + shutdownTimeout; h += (h << 5) + shutdownTimeoutUnit.hashCode(); h += (h << 5) + Booleans.hashCode(blockingQueue); return h; } /** * Prints the immutable value {@code BulkIndexerConfig} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("BulkIndexerConfig") .omitNullValues() .add("automaticFlushMillis", automaticFlushMillis) .add("maxBulkOperationBytes", maxBulkOperationBytes) .add("maxBulkOperations", maxBulkOperations) .add("maximumThreads", maximumThreads) .add("maxPartialRetries", maxPartialRetries) .add("partialRetryDelayMillis", partialRetryDelayMillis) .add("queueSize", queueSize) .add("shutdownTimeout", shutdownTimeout) .add("shutdownTimeoutUnit", shutdownTimeoutUnit) .add("blockingQueue", blockingQueue) .toString(); } private static ImmutableBulkIndexerConfig validate(ImmutableBulkIndexerConfig instance) { instance.checkSettings(); return instance; } /** * Creates a builder for {@link ImmutableBulkIndexerConfig ImmutableBulkIndexerConfig}. *

   * ImmutableBulkIndexerConfig.builder()
   *    .automaticFlushMillis(int) // optional {@link BulkIndexerConfig#getAutomaticFlushMillis() automaticFlushMillis}
   *    .bulkOperationFactory(com.arakelian.elastic.bulk.BulkOperationFactory) // required {@link BulkIndexerConfig#getBulkOperationFactory() bulkOperationFactory}
   *    .listener(com.arakelian.elastic.bulk.event.IndexerListener) // optional {@link BulkIndexerConfig#getListener() listener}
   *    .maxBulkOperationBytes(int) // optional {@link BulkIndexerConfig#getMaxBulkOperationBytes() maxBulkOperationBytes}
   *    .maxBulkOperations(int) // optional {@link BulkIndexerConfig#getMaxBulkOperations() maxBulkOperations}
   *    .maximumThreads(int) // optional {@link BulkIndexerConfig#getMaximumThreads() maximumThreads}
   *    .maxPartialRetries(int) // optional {@link BulkIndexerConfig#getMaxPartialRetries() maxPartialRetries}
   *    .partialRetryDelayMillis(int) // optional {@link BulkIndexerConfig#getPartialRetryDelayMillis() partialRetryDelayMillis}
   *    .queueSize(int) // optional {@link BulkIndexerConfig#getQueueSize() queueSize}
   *    .retryer(com.arakelian.retry.Retryer&lt;com.arakelian.elastic.model.BulkResponse&gt;) // optional {@link BulkIndexerConfig#getRetryer() retryer}
   *    .shutdownTimeout(int) // optional {@link BulkIndexerConfig#getShutdownTimeout() shutdownTimeout}
   *    .shutdownTimeoutUnit(concurrent.TimeUnit) // optional {@link BulkIndexerConfig#getShutdownTimeoutUnit() shutdownTimeoutUnit}
   *    .blockingQueue(boolean) // optional {@link BulkIndexerConfig#isBlockingQueue() blockingQueue}
   *    .build();
   * 
* @return A new ImmutableBulkIndexerConfig builder */ public static ImmutableBulkIndexerConfig.Builder builder() { return new ImmutableBulkIndexerConfig.Builder(); } /** * Builds instances of type {@link ImmutableBulkIndexerConfig ImmutableBulkIndexerConfig}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "BulkIndexerConfig", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_BULK_OPERATION_FACTORY = 0x1L; private static final long OPT_BIT_AUTOMATIC_FLUSH_MILLIS = 0x1L; private static final long OPT_BIT_MAX_BULK_OPERATION_BYTES = 0x2L; private static final long OPT_BIT_MAX_BULK_OPERATIONS = 0x4L; private static final long OPT_BIT_MAXIMUM_THREADS = 0x8L; private static final long OPT_BIT_MAX_PARTIAL_RETRIES = 0x10L; private static final long OPT_BIT_PARTIAL_RETRY_DELAY_MILLIS = 0x20L; private static final long OPT_BIT_QUEUE_SIZE = 0x40L; private static final long OPT_BIT_SHUTDOWN_TIMEOUT = 0x80L; private static final long OPT_BIT_BLOCKING_QUEUE = 0x100L; private long initBits = 0x1L; private long optBits; private int automaticFlushMillis; private @Nullable BulkOperationFactory bulkOperationFactory; private @Nullable IndexerListener listener; private int maxBulkOperationBytes; private int maxBulkOperations; private int maximumThreads; private int maxPartialRetries; private int partialRetryDelayMillis; private int queueSize; private @Nullable Retryer retryer; private int shutdownTimeout; private @Nullable TimeUnit shutdownTimeoutUnit; private boolean blockingQueue; private Builder() { } /** * Fill a builder with attribute values from the provided {@code BulkIndexerConfig} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(BulkIndexerConfig instance) { Objects.requireNonNull(instance, "instance"); automaticFlushMillis(instance.getAutomaticFlushMillis()); bulkOperationFactory(instance.getBulkOperationFactory()); listener(instance.getListener()); maxBulkOperationBytes(instance.getMaxBulkOperationBytes()); maxBulkOperations(instance.getMaxBulkOperations()); maximumThreads(instance.getMaximumThreads()); maxPartialRetries(instance.getMaxPartialRetries()); partialRetryDelayMillis(instance.getPartialRetryDelayMillis()); queueSize(instance.getQueueSize()); retryer(instance.getRetryer()); shutdownTimeout(instance.getShutdownTimeout()); shutdownTimeoutUnit(instance.getShutdownTimeoutUnit()); blockingQueue(instance.isBlockingQueue()); return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getAutomaticFlushMillis() automaticFlushMillis} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getAutomaticFlushMillis() automaticFlushMillis}. * @param automaticFlushMillis The value for automaticFlushMillis * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder automaticFlushMillis(int automaticFlushMillis) { this.automaticFlushMillis = automaticFlushMillis; optBits |= OPT_BIT_AUTOMATIC_FLUSH_MILLIS; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getBulkOperationFactory() bulkOperationFactory} attribute. * @param bulkOperationFactory The value for bulkOperationFactory * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder bulkOperationFactory(BulkOperationFactory bulkOperationFactory) { this.bulkOperationFactory = Objects.requireNonNull(bulkOperationFactory, "bulkOperationFactory"); initBits &= ~INIT_BIT_BULK_OPERATION_FACTORY; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getListener() listener} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getListener() listener}. * @param listener The value for listener * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder listener(IndexerListener listener) { this.listener = Objects.requireNonNull(listener, "listener"); return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getMaxBulkOperationBytes() maxBulkOperationBytes} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getMaxBulkOperationBytes() maxBulkOperationBytes}. * @param maxBulkOperationBytes The value for maxBulkOperationBytes * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder maxBulkOperationBytes(int maxBulkOperationBytes) { this.maxBulkOperationBytes = maxBulkOperationBytes; optBits |= OPT_BIT_MAX_BULK_OPERATION_BYTES; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getMaxBulkOperations() maxBulkOperations} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getMaxBulkOperations() maxBulkOperations}. * @param maxBulkOperations The value for maxBulkOperations * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder maxBulkOperations(int maxBulkOperations) { this.maxBulkOperations = maxBulkOperations; optBits |= OPT_BIT_MAX_BULK_OPERATIONS; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getMaximumThreads() maximumThreads} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getMaximumThreads() maximumThreads}. * @param maximumThreads The value for maximumThreads * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder maximumThreads(int maximumThreads) { this.maximumThreads = maximumThreads; optBits |= OPT_BIT_MAXIMUM_THREADS; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getMaxPartialRetries() maxPartialRetries} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getMaxPartialRetries() maxPartialRetries}. * @param maxPartialRetries The value for maxPartialRetries * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder maxPartialRetries(int maxPartialRetries) { this.maxPartialRetries = maxPartialRetries; optBits |= OPT_BIT_MAX_PARTIAL_RETRIES; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getPartialRetryDelayMillis() partialRetryDelayMillis} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getPartialRetryDelayMillis() partialRetryDelayMillis}. * @param partialRetryDelayMillis The value for partialRetryDelayMillis * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder partialRetryDelayMillis(int partialRetryDelayMillis) { this.partialRetryDelayMillis = partialRetryDelayMillis; optBits |= OPT_BIT_PARTIAL_RETRY_DELAY_MILLIS; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getQueueSize() queueSize} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getQueueSize() queueSize}. * @param queueSize The value for queueSize * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder queueSize(int queueSize) { this.queueSize = queueSize; optBits |= OPT_BIT_QUEUE_SIZE; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getRetryer() retryer} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getRetryer() retryer}. * @param retryer The value for retryer * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder retryer(Retryer retryer) { this.retryer = Objects.requireNonNull(retryer, "retryer"); return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getShutdownTimeout() shutdownTimeout} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getShutdownTimeout() shutdownTimeout}. * @param shutdownTimeout The value for shutdownTimeout * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder shutdownTimeout(int shutdownTimeout) { this.shutdownTimeout = shutdownTimeout; optBits |= OPT_BIT_SHUTDOWN_TIMEOUT; return this; } /** * Initializes the value for the {@link BulkIndexerConfig#getShutdownTimeoutUnit() shutdownTimeoutUnit} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#getShutdownTimeoutUnit() shutdownTimeoutUnit}. * @param shutdownTimeoutUnit The value for shutdownTimeoutUnit * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder shutdownTimeoutUnit(TimeUnit shutdownTimeoutUnit) { this.shutdownTimeoutUnit = Objects.requireNonNull(shutdownTimeoutUnit, "shutdownTimeoutUnit"); return this; } /** * Initializes the value for the {@link BulkIndexerConfig#isBlockingQueue() blockingQueue} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link BulkIndexerConfig#isBlockingQueue() blockingQueue}. * @param blockingQueue The value for blockingQueue * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder blockingQueue(boolean blockingQueue) { this.blockingQueue = blockingQueue; optBits |= OPT_BIT_BLOCKING_QUEUE; return this; } /** * Builds a new {@link ImmutableBulkIndexerConfig ImmutableBulkIndexerConfig}. * @return An immutable instance of BulkIndexerConfig * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableBulkIndexerConfig build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutableBulkIndexerConfig.validate(new ImmutableBulkIndexerConfig(this)); } private boolean automaticFlushMillisIsSet() { return (optBits & OPT_BIT_AUTOMATIC_FLUSH_MILLIS) != 0; } private boolean maxBulkOperationBytesIsSet() { return (optBits & OPT_BIT_MAX_BULK_OPERATION_BYTES) != 0; } private boolean maxBulkOperationsIsSet() { return (optBits & OPT_BIT_MAX_BULK_OPERATIONS) != 0; } private boolean maximumThreadsIsSet() { return (optBits & OPT_BIT_MAXIMUM_THREADS) != 0; } private boolean maxPartialRetriesIsSet() { return (optBits & OPT_BIT_MAX_PARTIAL_RETRIES) != 0; } private boolean partialRetryDelayMillisIsSet() { return (optBits & OPT_BIT_PARTIAL_RETRY_DELAY_MILLIS) != 0; } private boolean queueSizeIsSet() { return (optBits & OPT_BIT_QUEUE_SIZE) != 0; } private boolean shutdownTimeoutIsSet() { return (optBits & OPT_BIT_SHUTDOWN_TIMEOUT) != 0; } private boolean blockingQueueIsSet() { return (optBits & OPT_BIT_BLOCKING_QUEUE) != 0; } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_BULK_OPERATION_FACTORY) != 0) attributes.add("bulkOperationFactory"); return "Cannot build BulkIndexerConfig, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy