ConnectionDesc.java revision 2362
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * This code is free software; you can redistribute it and/or modify it
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * under the terms of the GNU General Public License version 2 only, as
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * published by the Free Software Foundation. Oracle designates this
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * particular file as subject to the "Classpath" exception as provided
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * by Oracle in the LICENSE file that accompanied this code.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * This code is distributed in the hope that it will be useful, but WITHOUT
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * version 2 for more details (a copy is included in the LICENSE file that
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * accompanied this code).
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * You should have received a copy of the GNU General Public License version
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * 2 along with this work; if not, write to the Free Software Foundation,
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * or visit www.oracle.com if you need additional information or have any
6876da76f91687fee15a706830b990a2c0d55157Trang Do * questions.
535ec645ca371f1ce298eaf76bf8feb73494f923dduvall * Represents a description of PooledConnection in Connections.
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * Contains a PooledConnection, its state (busy, idle, expired), and idle time.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * Any access or update to a descriptor's state is synchronized.
dd566498928f08e7c9a79797a40db893c6a4b9fbvn * @author Rosanna Lee
14ea4bb737263733ad80a36b4f73f681c30a6b45sdfinal class ConnectionDesc {
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh // Package private because used by Pool.showStats()
14ea4bb737263733ad80a36b4f73f681c30a6b45sd private long idleSince;
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * Two desc are equal if their PooledConnections are the same.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * This is useful when searching for a ConnectionDesc using only its
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * PooledConnection.
dd566498928f08e7c9a79797a40db893c6a4b9fbvn * Hashcode is that of PooledConnection to facilitate
dd566498928f08e7c9a79797a40db893c6a4b9fbvn * searching for a ConnectionDesc using only its PooledConnection.
dd566498928f08e7c9a79797a40db893c6a4b9fbvn public int hashCode() {
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * Changes the state of a ConnectionDesc from BUSY to IDLE and
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * records the current time so that we will know how long it has been idle.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * @return true if state change occurred.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd synchronized boolean release() {
14ea4bb737263733ad80a36b4f73f681c30a6b45sd d("release()");
6876da76f91687fee15a706830b990a2c0d55157Trang Do return true; // Connection released, ready for reuse
6876da76f91687fee15a706830b990a2c0d55157Trang Do return false; // Connection wasn't busy to begin with
6876da76f91687fee15a706830b990a2c0d55157Trang Do * If ConnectionDesc is IDLE, change its state to BUSY and return
6876da76f91687fee15a706830b990a2c0d55157Trang Do * its connection.
6876da76f91687fee15a706830b990a2c0d55157Trang Do * @return ConnectionDesc's PooledConnection if it was idle; null otherwise.
6876da76f91687fee15a706830b990a2c0d55157Trang Do d("tryUse()");
6876da76f91687fee15a706830b990a2c0d55157Trang Do * If ConnectionDesc is IDLE and has expired, close the corresponding
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * PooledConnection.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * @param threshold a connection that has been idle before this time
dd566498928f08e7c9a79797a40db893c6a4b9fbvn * have expired.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * @return true if entry is idle and has expired; false otherwise.
dd566498928f08e7c9a79797a40db893c6a4b9fbvn d("expire(): expired");
dd566498928f08e7c9a79797a40db893c6a4b9fbvn return true; // Expiration successful
14ea4bb737263733ad80a36b4f73f681c30a6b45sd d("expire(): not expired");
14ea4bb737263733ad80a36b4f73f681c30a6b45sd return false; // Expiration did not occur
dd566498928f08e7c9a79797a40db893c6a4b9fbvn (state == BUSY ? "busy" : (state == IDLE ? "idle" : "expired"));
14ea4bb737263733ad80a36b4f73f681c30a6b45sd // Used by Pool.showStats()
14ea4bb737263733ad80a36b4f73f681c30a6b45sd // Used by Pool.showStats()