@Override
public void sendPacket(Packet packet) {
checkNotNull(packet, "packet");
while (true) {
Transport transport = currentTransport.get();
if (transport == null) {
if (packet.isVolatile()) {
log.debug("Volatile packet dropped. packet={}", packet);
return;
}
synchronized (queueMutex) {
transport = currentTransport.get();
if (transport == null) {
if (packetQueue.offer(packet)) {
log.trace("Packet successfully queued. packet={}", packet);
} else {
log.warn("Packet dropped from queue: {}", packet);
}
return;
}
}
}
if (transport.dispatch(packet)) {
log.trace("Packet successfully dispatched. packet={}", packet);
return;
}
log.debug("Transport failed to dispatch packet. transport={}", transport);