< prev index next >

src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 421             }
 422         } else {
 423             return (byte[])pw;
 424         }
 425     }
 426 
 427     synchronized void close(Control[] reqCtls, boolean hardClose) {
 428         --referenceCount;
 429 
 430         if (debug > 1) {
 431             System.err.println("LdapClient: " + this);
 432             System.err.println("LdapClient: close() called: " + referenceCount);
 433             (new Throwable()).printStackTrace();
 434         }
 435 
 436         if (referenceCount <= 0 && conn != null) {
 437             if (debug > 0) System.err.println("LdapClient: closed connection " + this);
 438             if (!pooled) {
 439                 // Not being pooled; continue with closing
 440                 conn.cleanup(reqCtls, false);
 441                 conn = null;
 442             } else {
 443                 // Pooled
 444 
 445                 // Is this a real close or a request to return conn to pool
 446                 if (hardClose) {
 447                     conn.cleanup(reqCtls, false);
 448                     conn = null;
 449                     pcb.removePooledConnection(this);
 450                 } else {
 451                     pcb.releasePooledConnection(this);
 452                 }
 453             }
 454         }
 455     }
 456 
 457     // NOTE: Should NOT be synchronized otherwise won't be able to close
 458     private void forceClose(boolean cleanPool) {
 459         referenceCount = 0; // force closing of connection
 460 
 461         if (debug > 1) {
 462             System.err.println("LdapClient: forceClose() of " + this);
 463         }
 464 
 465         if (conn != null) {
 466             if (debug > 0) System.err.println(
 467                 "LdapClient: forced close of connection " + this);
 468             conn.cleanup(null, false);
 469             conn = null;
 470 
 471             if (cleanPool) {
 472                 pcb.removePooledConnection(this);
 473             }
 474         }
 475     }
 476 
 477     @SuppressWarnings("deprecation")
 478     protected void finalize() {
 479         if (debug > 0) System.err.println("LdapClient: finalize " + this);
 480         forceClose(pooled);
 481     }
 482 
 483     /*
 484      * Used by connection pooling to close physical connection.
 485      */
 486     synchronized public void closeConnection() {
 487         forceClose(false); // this is a pool callback so no need to clean pool
 488     }
 489 


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 421             }
 422         } else {
 423             return (byte[])pw;
 424         }
 425     }
 426 
 427     synchronized void close(Control[] reqCtls, boolean hardClose) {
 428         --referenceCount;
 429 
 430         if (debug > 1) {
 431             System.err.println("LdapClient: " + this);
 432             System.err.println("LdapClient: close() called: " + referenceCount);
 433             (new Throwable()).printStackTrace();
 434         }
 435 
 436         if (referenceCount <= 0 && conn != null) {
 437             if (debug > 0) System.err.println("LdapClient: closed connection " + this);
 438             if (!pooled) {
 439                 // Not being pooled; continue with closing
 440                 conn.cleanup(reqCtls, false);
 441                 //conn = null;
 442             } else {
 443                 // Pooled
 444 
 445                 // Is this a real close or a request to return conn to pool
 446                 if (hardClose) {
 447                     conn.cleanup(reqCtls, false);
 448                     //conn = null;
 449                     pcb.removePooledConnection(this);
 450                 } else {
 451                     pcb.releasePooledConnection(this);
 452                 }
 453             }
 454         }
 455     }
 456 
 457     // NOTE: Should NOT be synchronized otherwise won't be able to close
 458     private void forceClose(boolean cleanPool) {
 459         referenceCount = 0; // force closing of connection
 460 
 461         if (debug > 1) {
 462             System.err.println("LdapClient: forceClose() of " + this);
 463         }
 464 
 465         if (conn != null) {
 466             if (debug > 0) System.err.println(
 467                 "LdapClient: forced close of connection " + this);
 468             conn.cleanup(null, false);
 469             //conn = null;
 470 
 471             if (cleanPool) {
 472                 pcb.removePooledConnection(this);
 473             }
 474         }
 475     }
 476 
 477     @SuppressWarnings("deprecation")
 478     protected void finalize() {
 479         if (debug > 0) System.err.println("LdapClient: finalize " + this);
 480         forceClose(pooled);
 481     }
 482 
 483     /*
 484      * Used by connection pooling to close physical connection.
 485      */
 486     synchronized public void closeConnection() {
 487         forceClose(false); // this is a pool callback so no need to clean pool
 488     }
 489 


< prev index next >