@Override public void doAppend( final LogEventPack logEventPack, final RecordHeader header, final LogDeliveryCallback listener) { if (!closed) { if (executor == null || callbackExecutor == null || flumeClientManager == null) { reinit(); } if (executor == null || callbackExecutor == null || flumeClientManager == null) { LOG.warn("Some of components haven't been initialized. Skipping append method"); listener.onInternalError(); return; } executor.submit( new Runnable() { @Override public void run() { try { List<Event> events = flumeEventBuilder.generateEvents(logEventPack, header, getApplicationToken()); try { if (events != null && !events.isEmpty()) { if (flumeClientManager != null) { int logCount = events.size(); inputLogCount.getAndAdd(logCount); ListenableFuture<AppendBatchAsyncResultPojo> result = flumeClientManager.sendEventsToFlumeAsync(events); Futures.addCallback( result, new Callback( listener, flumeSuccessLogCount, flumeFailureLogCount, logCount), callbackExecutor); LOG.debug("Appended {} logs to flume", logEventPack.getEvents().size()); } else { LOG.warn("Flume client wasn't initialized. Invoke method init before."); listener.onInternalError(); } } else { LOG.warn("Unable to generate Flume events from log event pack!"); listener.onInternalError(); } } catch (EventDeliveryException e) { LOG.warn("Can't send flume event. ", e); listener.onConnectionError(); } } catch (Exception e) { LOG.warn("Got exception. Can't process log events", e); listener.onInternalError(); } } }); } else { LOG.info("Attempted to append to closed appender named [{}].", getName()); listener.onInternalError(); } }
@Override public void onFailure(Throwable t) { flumeFailureLogCount.getAndAdd(size); LOG.warn("Failed to store record", t); if (t instanceof IOException) { callback.onConnectionError(); } else if (t instanceof EventDeliveryException) { callback.onRemoteError(); } else { callback.onInternalError(); } }