/*
 * $Source: /home/cvs/commons/pool1.1/ja/src/org/apache/commons/pool/ObjectPool.java,v $
 * $Revision: 1.1 $
 * $Date: 2004/02/22 11:58:26 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowledgement:
 *       "This product includes software developed by the
 *        Apache Software Foundation - http://www.apache.org/"
 *    Alternately, this acknowledgement may appear in the software itself,
 *    if and wherever such third-party acknowledgements normally appear.
 *
 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * http://www.apache.org/
 *
 */

package org.apache.commons.pool;

/**
 * プーリングを行うためのためのインターフェイスです。
 * {@primary A pooling interface.}
 * <p>
 * <code>ObjectPool</code> は一般的でシンプルなプーリングインターフェイスを定義します。
 * 必須となるメソッドは {@link #borrowObject borrowObject} と {@link #returnObject returnObject} だけです。
 * {@primary <code>ObjectPool</code> defines a trivially simple pooling interface. The only 
 * required methods are {@link #borrowObject borrowObject} and {@link #returnObject returnObject}.}
 * <p>
 * 以下に使用方法を示します:
 * {@primary Example of use:}
 * <table border="1" cellspacing="0" cellpadding="3" align="center" bgcolor="#FFFFFF"><tr><td>
 * &nbsp;Object obj = <font color="#0000CC">null</font>;<br/>
 * <br/>
 * &nbsp;<font color="#0000CC">try</font> {<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;obj = pool.borrowObject();<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;<font color="#00CC00">//...オブジェクトを使用...</font>{@primary
 * &nbsp;&nbsp;&nbsp;&nbsp;//...use the object...}<br/>
 * &nbsp;}&nbsp;<font color="#0000CC">catch</font>(Exception e) {<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;<font color="#00CC00">//...例外をハンドル...</font>{@primary
 * &nbsp;&nbsp;&nbsp;&nbsp;//...handle any exceptions...}<br/>
 * &nbsp;}&nbsp;<font color="#0000CC">finally</font> {<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;<font color="#00CC00">// 確実にオブジェクトをプールに返す</font>&nbsp;{@primary
 * &nbsp;&nbsp;&nbsp;&nbsp;// make sure the object is returned to the pool&nbsp;}<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000CC">if</font>(<font color="#0000CC">null</font> != obj) {<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.returnObject(obj);<br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;}<br/>
 * &nbsp;}<br/></td></tr></table><br/>
 * シンプルな規定クラス {@link org.apache.commons.pool.BaseObjectPool BaseObjectPool} を併せて参照ください。
 * {@primary See {@link org.apache.commons.pool.BaseObjectPool BaseObjectPool} for a simple base implementation.}
 *
 * @author Rodney Waldhoff
 * @version $Revision: 1.1 $ $Date: 2004/02/22 11:58:26 $ 
 *
 * @translator 日置 聡
 * @status firstdraft
 * @update 2004/02/21
 */
public interface ObjectPool {
    /**
     * プールからインスタンスを取り出します。
     * プールからインスタンスを取得したクライアントは必ず
     * {@link #returnObject(java.lang.Object) returnObject}
     * または実装クラスやサブインターフェイスのそれと関連するメソッドを使用して
     * インスタンスをプールに返さなくてはなりません。
     * {@primary Obtain an instance from my pool.
     * By contract, clients MUST return
     * the borrowed instance using
     * {@link #returnObject(java.lang.Object) returnObject}
     * or a related method as defined in an implementation
     * or sub-interface.}
     * <p>
     * プール内のインスタンスが空の場合のこのメソッドの振る舞いは明示されません
     * (各実装クラスで明示されるでしょう)。
     * {@primary The behaviour of this method when the pool has been exhausted
     * is not specified (although it may be specified by implementations).}
     *
     * @return プールから取り出されたインスタンス
     * {@primary an instance from my pool.}
     */
    Object borrowObject() throws Exception;

    /**
     * プールにインスタンスを返します。
     * プールに返される <i>obj</i> は必ず
     * {@link #borrowObject() borrowObject}
     * または実装クラスやサブインターフェイスのそれと関連するメソッドを使用して
     * 取得されたインスタンスでなくてはなりません。
     * {@primary Return an instance to my pool.
     * By contract, <i>obj</i> MUST have been obtained
     * using {@link #borrowObject() borrowObject}
     * or a related method as defined in an implementation
     * or sub-interface.}
     *
     * @param obj プールに返す {@link #borrowObject borrowed} にて取得されたインスタンス
     * {@primary  a {@link #borrowObject borrowed} instance to be returned.}
     */
    void returnObject(Object obj) throws Exception;

    /**
     * プール内で管理されるオブジェクトを無効にします。
     * 対象となる <i>obj</i> は {@link #borrowObject borrowObject}
     * か、実装クラスに定義された関連するメソッドか、 <i>key</i> 
     * を用いたサブインターフェイスの同等の機能を持つメソッドによって取得されたものでなくてはなりません。
     * {@primary Invalidates an object from the pool
     * By contract, <i>obj</i> MUST have been obtained
     * using {@link #borrowObject() borrowObject}
     * or a related method as defined in an implementation
     * or sub-interface.}
     * <p>
     * このメソッドはプールから取得されたオブジェクトが(例外等で)無効であるとみなされた場合に使用するべきです。
     * オブジェクト取得の前、もしくは戻された後にオブジェクトの評価を行う場合には
     * {@link PoolableObjectFactory#validateObject} を使用して下さい。
     * {@primary This method should be used when an object that has been borrowed
     * is determined (due to an exception or other problem) to be invalid.
     * If the connection should be validated before or after borrowing,
     * then the {@link PoolableObjectFactory#validateObject} method should be
     * used instead.}
     *
     * @param obj プールから{@link #borrowObject 取得} されたインスタンス
     * {@primary a {@link #borrowObject borrowed} instance to be returned.}
     */
    void invalidateObject(Object obj) throws Exception;

    /**
     * 自身の{@link #setFactory ファクトリ}または他の実装に依存する機能によってプール内にオブジェクトを配置します。
     * addObject() は事前に準備されたオブジェクトをプール内に用意する際に有用です(オプショナルな処理)。
     * {@primary Create an object using my {@link #setFactory factory} or other
     * implementation dependent mechanism, and place it into the pool.
     * addObject() is useful for "pre-loading" a pool with idle objects.
     * (Optional operation).}
     */
    void addObject() throws Exception;

    /**
     * 現在プール内にある使用されていないインスタンスの数を返します(オプショナルな処理)。
     * これは新たなインスタンスを生成せずに {@link #borrowObject 取得}
     * することのできるオブジェクトの数を対象とします。
     * {@primary Return the number of instances
     * currently idle in my pool (optional operation).  
     * This may be considered an approximation of the number
     * of objects that can be {@link #borrowObject borrowed}
     * without creating any new instances.}
     *
     * @return プール内にある使用されていないインスタンスの数
     * {@primary the number of instances currently idle in my pool}
     * @throws UnsupportedOperationException この実装がこの処理をサポートしない場合
     * {@primary if this implementation does not support the operation}
     */
    int getNumIdle() throws UnsupportedOperationException;

    /**
     * 現在プールから貸し出されているインスタンスの数を返します(オプショナルな処理)。
     * {@primary Return the number of instances
     * currently borrowed from my pool 
     * (optional operation).}
     *
     * @return 現在プールから貸し出されているインスタンスの数
     * {@primary the number of instances currently borrowed in my pool}
     * @throws UnsupportedOperationException この実装がこの処理をサポートしない場合
     * {@primary if this implementation does not support the operation}
     */
    int getNumActive() throws UnsupportedOperationException;

    /**
     * プール内にある使用されていないオブジェクトを削除し、関連するリソースを開放します(オプショナルな処理)。
     * {@primary Clears any objects sitting idle in the pool, releasing any
     * associated resources (optional operation).}
     *
     * @throws UnsupportedOperationException この実装がこの処理をサポートしない場合
     * {@primary if this implementation does not support the operation}
     */
    void clear() throws Exception, UnsupportedOperationException;

    /**
     * このプールを閉じ、関連する全てのリソースを開放します。
     * {@primary Close this pool, and free any resources associated with it.}
     */
    void close() throws Exception;

    /**
     * 新たなインスタンスを生成するために使用する
     * {@link PoolableObjectFactory factory} を設定します(オプショナルな処理)。
     * {@primary Sets the {@link PoolableObjectFactory ファクトリ} I use
     * to create new instances (optional operation).}
     *
     * @param factory 新たなインスタンスを生成するために使用する {@link PoolableObjectFactory}
     * {@primary the {@link PoolableObjectFactory} I use to create new instances.}
     * @throws IllegalStateException ファクトリを設定できる状態でない場合
     * {@primary IllegalStateException when the factory cannot be set at this time}
     * @throws UnsupportedOperationException この実装がこの処理をサポートしない場合
     * {@primary if this implementation does not support the operation}
     */
    void setFactory(PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException;
}
