@Override public void run() { logger.log(Level.FINER, "Sending messages based on schedule."); activeAlarm.getAndSet(false); publishAllOutstanding(); } },
/** * Schedules immediate publishing of any outstanding messages and waits until all are processed. * * <p>Sends remaining outstanding messages and prevents future calls to publish. This method * should be invoked prior to deleting the {@link Publisher} object in order to ensure that no * pending messages are lost. */ public void shutdown() throws Exception { if (shutdown.getAndSet(true)) { throw new IllegalStateException("Cannot shut down a publisher already shut-down."); } if (currentAlarmFuture != null && activeAlarm.getAndSet(false)) { currentAlarmFuture.cancel(false); } publishAllOutstanding(); messagesWaiter.waitNoMessages(); for (AutoCloseable closeable : closeables) { closeable.close(); } publisherStub.shutdown(); }