Source code

    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.impl;
    018
    019/**
    020 * A simple "struct" encapsulating the configuration for a
    021 * {@link GenericObjectPool}.
    022 *
    023 * <p>
    024 * This class is not thread-safe; it is only intended to be used to provide
    025 * attributes used when creating a pool.
    026 * </p>
    027 *
    028 * @param <T> Type of element pooled.
    029 * @since 2.0
    030 */
    031public class GenericObjectPoolConfig<T> extends BaseObjectPoolConfig<T> {
    032
    033    /**
    034     * The default value for the {@code maxTotal} configuration attribute.
    035     * @see GenericObjectPool#getMaxTotal()
    036     */
    037    public static final int DEFAULT_MAX_TOTAL = 8;
    038
    039    /**
    040     * The default value for the {@code maxIdle} configuration attribute.
    041     * @see GenericObjectPool#getMaxIdle()
    042     */
    043    public static final int DEFAULT_MAX_IDLE = 8;
    044
    045    /**
    046     * The default value for the {@code minIdle} configuration attribute.
    047     * @see GenericObjectPool#getMinIdle()
    048     */
    049    public static final int DEFAULT_MIN_IDLE = 0;
    050
    051
    052    private int maxTotal = DEFAULT_MAX_TOTAL;
    053
    054    private int maxIdle = DEFAULT_MAX_IDLE;
    055
    056    private int minIdle = DEFAULT_MIN_IDLE;
    057
    058    @SuppressWarnings("unchecked")
    059    @Override
    060    public GenericObjectPoolConfig<T> clone() {
    061        try {
    062            return (GenericObjectPoolConfig<T>) super.clone();
    063        } catch (final CloneNotSupportedException e) {
    064            throw new AssertionError(); // Can't happen
    065        }
    066    }
    067
    068    /**
    069     * Get the value for the {@code maxIdle} configuration attribute
    070     * for pools created with this configuration instance.
    071     *
    072     * @return  The current setting of {@code maxIdle} for this
    073     *          configuration instance
    074     *
    075     * @see GenericObjectPool#getMaxIdle()
    076     */
    077    public int getMaxIdle() {
    078        return maxIdle;
    079    }
    080
    081
    082    /**
    083     * Get the value for the {@code maxTotal} configuration attribute
    084     * for pools created with this configuration instance.
    085     *
    086     * @return  The current setting of {@code maxTotal} for this
    087     *          configuration instance
    088     *
    089     * @see GenericObjectPool#getMaxTotal()
    090     */
    091    public int getMaxTotal() {
    092        return maxTotal;
    093    }
    094
    095    /**
    096     * Get the value for the {@code minIdle} configuration attribute
    097     * for pools created with this configuration instance.
    098     *
    099     * @return  The current setting of {@code minIdle} for this
    100     *          configuration instance
    101     *
    102     * @see GenericObjectPool#getMinIdle()
    103     */
    104    public int getMinIdle() {
    105        return minIdle;
    106    }
    107
    108
    109    /**
    110     * Set the value for the {@code maxIdle} configuration attribute for
    111     * pools created with this configuration instance.
    112     *
    113     * @param maxIdle The new setting of {@code maxIdle}
    114     *        for this configuration instance
    115     *
    116     * @see GenericObjectPool#setMaxIdle(int)
    117     */
    118    public void setMaxIdle(final int maxIdle) {
    119        this.maxIdle = maxIdle;
    120    }
    121
    122    /**
    123     * Set the value for the {@code maxTotal} configuration attribute for
    124     * pools created with this configuration instance.
    125     *
    126     * @param maxTotal The new setting of {@code maxTotal}
    127     *        for this configuration instance
    128     *
    129     * @see GenericObjectPool#setMaxTotal(int)
    130     */
    131    public void setMaxTotal(final int maxTotal) {
    132        this.maxTotal = maxTotal;
    133    }
    134
    135    /**
    136     * Set the value for the {@code minIdle} configuration attribute for
    137     * pools created with this configuration instance.
    138     *
    139     * @param minIdle The new setting of {@code minIdle}
    140     *        for this configuration instance
    141     *
    142     * @see GenericObjectPool#setMinIdle(int)
    143     */
    144    public void setMinIdle(final int minIdle) {
    145        this.minIdle = minIdle;
    146    }
    147
    148    @Override
    149    protected void toStringAppendFields(final StringBuilder builder) {
    150        super.toStringAppendFields(builder);
    151        builder.append(", maxTotal=");
    152        builder.append(maxTotal);
    153        builder.append(", maxIdle=");
    154        builder.append(maxIdle);
    155        builder.append(", minIdle=");
    156        builder.append(minIdle);
    157    }
    158}