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 */
017package org.apache.commons.pool2;
018
019/**
020 * A base implementation of <code>PoolableObjectFactory</code>.
021 * <p>
022 * All operations defined here are essentially no-op's.
023 * <p>
024 * This class is immutable, and therefore thread-safe
025 *
026 * @param <T> Type of element managed in this factory.
027 *
028 * @see PooledObjectFactory
029 * @see BaseKeyedPooledObjectFactory
030 *
031 * @version $Revision: 1333925 $
032 *
033 * @since 2.0
034 */
035public abstract class BasePooledObjectFactory<T> implements PooledObjectFactory<T> {
036    /**
037     * Creates an object instance, to be wrapped in a {@link PooledObject}.
038     * <p>This method <strong>must</strong> support concurrent, multi-threaded
039     * activation.</p>
040     *
041     * @return an instance to be served by the pool
042     */
043    public abstract T create() throws Exception;
044
045    /**
046     * Wrap the provided instance with an implementation of
047     * {@link PooledObject}.
048     *
049     * @param obj the instance to wrap
050     *
051     * @return The provided instance, wrapped by a {@link PooledObject}
052     */
053    public abstract PooledObject<T> wrap(T obj);
054
055    @Override
056    public PooledObject<T> makeObject() throws Exception {
057        return wrap(create());
058    }
059
060    /**
061     *  No-op.
062     *
063     *  @param p ignored
064     */
065    @Override
066    public void destroyObject(PooledObject<T> p)
067        throws Exception  {
068    }
069
070    /**
071     * This implementation always returns {@code true}.
072     *
073     * @param p ignored
074     *
075     * @return {@code true}
076     */
077    @Override
078    public boolean validateObject(PooledObject<T> p) {
079        return true;
080    }
081
082    /**
083     *  No-op.
084     *
085     *  @param p ignored
086     */
087    @Override
088    public void activateObject(PooledObject<T> p) throws Exception {
089    }
090
091    /**
092     *  No-op.
093     *
094     * @param p ignored
095     */
096    @Override
097    public void passivateObject(PooledObject<T> p)
098        throws Exception {
099    }
100}