if (debug()) { String m = MessageUtils.toShortString (paam); log.debug ("PureAckAckSender: " +m+ " timeLeft="+timeLeft); }
  public void run()   {    int len;    while (true)     {      //  Wait until we have some new messages or we have timed out to       //  re-examine old messages.      synchronized (queue)       {        while (true)        {          //  Check for new messages before waiting.  They can come          //  in during waiting or during queue processing.          if (haveNewMessages)          {            haveNewMessages = false;            if (queue.size() > 0) break;          }          //  Check how long to wait before we need to satisfy a send deadline          long waitTime = 0;  // 0 = wait till notify (or interrupt)          if (queue.size() > 0)          {            waitTime = minSendDeadline - now();            if (waitTime <= 0) break;          }          //  Wait until timeout, notify, or interrupt          // System.err.println ("\nPureAckAckSender: WAIT waitTime= "+waitTime);          try { queue.wait (waitTime); } catch (Exception e) {}          // System.err.println ("\nPureAckAckSender: RUN");        }        messages = (PureAckAckMessage[]) queue.toArray (messages);  // try array reuse        len = queue.size();//System.err.println ("PureAckAckSender: len="+len);      }      //  Check if it is time to send a pure ack-ack message      minSendDeadline = Long.MAX_VALUE;      for (int i=0; i<len; i++)      {        PureAckAckMessage paam = messages[i];//System.err.println ("PureAckAckSender: msg="+MessageUtils.toString(paam));        PureAckAck pureAckAck = (PureAckAck) MessageUtils.getAck (paam);        String node = MessageUtils.getToAgentNode (paam);        long lastSendTime = MessageAckingAspect.getLastSendTime (node);        //  We sent at most one ack-ack, and then only if there has        //  not been any traffic back to the sending node since the        //  time we received a pure ack from it.        if (lastSendTime < pureAckAck.getReceiveTime())        {          long sendDeadline = pureAckAck.getSendDeadline();          long timeLeft = sendDeadline - now();// String m = MessageUtils.toShortString (paam);// System.err.println ("PureAckAckSender: "+m+": timeLeft="+timeLeft);          if (timeLeft <= 0)          {            //  Time to send the ack-ack// System.err.println ("PureAckAckSender: Launching " +paam);            remove (paam);  // remove first to avoid race condition with send            MessageSender.sendMsg (paam);          }          else           {            if (sendDeadline < minSendDeadline) minSendDeadline = sendDeadline;          }        }        else        {//System.err.println ("PureAckAckSender: removing " +paam);          remove (paam);  // done sending this pure ack-ack message        }      }      Arrays.fill (messages, null);  // release references    }  }