private Packet queuePacket ( ProtocolHeader header , Protocol protocol , ProtocolCallback cb , Object context , ServiceDirectoryFuture future , WatcherRegistration wr ) { Packet packet = new Packet ( header , protocol , wr ) ; PacketLatency . initPacket ( packet ) ; header . createTime = packet . createTime ; packet . cb = cb ; packet . context = context ; packet . future = future ; if ( ! clientSocket . isConnected ( ) || closing ) { onLossPacket ( packet ) ; } else { synchronized ( pendingQueue ) { if ( LOGGER . isTraceEnabled ( ) ) { LOGGER . trace ( "Add the packet in queuePacket, type=" + header . getType ( ) ) ; } header . setXid ( xid . incrementAndGet ( ) ) ; try { PacketLatency . queuePacket ( packet ) ; clientSocket . sendPacket ( header , protocol ) ; pendingQueue . add ( packet ) ; PacketLatency . sendPacket ( packet ) ; } catch ( IOException e ) { LOGGER . error ( "ClientSocket send packet failed." ) ; if ( LOGGER . isTraceEnabled ( ) ) { LOGGER . trace ( "ClientSocket send packet failed." , e ) ; } if ( packet != null ) { onLossPacket ( packet ) ; } } } } return packet ; }
Queue the Packet to Connection .