public abstract class AbstractLogWriter<ConfigType extends AbstractWriterConfig<ConfigType>,StatsType extends AbstractWriterStatistics> extends Object implements LogWriter
| Modifier and Type | Field and Description |
|---|---|
protected ConfigType |
config |
protected InternalLogger |
logger |
protected StatsType |
stats |
| Constructor and Description |
|---|
AbstractLogWriter(ConfigType config,
StatsType appenderStats,
InternalLogger logger) |
| Modifier and Type | Method and Description |
|---|---|
void |
addMessage(LogMessage message)
Adds a message to the writer's message queue.
|
protected List<LogMessage> |
buildBatch(long waitUntil)
Attempts to read a list of messages from the queue.
|
protected abstract int |
effectiveSize(LogMessage message)
Calculates the effective size of the message.
|
protected abstract boolean |
ensureDestinationAvailable()
Verifies that the logging destination is available (which may involve
creating it).
|
int |
getBatchCount()
Returns the number of batches processed.
|
long |
getBatchDelay()
Returns the current batch delay.
|
protected boolean |
initialize()
Called before the main loop, to ensure that the writer is able to perform
its job.
|
boolean |
isRunning()
Returns whether or not the writer is currently running.
|
boolean |
isSynchronous()
Returns a flag to indicate whether the writer is operating in synchrnous mode.
|
protected boolean |
keepRunning()
A check for whether we should keep running: either we haven't been shut
down or there's still messages to process
|
protected void |
processBatch(long waitUntil)
Called from the main loop to build a batch of messages and send them.
|
protected void |
reportError(String message,
Throwable exception)
Reports an operational error to both the internal logger and the stats
bean.
|
void |
run() |
protected abstract List<LogMessage> |
sendBatch(List<LogMessage> currentBatch)
Sends a batch of messages.
|
void |
setBatchDelay(long value)
Sets the batch delay for the writer.
|
void |
setDiscardAction(MessageQueue.DiscardAction value)
Updates the writer's discard action: how it discards messages once the threshold
has been reached.
|
void |
setDiscardThreshold(int value)
Updates the writer's discard threshold: the maximum number of message stored
in its queue.
|
void |
stop()
Signals the writer that it will no longer receive batches.
|
protected abstract void |
stopAWSClient()
This is called when the logwriter is stopped, to explicitly close the
AWS service client.
|
boolean |
waitUntilInitialized(long millisToWait)
Waits up to the specified amount of time for the writer to initialize.
|
void |
waitUntilStopped(long millisToWait)
Waits until the writer thread has stopped, the timeout has expired, or the
calling thread is interrupted.
|
protected abstract boolean |
withinServiceLimits(int batchBytes,
int numMessages)
Determines whether the provided batch size or number of messages would
exceed the service's limits.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmaxMessageSizeprotected ConfigType extends AbstractWriterConfig<ConfigType> config
protected StatsType extends AbstractWriterStatistics stats
protected InternalLogger logger
public AbstractLogWriter(ConfigType config, StatsType appenderStats, InternalLogger logger)
public boolean isRunning()
public long getBatchDelay()
public int getBatchCount()
public void setBatchDelay(long value)
LogWriterThis is a no-op if the writer doesn't support batching or is in synchronous mode.
setBatchDelay in interface LogWriterpublic void setDiscardThreshold(int value)
LogWritersetDiscardThreshold in interface LogWriterpublic void setDiscardAction(MessageQueue.DiscardAction value)
LogWritersetDiscardAction in interface LogWriterpublic boolean isSynchronous()
LogWriterisSynchronous in interface LogWriterpublic boolean waitUntilInitialized(long millisToWait)
LogWriterwaitUntilInitialized in interface LogWritertrue if it initialized successfully, false
if writer failed to initialize, the timeout expired, or the calling
thread was interrupted.public void addMessage(LogMessage message)
LogWriterImplementations should assume that they are invoked within a synchronized block, and therefore should not perform excessive amounts work (synchronous mode being an exception).
addMessage in interface LogWriterpublic void stop()
LogWriterrun() method.public void waitUntilStopped(long millisToWait)
LogWriterwaitUntilStopped in interface LogWriterprotected boolean keepRunning()
protected boolean initialize()
protected void processBatch(long waitUntil)
sendBatch(java.util.List<com.kdgregory.logging.common.LogMessage>).
It's necessary to synchronize this method to support synchronous mode. In normal threaded mode it the lock will always be uncontended.
protected List<LogMessage> buildBatch(long waitUntil)
For each message, the subclass is called to determine the effective size of the message, and whether the aggregate batch size is within the range accepted by the service.
protected abstract boolean ensureDestinationAvailable()
true if successful, false
if not (which will cause the appender to stop running).protected abstract List<LogMessage> sendBatch(List<LogMessage> currentBatch)
protected abstract int effectiveSize(LogMessage message)
protected abstract boolean withinServiceLimits(int batchBytes,
int numMessages)
protected abstract void stopAWSClient()
Copyright © 2023. All rights reserved.