public abstract class AbstractBatch extends AbstractPdbBatch implements Runnable, PdbBatch
onFlushFailure(BatchEntry[]).| Modifier and Type | Field and Description |
|---|---|
protected int |
batch
The batch at the present moment.
|
protected BatchListener |
batchListener
The listener for customized behavior when this batch succeeds or fails to persist data.
|
protected int |
batchSize
The batchSize.
|
protected long |
batchTimeout
The batch timeout.
|
protected LinkedList<BatchEntry> |
buffer
EntityEntry buffer.
|
protected org.slf4j.Logger |
confidentialLogger
The confidential logger.
|
protected DatabaseEngine |
de
The database engine.
|
static long |
DEFAULT_RETRY_INTERVAL
Constant representing the default time interval (milliseconds) to wait between batch flush retries.
|
protected static org.slf4j.Marker |
dev
The dev Marker.
|
protected long |
flushRetryDelay
The time interval (milliseconds) to wait between batch flush retries.
|
protected long |
lastFlush
Timestamp of the last flush.
|
protected static org.slf4j.Logger |
logger
The logger.
|
protected long |
maxAwaitTimeShutdown
The maximum await time to wait for the batch to shutdown.
|
protected int |
maxFlushRetries
The number of times to retry a batch flush upon failure.
|
protected String |
name
The name of the batch.
|
static int |
NO_RETRY
Constant representing that no retries should be attempted on batch flush failures.
|
protected static int |
salt
Salt to avoid erroneous flushes.
|
protected ScheduledExecutorService |
scheduler
The Timer that runs this task.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractBatch(DatabaseEngine de,
BatchConfig<?> config)
Creates a new instance of
AbstractBatch. |
protected |
AbstractBatch(DatabaseEngine de,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
BatchListener batchListener)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
BatchListener batchListener,
int maxFlushRetries,
long flushRetryDelay)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
BatchListener batchListener,
int maxFlushRetries,
long flushRetryDelay,
org.slf4j.Logger confidentialLogger)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
FailureListener failureListener)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
FailureListener failureListener,
int maxFlushRetries,
long flushRetryDelay)
Deprecated.
Use
AbstractBatch(DatabaseEngine, BatchConfig) instead. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(BatchEntry batchEntry)
Adds the fields to the batch.
|
void |
add(String entityName,
EntityEntry ee)
Adds the fields to the batch.
|
void |
close() |
static BatchListener |
convertToBatchListener(FailureListener failureListener)
Deprecated.
The
FailureListener is deprecated and this method will be removed once it is removed. |
void |
destroy()
Destroys this batch.
|
void |
flush()
Flushes the pending batches.
|
void |
flush(boolean sync)
Flushes the pending messages.
|
void |
onFlushFailure(BatchEntry[] entries)
Notifies about the pending entries on flush failure.
|
void |
onFlushSuccess(BatchEntry[] entries)
Notifies about succeeded entries on flush success.
|
void |
run() |
protected void |
start()
Starts the timer task.
|
flushAsync, processBatchclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitflushAsyncprotected static final org.slf4j.Logger logger
protected final org.slf4j.Logger confidentialLogger
public static final int NO_RETRY
public static final long DEFAULT_RETRY_INTERVAL
protected static final org.slf4j.Marker dev
protected static final int salt
protected final DatabaseEngine de
protected final long maxAwaitTimeShutdown
protected ScheduledExecutorService scheduler
protected final int batchSize
protected final long batchTimeout
protected int batch
protected volatile long lastFlush
protected LinkedList<BatchEntry> buffer
protected String name
protected BatchListener batchListener
protected final int maxFlushRetries
Defaults to 0.
protected final long flushRetryDelay
Defaults to 300L.
protected AbstractBatch(DatabaseEngine de, BatchConfig<?> config)
AbstractBatch.de - The database engine.config - The batch configuration.@Deprecated protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, @Nullable BatchListener batchListener, int maxFlushRetries, long flushRetryDelay, @Nullable org.slf4j.Logger confidentialLogger)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch with a BatchListener.de - The database engine.name - The batch name (null or empty names are allowed, falling back to "Anonymous Batch").batchSize - The batch size.batchTimeout - The batch timeout.maxAwaitTimeShutdown - The maximum await time for the batch to shutdown.batchListener - The listener that will be invoked whenever some batch operation fail or succeeds to persist.maxFlushRetries - The number of times to retry a batch flush upon failure. When set to 0, no retries
will be attempted.flushRetryDelay - The time interval (milliseconds) to wait between batch flush retries.confidentialLogger - The confidential logger.@Deprecated protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, @Nullable BatchListener batchListener, int maxFlushRetries, long flushRetryDelay)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch with a BatchListener.de - The database engine.name - The batch name (null or empty names are allowed, falling back to "Anonymous Batch").batchSize - The batch size.batchTimeout - The batch timeout.maxAwaitTimeShutdown - The maximum await time for the batch to shutdown.batchListener - The listener that will be invoked whenever some batch operation fail or succeeds to persist.maxFlushRetries - The number of times to retry a batch flush upon failure. When set to 0, no retries
will be attempted.flushRetryDelay - The time interval (milliseconds) to wait between batch flush retries.@Deprecated protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, @Nullable BatchListener batchListener)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch with a BatchListener.de - The database engine.name - The batch name (null or empty names are allowed, falling back to "Anonymous Batch").batchSize - The batch size.batchTimeout - The batch timeout.maxAwaitTimeShutdown - The maximum await time for the batch to shutdown.batchListener - The listener that will be invoked whenever some batch operation fail or succeeds to persist.@Deprecated protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, FailureListener failureListener, int maxFlushRetries, long flushRetryDelay)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch with a FailureListener.de - The database engine.name - The batch name (null or empty names are allowed, falling back to "Anonymous Batch").batchSize - The batch size.batchTimeout - The batch timeout.maxAwaitTimeShutdown - The maximum await time for the batch to shutdown.failureListener - The listener that will be invoked whenever some batch operation fail to persist.maxFlushRetries - The number of times to retry a batch flush upon failure. When set to 0, no retries
will be attempted.flushRetryDelay - The time interval (milliseconds) to wait between batch flush retries.@Deprecated protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, FailureListener failureListener)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch with a FailureListener.de - The database engine.name - The batch name (null or empty names are allowed, falling back to "Anonymous Batch").batchSize - The batch size.batchTimeout - The batch timeout.maxAwaitTimeShutdown - The maximum await time for the batch to shutdown.failureListener - The listener that will be invoked whenever some batch operation fail to persist.@Deprecated protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch.de - The database engine.name - The batch name (null or empty names are allowed, falling back to "Anonymous Batch").batchSize - The batch size.batchTimeout - The batch timeout.maxAwaitTimeShutdown - The maximum await time for the batch to shutdown.@Deprecated protected AbstractBatch(DatabaseEngine de, int batchSize, long batchTimeout, long maxAwaitTimeShutdown)
AbstractBatch(DatabaseEngine, BatchConfig) instead.AbstractBatch.de - The database engine.batchSize - The batch size.batchTimeout - The batch timeout.protected void start()
public void close()
throws Exception
close in interface AutoCloseableExceptionpublic void destroy()
public void add(BatchEntry batchEntry) throws DatabaseEngineException
add in interface PdbBatchbatchEntry - The batch entry.DatabaseEngineException - If an error with the database occurs.public void add(String entityName, EntityEntry ee) throws DatabaseEngineException
add in interface PdbBatchadd in class AbstractPdbBatchentityName - The table name.ee - The entity entry.DatabaseEngineException - If an error with the database occurs.public void flush()
flush in interface PdbBatchflush(boolean) with false.public void flush(boolean sync)
If sync is true it waits for other pending flush operations.
If it is false it can return directly if the buffer in the batch is empty.
sync - true if it should wait for other flush operations (from here, or those started by calling
flush()).flushTransactionLock before a non synchronous one, leading to a non serial execution.
Since the flushes on the DB connection are also guarded by the same flushTransactionLock, the result is
that if the batch is not empty, the thread calling this method will wait for an ongoing flush either before or
after draining the batch buffer to a local temporary buffer (respectively, when sync is true or
false).
If the batch is empty, then the thread calling this method will either wait for an ongoing flush or it will
return from the method, depending on whether sync is true or false, respectively.
public void onFlushFailure(BatchEntry[] entries)
entries - The entries that are pending to be persisted.public void onFlushSuccess(BatchEntry[] entries)
entries - The entries that were persisted.public static BatchListener convertToBatchListener(FailureListener failureListener)
FailureListener is deprecated and this method will be removed once it is removed.FailureListener to BatchListener.failureListener - The FailureListener to be converted.BatchListener that calls a FailureListener on failure.Copyright © 2023 Feedzai. All rights reserved.