Source:
<code>public synchronized void sendNotification(final T notification) { final SendableApnsPushNotification<T> sendableNotification = new SendableApnsPushNotification<T>(notification, this.sequenceNumber.getAndIncrement()); final ApnsConnection<T> apnsConnection = this; if (this.channel == null) { throw new IllegalStateException(String.format("%s has not connected.", this.name)); } log.trace("{} sending {}", apnsConnection.name, sendableNotification); this.pendingOperationLock.lock(); try { this.pendingOperationCount += 1; this.channel.writeAndFlush(sendableNotification).addListener(new GenericFutureListener<ChannelFuture>() { public void operationComplete(final ChannelFuture writeFuture) { if (writeFuture.isSuccess()) { log.trace("{} successfully wrote notification {}", apnsConnection.name, sendableNotification.getSequenceNumber()); <START> apnsConnection.sentNotificationBuffer.addSentNotification(sendableNotification); <END> } else { log.trace("{} failed to write notification {}", apnsConnection.name, sendableNotification, writeFuture.cause()); apnsConnection.listener.handleWriteFailure(apnsConnection, notification, writeFuture.cause()); } apnsConnection.pendingOperationLock.lock(); try { apnsConnection.pendingOperationCount -= 1; if (apnsConnection.pendingOperationCount == 0) { apnsConnection.pendingOperationsFinished.signalAll(); } } finally { apnsConnection.pendingOperationLock.unlock(); } } }); } finally { this.pendingOperationLock.unlock(); } }</code><technical_language>out isTraceEnabled() checks? Do check for elsewhere, decided write traces</technical_language>

Target:
public void sendNotification(final T notification) { final ApnsConnection<T> apnsConnection = this; if (this.channel == null) { throw new IllegalStateException(String.format("%s has not connected.", this.name)); } this.channel.eventLoop().execute(new Runnable() { public void run() { final SendableApnsPushNotification<T> sendableNotification = new SendableApnsPushNotification<T>(notification, apnsConnection.sequenceNumber++); log.trace("{} sending {}", apnsConnection.name, sendableNotification); apnsConnection.pendingWriteCount += 1; apnsConnection.channel.writeAndFlush(sendableNotification).addListener(new GenericFutureListener<ChannelFuture>() { public void operationComplete(final ChannelFuture writeFuture) { if (writeFuture.isSuccess()) { log.trace("{} successfully wrote notification {}", apnsConnection.name, sendableNotification.getSequenceNumber()); if (apnsConnection.rejectionReceived) { apnsConnection.listener.handleUnprocessedNotifications(apnsConnection, java.util.Collections.singletonList(notification)); } else { apnsConnection.sentNotificationBuffer.addSentNotification(sendableNotification); } } else { log.trace("{} failed to write notification {}", apnsConnection.name, sendableNotification, writeFuture.cause()); apnsConnection.listener.handleWriteFailure(apnsConnection, notification, writeFuture.cause()); } apnsConnection.pendingWriteCount -= 1; assert apnsConnection.pendingWriteCount >= 0; if (apnsConnection.pendingWriteCount == 0) { synchronized (apnsConnection.pendingWriteMonitor) { apnsConnection.pendingWriteMonitor.notifyAll(); } } } }); } }); }