public abstract class AbstractBatch extends Object implements Runnable
onFlushFailure(BatchEntry[]).| Modifier and Type | Field and Description |
|---|---|
protected int |
batch
The batch at the present moment.
|
protected Optional<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 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 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,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown)
Creates a new instance of
AbstractBatch. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown)
Creates a new instance of
AbstractBatch. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
BatchListener batchListener)
Creates a new instance of
AbstractBatch with a BatchListener. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
BatchListener batchListener,
int maxFlushRetries,
long flushRetryDelay)
Creates a new instance of
AbstractBatch with a BatchListener. |
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
FailureListener failureListener)
Deprecated.
|
protected |
AbstractBatch(DatabaseEngine de,
String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
FailureListener failureListener,
int maxFlushRetries,
long flushRetryDelay)
Deprecated.
|
| 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.
|
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.
|
protected final org.slf4j.Logger logger
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 Optional<BatchListener> batchListener
protected final int maxFlushRetries
Defaults to 0.
protected final long flushRetryDelay
Defaults to 300L.
protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, @Nullable BatchListener batchListener, int maxFlushRetries, long flushRetryDelay)
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.protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, @Nullable BatchListener batchListener)
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, String, int, long, long, BatchListener, int, long) 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, String, int, long, long, BatchListener) 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.protected AbstractBatch(DatabaseEngine de, String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown)
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.protected AbstractBatch(DatabaseEngine de, int batchSize, long batchTimeout, long maxAwaitTimeShutdown)
AbstractBatch.de - The database engine.batchSize - The batch size.batchTimeout - The batch timeout.protected void start()
public void destroy()
public void add(BatchEntry batchEntry) throws DatabaseEngineException
batchEntry - The batch entry.DatabaseEngineException - If an error with the database occurs.public void add(String entityName, EntityEntry ee) throws DatabaseEngineException
entityName - The table name.ee - The entity entry.DatabaseEngineException - If an error with the database occurs.public void flush()
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()).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 © 2021 Feedzai. All rights reserved.