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 * @param <K> the type of keys in this pool 027 * @param <V> the type of objects held in this pool 028 * 029 * @see KeyedPoolableObjectFactory 030 * 031 * @author Rodney Waldhoff 032 * @version $Revision: 1222388 $ $Date: 2011-12-22 13:28:27 -0500 (Thu, 22 Dec 2011) $ 033 * @since Pool 1.0 034 */ 035 public abstract class BaseKeyedPoolableObjectFactory<K, V> implements KeyedPoolableObjectFactory<K, V> { 036 /** 037 * Create an instance that can be served by the pool. 038 * 039 * @param key the key used when constructing the object 040 * @return an instance that can be served by the pool 041 */ 042 public abstract V makeObject(K key) 043 throws Exception; 044 045 /** 046 * Destroy an instance no longer needed by the pool. 047 * <p> 048 * The default implementation is a no-op. 049 * </p> 050 * 051 * @param key the key used when selecting the instance 052 * @param obj the instance to be destroyed 053 */ 054 public void destroyObject(K key, V obj) 055 throws Exception { 056 } 057 058 /** 059 * Ensures that the instance is safe to be returned by the pool. 060 * <p> 061 * The default implementation always returns <tt>true</tt>. 062 * </p> 063 * 064 * @param key the key used when selecting the object 065 * @param obj the instance to be validated 066 * @return always <code>true</code> in the default implementation 067 */ 068 public boolean validateObject(K key, V obj) { 069 return true; 070 } 071 072 /** 073 * Reinitialize an instance to be returned by the pool. 074 * <p> 075 * The default implementation is a no-op. 076 * </p> 077 * 078 * @param key the key used when selecting the object 079 * @param obj the instance to be activated 080 */ 081 public void activateObject(K key, V obj) 082 throws Exception { 083 } 084 085 /** 086 * Uninitialize an instance to be returned to the idle object pool. 087 * <p> 088 * The default implementation is a no-op. 089 * </p> 090 * 091 * @param key the key used when selecting the object 092 * @param obj the instance to be passivated 093 */ 094 public void passivateObject(K key, V obj) 095 throws Exception { 096 } 097 }