private String awaitingLogMessage(GracefulShutdownContext context) { long awaitingNotification = context.getNotificationCompleteLatch().getCount(); long awaitingFinalShutdown = context.getShutdownCompleteLatch().getCount(); return String.format( "Waiting for %d record process to complete shutdown notification, and %d record processor to complete final shutdown ", awaitingNotification, awaitingFinalShutdown); }
@Override public Boolean call() throws Exception { GracefulShutdownContext context; try { context = startWorkerShutdown.call(); } catch (Exception ex) { log.warn("Caught exception while requesting initial worker shutdown.", ex); throw ex; } return context.isShutdownAlreadyCompleted() || waitForRecordProcessors(context); } }
while (!context.getNotificationCompleteLatch().await(1, TimeUnit.SECONDS)) { if (Thread.interrupted()) { throw new InterruptedException(); if (workerShutdownWithRemaining(context.getShutdownCompleteLatch().getCount(), context)) { return false; context.getWorker().shutdown(); while (!context.getShutdownCompleteLatch().await(1, TimeUnit.SECONDS)) { if (Thread.interrupted()) { throw new InterruptedException(); if (workerShutdownWithRemaining(context.getShutdownCompleteLatch().getCount(), context)) { return false;
/** * This checks to see if the worker has already hit it's shutdown target, while there is outstanding record * processors. This maybe a little racy due to when the value of outstanding is retrieved. In general though the * latch should be decremented before the shutdown completion. * * @param outstanding * the number of record processor still awaiting shutdown. */ private boolean workerShutdownWithRemaining(long outstanding, GracefulShutdownContext context) { if (isWorkerShutdownComplete(context)) { if (outstanding != 0) { log.info("Shutdown completed, but shutdownCompleteLatch still had outstanding " + outstanding + " with a current value of " + context.getShutdownCompleteLatch().getCount() + ". shutdownComplete: " + context.getWorker().isShutdownComplete() + " -- Consumer Map: " + context.getWorker().getShardInfoShardConsumerMap().size()); return true; } } return false; }
private String awaitingFinalShutdownMessage(GracefulShutdownContext context) { long outstanding = context.getShutdownCompleteLatch().getCount(); return String.format("Waiting for %d record processors to complete final shutdown", outstanding); }
return new GracefulShutdownContext(shutdownCompleteLatch, notificationCompleteLatch, this); };