Source:
<code>public synchronized EnqueueResult enqueue(T message, String key) throws WriteFailedException { Map.Entry<String, T> msgEntry = new AbstractMap.SimpleImmutableEntry<>(key, message); <START> LOG.debug("Attempting to enqueue with key into queue with current size {}", message, key, getSize()); <END> if (offHeapQueue == null) { LOG.trace("Enqueueing with key in-memory since there is no off-heap queue " + "configured", message, key); try { inMemoryQueue.put(msgEntry); } catch (InterruptedException e) { throw new WriteFailedException(e); } return EnqueueResult.IMMEDIATE; } int size = 0; byte[] serializedBatch = null; synchronized (offHeapMutex) { if (offHeapQueue.size() <= 0 && batch.isEmpty()) { boolean inMemoryQueueHadSpace = inMemoryQueue.offer(msgEntry); if (inMemoryQueueHadSpace) { LOG.trace("Enqueueing with key in-memory", message, key); return EnqueueResult.IMMEDIATE; } } LOG.trace("Batching message with key for off-heap queue", message, key); batch.add(message); if (batch.isFull()) { LOG.trace("Flushing batch off-heap"); try { serializedBatch = batch.toSerializedBatchAndClear(); } catch (Exception e) { RATE_LIMITED_LOGGER.warn("Failed to flush to off-heap", e); throw new WriteFailedException(e); } size = serializedBatch.length + SERIALIZED_OBJECT_HEADER_SIZE_IN_BYTES; fileCapacityLatch.markFlushNeeded(); } } if (serializedBatch != null) { try { fileCapacityLatch.waitForCapacity(size); synchronized (offHeapMutex) { if (!fileCapacityLatch.isFlushNeeded()) { return EnqueueResult.DEFERRED; } try { offHeapQueue.add(serializedBatch); checkFileSize(); } catch (IOException e) { throw new WriteFailedException(e); } } } catch (InterruptedException e) { throw new WriteFailedException(e); } } return EnqueueResult.DEFERRED; }</code><technical_language>This LOG.trace remove message log if want in debug</technical_language>

Target:
public EnqueueResult enqueue(T message, String key) throws WriteFailedException { enqueueLock.lock(); try { Map.Entry<String, T> msgEntry = new AbstractMap.SimpleImmutableEntry<>(key, message); LOG.trace("Attempting to enqueue with key into queue with current size {}", message, key, getSize()); if (offHeapQueue == null) { LOG.trace("Enqueueing with key in-memory since there is no off-heap queue " + "configured", message, key); try { inMemoryQueue.put(msgEntry); } catch (InterruptedException e) { throw new WriteFailedException(e); } return EnqueueResult.IMMEDIATE; } int size = 0; byte[] serializedBatch = null; offHeapLock.lock(); try { if (offHeapQueue.size() <= 0 && batch.isEmpty()) { boolean inMemoryQueueHadSpace = inMemoryQueue.offer(msgEntry); if (inMemoryQueueHadSpace) { LOG.trace("Enqueueing with key in-memory", message, key); return EnqueueResult.IMMEDIATE; } } LOG.trace("Batching message with key for off-heap queue", message, key); batch.add(message); if (batch.isFull()) { LOG.trace("Flushing batch off-heap"); try { serializedBatch = batch.toSerializedBatchAndClear(); } catch (Exception e) { RATE_LIMITED_LOGGER.warn("Failed to flush to off-heap", e); throw new WriteFailedException(e); } size = serializedBatch.length + SERIALIZED_OBJECT_HEADER_SIZE_IN_BYTES; fileCapacityLatch.markFlushNeeded(); } } finally { offHeapLock.unlock(); } if (serializedBatch != null) { try { fileCapacityLatch.waitForCapacity(size); offHeapLock.lock(); try { if (!fileCapacityLatch.isFlushNeeded()) { return EnqueueResult.DEFERRED; } try { offHeapQueue.add(serializedBatch); checkFileSize(); } catch (IOException e) { throw new WriteFailedException(e); } } finally { offHeapLock.unlock(); } } catch (InterruptedException e) { throw new WriteFailedException(e); } } return EnqueueResult.DEFERRED; } finally { enqueueLock.unlock(); } }