Exemplo n.º 1
0
 // Got a response UDP packet, or completed a large TCP answer-receive.
 // Install it as The Answer packet and wake up anybody waiting on an answer.
 protected void response(AutoBuffer ab) {
   assert _tasknum == ab.getTask();
   if (_done) {
     ab.close();
     return;
   } // Ignore duplicate response packet
   int flag = ab.getFlag(); // Must read flag also, to advance ab
   if (flag == SERVER_TCP_SEND) {
     ab.close();
     return;
   } // Ignore UDP packet for a TCP reply
   assert flag == SERVER_UDP_SEND;
   synchronized (this) { // Install the answer under lock
     if (_done) {
       ab.close();
       return;
     } // Ignore duplicate response packet
     _dt.read(ab); // Read the answer (under lock?)
     ab.close(); // Also finish the read (under lock?)
     _dt.onAck(); // One time only execute (before sending ACKACK)
     _done = true;
     UDPTimeOutThread.PENDING.remove(this);
     TASKS.remove(_tasknum); // Flag as task-completed, even if the result is null
     notifyAll(); // And notify in any case
   }
 }
Exemplo n.º 2
0
 // Attempt to cancel job
 public final boolean cancel(boolean mayInterruptIfRunning) {
   boolean did = false;
   synchronized (this) { // Install the answer under lock
     if (!isCancelled()) {
       did = true; // Did cancel (was not canceled already)
       _target = null; // Flag as canceled
       UDPTimeOutThread.PENDING.remove(this);
       TASKS.remove(_tasknum);
     }
     notifyAll(); // notify in any case
   }
   return did;
 }