src/share/classes/com/sun/jndi/ldap/Connection.java

Print this page




 422 
 423         try {
 424             synchronized (this) {
 425                 outStream.write(ber.getBuf(), 0, ber.getDataLen());
 426                 outStream.flush();
 427             }
 428         } catch (IOException e) {
 429             cleanup(null, true);
 430             throw (closureReason = e); // rethrow
 431         }
 432 
 433         return req;
 434     }
 435 
 436     /**
 437      * Reads a reply; waits until one is ready.
 438      */
 439     BerDecoder readReply(LdapRequest ldr)
 440             throws IOException, NamingException {
 441         BerDecoder rber;
 442         boolean waited = false;

 443 
 444         while (((rber = ldr.getReplyBer()) == null) && !waited) {


 445             try {
 446                 // If socket closed, don't even try
 447                 synchronized (this) {
 448                     if (sock == null) {
 449                         throw new ServiceUnavailableException(host + ":" + port +
 450                             "; socket closed");
 451                     }
 452                 }







 453                 synchronized (ldr) {
 454                     // check if condition has changed since our last check
 455                     rber = ldr.getReplyBer();
 456                     if (rber == null) {
 457                         if (readTimeout > 0) {  // Socket read timeout is specified
 458 
 459                             // will be woken up before readTimeout only if reply is
 460                             // available
 461                             ldr.wait(readTimeout);
 462                             waited = true;
 463                         } else {
 464                             ldr.wait(15 * 1000); // 15 second timeout
 465                         }
 466                     } else {
 467                         break;
 468                     }
 469                 }

 470             } catch (InterruptedException ex) {
 471                 throw new InterruptedNamingException(
 472                     "Interrupted during LDAP operation");
 473             }
 474         }
 475 
 476         if ((rber == null) && waited) {
 477             removeRequest(ldr);
 478             throw new NamingException("LDAP response read timed out, timeout used:"
 479                             + readTimeout + "ms." );
 480 
 481         }
 482         return rber;
 483     }
 484 
 485 
 486     ////////////////////////////////////////////////////////////////////////////
 487     //
 488     // Methods to add, find, delete, and abandon requests made to server
 489     //
 490     ////////////////////////////////////////////////////////////////////////////
 491 
 492     private synchronized void addRequest(LdapRequest ldapRequest) {
 493 
 494         LdapRequest ldr = pendingRequests;
 495         if (ldr == null) {
 496             pendingRequests = ldapRequest;




 422 
 423         try {
 424             synchronized (this) {
 425                 outStream.write(ber.getBuf(), 0, ber.getDataLen());
 426                 outStream.flush();
 427             }
 428         } catch (IOException e) {
 429             cleanup(null, true);
 430             throw (closureReason = e); // rethrow
 431         }
 432 
 433         return req;
 434     }
 435 
 436     /**
 437      * Reads a reply; waits until one is ready.
 438      */
 439     BerDecoder readReply(LdapRequest ldr)
 440             throws IOException, NamingException {
 441         BerDecoder rber;
 442         int timeOut = (readTimeout > 0) ?
 443                 readTimeout : 15 * 1000; // Default read timeout of 15 sec
 444 
 445         long startTime = System.currentTimeMillis();
 446 
 447         while (((rber = ldr.getReplyBer()) == null) && timeOut > 0) {
 448             try {
 449                 // If socket closed, don't even try
 450                 synchronized (this) {
 451                     if (sock == null) {
 452                         throw new ServiceUnavailableException(host + ":" + port +
 453                                                               "; socket closed");
 454                     }
 455                 }
 456                 long currTime = System.currentTimeMillis();
 457                 if (startTime > currTime) {
 458                     // System time must have changed
 459                     startTime = currTime;
 460                 }
 461                 if ((timeOut -= (currTime - startTime)) > 0) {
 462                     startTime = currTime;
 463                     synchronized (ldr) {
 464                         // check if condition has changed since our last check
 465                         rber = ldr.getReplyBer();
 466                         if (rber == null) {
 467                             ldr.wait(timeOut);








 468                         } else {
 469                             break;
 470                         }
 471                     }
 472                 }
 473             } catch (InterruptedException ex) {
 474                 throw new InterruptedNamingException(
 475                     "Interrupted during LDAP operation");
 476             }
 477         }
 478 
 479         if ((rber == null) && readTimeout > 0) {
 480             removeRequest(ldr);
 481             throw new NamingException("LDAP response read timed out, timeout used:"
 482                             + readTimeout + "ms." );
 483 
 484         }
 485         return rber;
 486     }
 487 
 488 
 489     ////////////////////////////////////////////////////////////////////////////
 490     //
 491     // Methods to add, find, delete, and abandon requests made to server
 492     //
 493     ////////////////////////////////////////////////////////////////////////////
 494 
 495     private synchronized void addRequest(LdapRequest ldapRequest) {
 496 
 497         LdapRequest ldr = pendingRequests;
 498         if (ldr == null) {
 499             pendingRequests = ldapRequest;