public abstract class AbstractBatch
extends java.lang.Object
implements java.lang.Runnable
onFlushFailure(BatchEntry[]).| Modifier and Type | Field and Description |
|---|---|
protected int |
batch
The batch at the present moment.
|
protected int |
batchSize
The batchSize.
|
protected long |
batchTimeout
The batch timeout.
|
protected java.util.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 java.util.Optional<FailureListener> |
failureListener
The failure listener for customized behavior when this batch fails to persist data.
|
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 java.lang.String |
name
The name of the batch.
|
static FailureListener |
NO_OP
Constant
FailureListener representing the NO OP operation. |
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 java.util.concurrent.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,
java.lang.String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown)
Creates a new instance of
AbstractBatch. |
protected |
AbstractBatch(DatabaseEngine de,
java.lang.String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
FailureListener failureListener)
Creates a new instance of
AbstractBatch with a FailureListener. |
protected |
AbstractBatch(DatabaseEngine de,
java.lang.String name,
int batchSize,
long batchTimeout,
long maxAwaitTimeShutdown,
FailureListener failureListener,
int maxFlushRetries,
long flushRetryDelay)
Creates a new instance of
AbstractBatch with a FailureListener. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(BatchEntry batchEntry)
Adds the fields to the batch.
|
void |
add(java.lang.String entityName,
EntityEntry ee)
Adds the fields to the batch.
|
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 |
run() |
protected void |
start()
Starts the timer task.
|
protected final org.slf4j.Logger logger
public static final FailureListener NO_OP
FailureListener representing the NO OP operation.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 java.util.concurrent.ScheduledExecutorService scheduler
protected final int batchSize
protected final long batchTimeout
protected int batch
protected volatile long lastFlush
protected java.util.LinkedList<BatchEntry> buffer
protected java.lang.String name
protected java.util.Optional<FailureListener> failureListener
protected final int maxFlushRetries
Defaults to 0.
protected final long flushRetryDelay
Defaults to 300L.
protected AbstractBatch(DatabaseEngine de, java.lang.String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, FailureListener failureListener, int maxFlushRetries, long flushRetryDelay)
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.protected AbstractBatch(DatabaseEngine de, java.lang.String name, int batchSize, long batchTimeout, long maxAwaitTimeShutdown, FailureListener failureListener)
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, java.lang.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(java.lang.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 is true it waits for other pending flush operations.
If is false it can return directly if the buffer if the batch is empty.
sync - true if it should wait for other flush() operations.public void onFlushFailure(BatchEntry[] entries)
entries - The entries that are pending to be persisted.public void run()
run in interface java.lang.RunnableCopyright © 2018 Feedzai. All Rights Reserved.