library/src/main/java/com/kdgregory/aws/utils/cloudwatch/CloudWatchLogsWriter.java
/**
     *  Flush outstanding messages. Will build and send batches until the queue
     *  is empty or an uncrecoverable error occurs.
     */
Flush outstanding messages. Will build and send batches until the queue
is empty or an uncrecoverable error occurs.
Flush outstanding messages . Will build and send batches until the queue is empty or an uncrecoverable error occurs .
public synchronized void flush()
    {
        flushCount.incrementAndGet();
        lastFlushTimestamp.set(System.currentTimeMillis());
        LinkedList<QueuedMessage> messages = extractAndSortMessages();
        if (messages.isEmpty())
            return;
        try
        {
            String uploadSequenceToken = retrieveUploadSequenceToken();
            while (messages.size() > 0)
            {
                List<QueuedMessage> batch = extractBatch(messages);
                try
                {
                    uploadSequenceToken = attemptToSend(batch, uploadSequenceToken);
                    batch.clear();
                }
                catch (DataAlreadyAcceptedException ex)
                {
                    logger.warn("DataAlreadyAcceptedException: discarded " + batch.size()
                                + " to stream: " + logGroupName + "/" + logStreamName);
                    batch.clear();
                }
                catch (InvalidSequenceTokenException ex)
                {
                    invalidSequenceCount.incrementAndGet();
                    uploadSequenceToken = retrieveUploadSequenceToken();
                }
                finally
                {
                    messages.addAll(0, batch);
                }
            }
        }
        catch (Exception ex)
        {
            logger.warn(ex.getClass().getSimpleName() + " writing to stream: "
                        + logGroupName + "/" + logStreamName);
        }
        finally
        {
            unsentMessages.addAll(messages);
        }
    }
public synchronized void flush ( ) { flushCount . incrementAndGet ( ) ; lastFlushTimestamp . set ( System . currentTimeMillis ( ) ) ; LinkedList < QueuedMessage > messages = extractAndSortMessages ( ) ; if ( messages . isEmpty ( ) ) return ; try { String uploadSequenceToken = retrieveUploadSequenceToken ( ) ; while ( messages . size ( ) > 0 ) { List < QueuedMessage > batch = extractBatch ( messages ) ; try { uploadSequenceToken = attemptToSend ( batch , uploadSequenceToken ) ; batch . clear ( ) ; } catch ( DataAlreadyAcceptedException ex ) { logger . warn ( "DataAlreadyAcceptedException: discarded " + batch . size ( ) + " to stream: " + logGroupName + "/" + logStreamName ) ; batch . clear ( ) ; } catch ( InvalidSequenceTokenException ex ) { invalidSequenceCount . incrementAndGet ( ) ; uploadSequenceToken = retrieveUploadSequenceToken ( ) ; } finally { messages . addAll ( 0 , batch ) ; } } } catch ( Exception ex ) { logger . warn ( ex . getClass ( ) . getSimpleName ( ) + " writing to stream: " + logGroupName + "/" + logStreamName ) ; } finally { unsentMessages . addAll ( messages ) ; } }
Flush outstanding messages.
Flush outstanding messages .
// in normal operation this shouldn't happen, so it's worth a warning // the batch will be empty unless there was an exception // this catches unexpected exceptions, which are allowed to break out of the writer loop // it's worth logging, but I don't think a long stack trace will help anyone