private void flushInvalidationMessages( String cacheName, InvalidationEventQueue invalidationMessageQueue) { // If still in progress, no need to another attempt. So just ignore. if (invalidationMessageQueue.tryAcquire()) { try { CacheBatchInvalidationMessage batchInvalidationMessage = new CacheBatchInvalidationMessage(cacheName, invalidationMessageQueue.size()); CacheSingleInvalidationMessage invalidationMessage; final int size = invalidationMessageQueue.size(); // At most, poll from the invalidation queue as the current size of the queue before start // to polling. // So skip new invalidation queue items offered while the polling in progress in this round. for (int i = 0; i < size; i++) { invalidationMessage = invalidationMessageQueue.poll(); if (invalidationMessage == null) { break; } batchInvalidationMessage.addInvalidationMessage(invalidationMessage); } EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName); if (!registrations.isEmpty()) { eventService.publishEvent( ICacheService.SERVICE_NAME, registrations, batchInvalidationMessage, cacheName.hashCode()); } } finally { invalidationMessageQueue.release(); } } }