public Response waitForResponse(long timeout) throws InterruptedException {
  long before=System.currentTimeMillis();
  long expired=timeout > 0 ? (before + timeout) : 0;
synchronized (this) {
    if (lock == null) {
      lock=new Object();
    }
  }
synchronized (lock) {
    while (this.response == null && !isCanceled() && !isTimedOut() && !isRejected()) {
      lock.wait(timeout);
      long now=System.currentTimeMillis();
      if (timeout > 0 && expired <= now) {
        break;
      }
    }
    Response r=this.response;
    this.response=null;
    return r;
  }
}

public Response waitForResponse ( long timeout ) throws InterruptedException { long before = System . currentTimeMillis ( ) ; long expired = timeout > 0 ? ( before + timeout ) : 0 ; synchronized ( this ) { if ( lock == null ) { lock = new Object ( ) ; } } synchronized ( lock ) { while ( this . response == null && ! isCanceled ( ) && ! isTimedOut ( ) && ! isRejected ( ) ) { lock . wait ( timeout ) ; long now = System . currentTimeMillis ( ) ; if ( timeout > 0 && expired <= now ) { break ; } } Response r = this . response ; this . response = null ; return r ; } }
waits for the arrival of the response to this request . < p > this function blocks until there is a response , the request has been canceled or the specified timeout has expired . a timeout of 0 is interpreted as infinity . if a response is already here , this method returns it immediately . < p > the calling thread returns if either a response arrives , the request gets rejected by the server , the request gets canceled or , in case of a confirmable request , timeouts . in that case , if no response has arrived yet the return value is null . < p > this method also sets the response to null so that succeeding calls will wait for the next response . repeatedly calling this method is useful if the client expects multiple responses , e . g . , multiple notifications to an observe request or multiple responses to a multicast request .
