001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.pool;
019    
020    /**
021     * A base implementation of <code>KeyedPoolableObjectFactory</code>.
022     * <p>
023     * All operations defined here are essentially no-op's.
024     * </p>
025     *
026     * @see KeyedPoolableObjectFactory
027     *
028     * @author Rodney Waldhoff
029     * @version $Revision: 791907 $ $Date: 2009-07-07 12:56:33 -0400 (Tue, 07 Jul 2009) $
030     * @since Pool 1.0
031     */
032    public abstract class BaseKeyedPoolableObjectFactory implements KeyedPoolableObjectFactory {
033        /**
034         * Create an instance that can be served by the pool.
035         *
036         * @param key the key used when constructing the object
037         * @return an instance that can be served by the pool
038         */
039        public abstract Object makeObject(Object key)
040            throws Exception;
041    
042        /**
043         * Destroy an instance no longer needed by the pool.
044         * <p>
045         * The default implementation is a no-op.
046         * </p>
047         *
048         * @param key the key used when selecting the instance
049         * @param obj the instance to be destroyed
050         */
051        public void destroyObject(Object key, Object obj)
052            throws Exception {
053        }
054    
055        /**
056         * Ensures that the instance is safe to be returned by the pool.
057         * <p>
058         * The default implementation always returns <tt>true</tt>.
059         * </p>
060         *
061         * @param key the key used when selecting the object
062         * @param obj the instance to be validated
063         * @return always <code>true</code> in the default implementation
064         */ 
065        public boolean validateObject(Object key, Object obj) {
066            return true;
067        }
068    
069        /**
070         * Reinitialize an instance to be returned by the pool.
071         * <p>
072         * The default implementation is a no-op.
073         * </p>
074         *
075         * @param key the key used when selecting the object
076         * @param obj the instance to be activated
077         */
078        public void activateObject(Object key, Object obj)
079            throws Exception {
080        }
081    
082        /**
083         * Uninitialize an instance to be returned to the idle object pool.
084         * <p>
085         * The default implementation is a no-op.
086         * </p>
087         *
088         * @param key the key used when selecting the object
089         * @param obj the instance to be passivated
090         */
091        public void passivateObject(Object key, Object obj)
092            throws Exception {
093        }
094    }