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

Print this page




  94   *     inStream, outStream - no sync; used to construct new stream; accessed
  95   *             only when conn is "quiet" and not shared
  96   *     replaceStreams() - sync method
  97   * Members used by StartTLS:
  98   *     inStream, outStream - no sync; used to record the existing streams;
  99   *             accessed only when conn is "quiet" and not shared
 100   *     replaceStreams() - sync method
 101   * <p>
 102   * Handles anonymous, simple, and SASL bind for v3; anonymous and simple
 103   * for v2.
 104   * %%% made public for access by LdapSasl %%%
 105   *
 106   * @author Vincent Ryan
 107   * @author Rosanna Lee
 108   * @author Jagane Sundar
 109   */
 110 public final class Connection implements Runnable {
 111 
 112     private static final boolean debug = false;
 113     private static final int dump = 0; // > 0 r, > 1 rw
 114     public static final long DEFAULT_READ_TIMEOUT_MILLIS = 15 * 1000; // 15 second timeout;
 115 
 116 
 117     final private Thread worker;    // Initialized in constructor
 118 
 119     private boolean v3 = true;       // Set in setV3()
 120 
 121     final public String host;  // used by LdapClient for generating exception messages
 122                          // used by StartTlsResponse when creating an SSL socket
 123     final public int port;     // used by LdapClient for generating exception messages
 124                          // used by StartTlsResponse when creating an SSL socket
 125 
 126     private boolean bound = false;   // Set in setBound()
 127 
 128     // All three are initialized in constructor and read-only afterwards
 129     private OutputStream traceFile = null;
 130     private String traceTagIn = null;
 131     private String traceTagOut = null;
 132 
 133     // Initialized in constructor; read and used externally (LdapSasl);
 134     // Updated in replaceStreams() during "quiet", unshared, period


 443         boolean waited = false;
 444 
 445         while (((rber = ldr.getReplyBer()) == null) && !waited) {
 446             try {
 447                 // If socket closed, don't even try
 448                 synchronized (this) {
 449                     if (sock == null) {
 450                         throw new ServiceUnavailableException(host + ":" + port +
 451                             "; socket closed");
 452                     }
 453                 }
 454                 synchronized (ldr) {
 455                     // check if condition has changed since our last check
 456                     rber = ldr.getReplyBer();
 457                     if (rber == null) {
 458                         if (readTimeout > 0) {  // Socket read timeout is specified
 459 
 460                             // will be woken up before readTimeout only if reply is
 461                             // available
 462                             ldr.wait(readTimeout);

 463                         } else {
 464                             ldr.wait(DEFAULT_READ_TIMEOUT_MILLIS);
 465                         }
 466                         waited = true;
 467                     } else {
 468                         break;
 469                     }
 470                 }
 471             } catch (InterruptedException ex) {
 472                 throw new InterruptedNamingException(
 473                     "Interrupted during LDAP operation");
 474             }
 475         }
 476 
 477         if ((rber == null) && waited) {
 478             abandonRequest(ldr, null);
 479             throw new NamingException("LDAP response read timed out, timeout used:"
 480                             + readTimeout + "ms." );
 481 
 482         }
 483         return rber;
 484     }
 485 
 486 




  94   *     inStream, outStream - no sync; used to construct new stream; accessed
  95   *             only when conn is "quiet" and not shared
  96   *     replaceStreams() - sync method
  97   * Members used by StartTLS:
  98   *     inStream, outStream - no sync; used to record the existing streams;
  99   *             accessed only when conn is "quiet" and not shared
 100   *     replaceStreams() - sync method
 101   * <p>
 102   * Handles anonymous, simple, and SASL bind for v3; anonymous and simple
 103   * for v2.
 104   * %%% made public for access by LdapSasl %%%
 105   *
 106   * @author Vincent Ryan
 107   * @author Rosanna Lee
 108   * @author Jagane Sundar
 109   */
 110 public final class Connection implements Runnable {
 111 
 112     private static final boolean debug = false;
 113     private static final int dump = 0; // > 0 r, > 1 rw
 114     // public static final long DEFAULT_READ_TIMEOUT_MILLIS = 15 * 1000; // 15 second timeout;
 115 
 116 
 117     final private Thread worker;    // Initialized in constructor
 118 
 119     private boolean v3 = true;       // Set in setV3()
 120 
 121     final public String host;  // used by LdapClient for generating exception messages
 122                          // used by StartTlsResponse when creating an SSL socket
 123     final public int port;     // used by LdapClient for generating exception messages
 124                          // used by StartTlsResponse when creating an SSL socket
 125 
 126     private boolean bound = false;   // Set in setBound()
 127 
 128     // All three are initialized in constructor and read-only afterwards
 129     private OutputStream traceFile = null;
 130     private String traceTagIn = null;
 131     private String traceTagOut = null;
 132 
 133     // Initialized in constructor; read and used externally (LdapSasl);
 134     // Updated in replaceStreams() during "quiet", unshared, period


 443         boolean waited = false;
 444 
 445         while (((rber = ldr.getReplyBer()) == null) && !waited) {
 446             try {
 447                 // If socket closed, don't even try
 448                 synchronized (this) {
 449                     if (sock == null) {
 450                         throw new ServiceUnavailableException(host + ":" + port +
 451                             "; socket closed");
 452                     }
 453                 }
 454                 synchronized (ldr) {
 455                     // check if condition has changed since our last check
 456                     rber = ldr.getReplyBer();
 457                     if (rber == null) {
 458                         if (readTimeout > 0) {  // Socket read timeout is specified
 459 
 460                             // will be woken up before readTimeout only if reply is
 461                             // available
 462                             ldr.wait(readTimeout);
 463                             waited = true;
 464                         } else {
 465                             ldr.wait();
 466                         }

 467                     } else {
 468                         break;
 469                     }
 470                 }
 471             } catch (InterruptedException ex) {
 472                 throw new InterruptedNamingException(
 473                     "Interrupted during LDAP operation");
 474             }
 475         }
 476 
 477         if ((rber == null) && waited) {
 478             abandonRequest(ldr, null);
 479             throw new NamingException("LDAP response read timed out, timeout used:"
 480                             + readTimeout + "ms." );
 481 
 482         }
 483         return rber;
 484     }
 485 
 486