    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 * This class is used by pool implementations to pass configuration information
    021 * to {@link EvictionPolicy} instances. The {@link EvictionPolicy} may also have
    022 * its own specific configuration attributes.
    023 * <p>
    024 * This class is immutable and thread-safe.
    025 *
    026 * @version $Revision: $
    027 *
    028 * @since 2.0
    029 */
    030public class EvictionConfig {
    031
    032    private final long idleEvictTime;
    033    private final long idleSoftEvictTime;
    034    private final int minIdle;
    035
    036
    037    /**
    038     * Create a new eviction configuration with the specified parameters.
    039     * Instances are immutable.
    040     *
    041     * @param poolIdleEvictTime Expected to be provided by
    042     *        {@link BaseGenericObjectPool#getMinEvictableIdleTimeMillis()}
    043     * @param poolIdleSoftEvictTime Expected to be provided by
    044     *        {@link BaseGenericObjectPool#getSoftMinEvictableIdleTimeMillis()}
    045     * @param minIdle Expected to be provided by
    046     *        {@link GenericObjectPool#getMinIdle()} or
    047     *        {@link GenericKeyedObjectPool#getMinIdlePerKey()}
    048     */
    049    public EvictionConfig(long poolIdleEvictTime, long poolIdleSoftEvictTime,
    050            int minIdle) {
    051        if (poolIdleEvictTime > 0) {
    052            idleEvictTime = poolIdleEvictTime;
    053        } else {
    054            idleEvictTime = Long.MAX_VALUE;
    055        }
    056        if (poolIdleSoftEvictTime > 0) {
    057            idleSoftEvictTime = poolIdleSoftEvictTime;
    058        } else {
    059            idleSoftEvictTime  = Long.MAX_VALUE;
    060        }
    061        this.minIdle = minIdle;
    062    }
    063
    064    /**
    065     * Obtain the {@code idleEvictTime} for this eviction configuration
    066     * instance.
    067     * <p>
    068     * How the evictor behaves based on this value will be determined by the
    069     * configured {@link EvictionPolicy}.
    070     *
    071     * @return The {@code idleEvictTime} in milliseconds
    072     */
    073    public long getIdleEvictTime() {
    074        return idleEvictTime;
    075    }
    076
    077    /**
    078     * Obtain the {@code idleSoftEvictTime} for this eviction configuration
    079     * instance.
    080     * <p>
    081     * How the evictor behaves based on this value will be determined by the
    082     * configured {@link EvictionPolicy}.
    083     *
    084     * @return The (@code idleSoftEvictTime} in milliseconds
    085     */
    086    public long getIdleSoftEvictTime() {
    087        return idleSoftEvictTime;
    088    }
    089
    090    /**
    091     * Obtain the {@code minIdle} for this eviction configuration instance.
    092     * <p>
    093     * How the evictor behaves based on this value will be determined by the
    094     * configured {@link EvictionPolicy}.
    095     *
    096     * @return The {@code minIdle}
    097     */
    098    public int getMinIdle() {
    099        return minIdle;
    100    }
    101}