1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.pool; 19 20 /** 21 * A base implementation of <code>KeyedPoolableObjectFactory</code>. 22 * <p> 23 * All operations defined here are essentially no-op's. 24 * </p> 25 * 26 * @see KeyedPoolableObjectFactory 27 * 28 * @author Rodney Waldhoff 29 * @version $Revision: 791907 $ $Date: 2009-07-07 09:56:33 -0700 (Tue, 07 Jul 2009) $ 30 * @since Pool 1.0 31 */ 32 public abstract class BaseKeyedPoolableObjectFactory implements KeyedPoolableObjectFactory { 33 /** 34 * Create an instance that can be served by the pool. 35 * 36 * @param key the key used when constructing the object 37 * @return an instance that can be served by the pool 38 */ 39 public abstract Object makeObject(Object key) 40 throws Exception; 41 42 /** 43 * Destroy an instance no longer needed by the pool. 44 * <p> 45 * The default implementation is a no-op. 46 * </p> 47 * 48 * @param key the key used when selecting the instance 49 * @param obj the instance to be destroyed 50 */ 51 public void destroyObject(Object key, Object obj) 52 throws Exception { 53 } 54 55 /** 56 * Ensures that the instance is safe to be returned by the pool. 57 * <p> 58 * The default implementation always returns <tt>true</tt>. 59 * </p> 60 * 61 * @param key the key used when selecting the object 62 * @param obj the instance to be validated 63 * @return always <code>true</code> in the default implementation 64 */ 65 public boolean validateObject(Object key, Object obj) { 66 return true; 67 } 68 69 /** 70 * Reinitialize an instance to be returned by the pool. 71 * <p> 72 * The default implementation is a no-op. 73 * </p> 74 * 75 * @param key the key used when selecting the object 76 * @param obj the instance to be activated 77 */ 78 public void activateObject(Object key, Object obj) 79 throws Exception { 80 } 81 82 /** 83 * Uninitialize an instance to be returned to the idle object pool. 84 * <p> 85 * The default implementation is a no-op. 86 * </p> 87 * 88 * @param key the key used when selecting the object 89 * @param obj the instance to be passivated 90 */ 91 public void passivateObject(Object key, Object obj) 92 throws Exception { 93 } 94 }