public abstract class AbstractLogWriter extends Object implements LogWriter
| Constructor and Description |
|---|
AbstractLogWriter(AbstractAppenderStatistics appenderStats,
long batchDelay,
int discardThreshold,
MessageQueue.DiscardAction discardAction) |
| Modifier and Type | Method and Description |
|---|---|
void |
addMessage(LogMessage message)
Adds a message to the writer waiting for batch.
|
protected List<LogMessage> |
buildBatch()
Attempts to read a list of messages from the queue.
|
protected abstract void |
createAWSClient()
Creates the appropriate AWS client.
|
protected abstract int |
effectiveSize(LogMessage message)
Calculates the effective size of the message.
|
protected abstract boolean |
ensureDestinationAvailable()
Verifies that the logging destination is available, including creating
it if not.
|
int |
getBatchCount()
Returns the number of batches processed.
|
long |
getBatchDelay()
Returns the current batch delay.
|
String |
getClientFactoryUsed()
Returns the factory method used to create the client, if any.
|
protected boolean |
initializationFailure(String message,
Exception exception)
Records an initialization failure in the appender stats.
|
boolean |
isInitializationComplete()
Returns a flag indicating that initialization has completed (whether or not
successful).
|
protected abstract List<LogMessage> |
processBatch(List<LogMessage> currentBatch)
Processes a batch of messages.
|
void |
run() |
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 <T> T |
tryClientFactory(String clientFactoryName,
Class<T> expectedClientClass,
boolean rethrow)
Attempts to use a factory method to create the service client.
|
protected <T extends com.amazonaws.AmazonWebServiceClient> |
tryConfigureEndpointOrRegion(T client,
String endpoint)
Common support code: attempts to configure client endpoint and/or region.
|
protected abstract boolean |
withinServiceLimits(int batchBytes,
int numMessages)
Determines whether the provided batch size or number of messages would
exceed the service's limits.
|
public AbstractLogWriter(AbstractAppenderStatistics appenderStats, long batchDelay, int discardThreshold, MessageQueue.DiscardAction discardAction)
public long getBatchDelay()
public int getBatchCount()
public boolean isInitializationComplete()
public String getClientFactoryUsed()
public void addMessage(LogMessage message)
LogWriterImplementations should assume that they are invoked within a synchronized block, and therefore should not perform excessive amounts of work.
addMessage in interface LogWriterpublic void setBatchDelay(long value)
LogWriterIf the writer doesn't support batching, this will be a no-op.
setBatchDelay in interface LogWriterpublic void stop()
LogWriterrun() method.public void setDiscardThreshold(int value)
LogWritersetDiscardThreshold in interface LogWriterpublic void setDiscardAction(MessageQueue.DiscardAction value)
LogWritersetDiscardAction in interface LogWriterprotected abstract void createAWSClient()
protected abstract boolean ensureDestinationAvailable()
true if successful, false
if not (which will cause the appender to stop running).protected abstract List<LogMessage> processBatch(List<LogMessage> currentBatch)
protected abstract int effectiveSize(LogMessage message)
protected abstract boolean withinServiceLimits(int batchBytes,
int numMessages)
protected boolean initializationFailure(String message, Exception exception)
protected List<LogMessage> buildBatch()
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 <T> T tryClientFactory(String clientFactoryName, Class<T> expectedClientClass, boolean rethrow)
clientFactoryName - Fully qualified name of a static factory method.
If empty or null, this function returns null (used
to handle optionally-configured factories).expectedClientClass - The interface fullfilled by this client.rethrow - If true, any reflection exceptions will be wrapped
and rethrown; if false, exceptions return nullprotected <T extends com.amazonaws.AmazonWebServiceClient> T tryConfigureEndpointOrRegion(T client,
String endpoint)
client - A constructed writer-specific service client.endpoint - A possibly-null endpoint specification.Copyright © 2018. All rights reserved.