final static int MAX_DELAY_BETWEEN_STATUS_MESSAGES = 1228800 * CoreConstants.MILLIS_IN_ONE_SECOND; int delayBetweenStatusMessages = 300 * CoreConstants.MILLIS_IN_ONE_SECOND; long lastTrackerStatusPrint = 0; private int errorCount = 0;
String key = discriminator.getDiscriminatingValue(eventObject); long now = System.currentTimeMillis(); final CyclicBuffer cb = cbTracker.getOrCreate(key, now); subAppend(cb, eventObject); try { if (eventEvaluator.evaluate(eventObject)) { // clone the CyclicBuffer before sending out asynchronously CyclicBuffer cbClone = new CyclicBuffer(cb); // see http://jira.qos.ch/browse/LBCLASSIC-221 cb.clear();
if (isAsynchronousSending()) { // perform actual sending asynchronously SenderRunnable senderRunnable = new SenderRunnable(cbClone, eventObject); context.getExecutorService().execute(senderRunnable); } else { // synchronous sending sendBuffer(cbClone, eventObject); } } } catch (EvaluationException ex) { errorCount++; if (errorCount < CoreConstants.MAX_ERROR_COUNT) { addError("SMTPAppender's EventEvaluator threw an Exception-", ex); } }
// immediately remove the buffer if asked by the user if (eventMarksEndOfLife(eventObject)) { cbTracker.endOfLife(key); }
cbTracker.removeStaleComponents(now);
if (lastTrackerStatusPrint + delayBetweenStatusMessages < now) { addInfo("SMTPAppender [" + name + "] is tracking [" + cbTracker.getComponentCount() + "] buffers"); lastTrackerStatusPrint = now; // quadruple 'delay' assuming less than max delay if (delayBetweenStatusMessages < MAX_DELAY_BETWEEN_STATUS_MESSAGES) { delayBetweenStatusMessages *= 4; } } }
// Note: this code already owns the monitor for this // appender. This frees us from needing to synchronize on 'cb'. try { MimeBodyPart part = new MimeBodyPart();
// The subject must not contain new-line characters, which cause // an SMTP error (LOGBACK-865). Truncate the string at the first // new-line character. int newLinePos = (subjectStr != null) ? subjectStr.indexOf('\n') : -1; if (newLinePos > -1) { subjectStr = subjectStr.substring(0, newLinePos); } } mimeMsg.setSubject(subjectStr, charsetEncoding);
List destinationAddresses = parseAddress(lastEventObject); if (destinationAddresses.isEmpty()) { addInfo("Empty destination address. Aborting email transmission"); return; }