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 * @since 2.0 027 */ 028public class EvictionConfig { 029 030 private final long idleEvictTime; 031 private final long idleSoftEvictTime; 032 private final int minIdle; 033 034 /** 035 * Create a new eviction configuration with the specified parameters. 036 * Instances are immutable. 037 * 038 * @param poolIdleEvictTime Expected to be provided by 039 * {@link BaseGenericObjectPool#getMinEvictableIdleTimeMillis()} 040 * @param poolIdleSoftEvictTime Expected to be provided by 041 * {@link BaseGenericObjectPool#getSoftMinEvictableIdleTimeMillis()} 042 * @param minIdle Expected to be provided by 043 * {@link GenericObjectPool#getMinIdle()} or 044 * {@link GenericKeyedObjectPool#getMinIdlePerKey()} 045 */ 046 public EvictionConfig(final long poolIdleEvictTime, final long poolIdleSoftEvictTime, 047 final int minIdle) { 048 if (poolIdleEvictTime > 0) { 049 idleEvictTime = poolIdleEvictTime; 050 } else { 051 idleEvictTime = Long.MAX_VALUE; 052 } 053 if (poolIdleSoftEvictTime > 0) { 054 idleSoftEvictTime = poolIdleSoftEvictTime; 055 } else { 056 idleSoftEvictTime = Long.MAX_VALUE; 057 } 058 this.minIdle = minIdle; 059 } 060 061 /** 062 * Obtain the {@code idleEvictTime} for this eviction configuration 063 * instance. 064 * <p> 065 * How the evictor behaves based on this value will be determined by the 066 * configured {@link EvictionPolicy}. 067 * 068 * @return The {@code idleEvictTime} in milliseconds 069 */ 070 public long getIdleEvictTime() { 071 return idleEvictTime; 072 } 073 074 /** 075 * Obtain the {@code idleSoftEvictTime} for this eviction configuration 076 * instance. 077 * <p> 078 * How the evictor behaves based on this value will be determined by the 079 * configured {@link EvictionPolicy}. 080 * 081 * @return The (@code idleSoftEvictTime} in milliseconds 082 */ 083 public long getIdleSoftEvictTime() { 084 return idleSoftEvictTime; 085 } 086 087 /** 088 * Obtain the {@code minIdle} for this eviction configuration instance. 089 * <p> 090 * How the evictor behaves based on this value will be determined by the 091 * configured {@link EvictionPolicy}. 092 * 093 * @return The {@code minIdle} 094 */ 095 public int getMinIdle() { 096 return minIdle; 097 } 098 099 /** 100 * @since 2.4 101 */ 102 @Override 103 public String toString() { 104 final StringBuilder builder = new StringBuilder(); 105 builder.append("EvictionConfig [idleEvictTime="); 106 builder.append(idleEvictTime); 107 builder.append(", idleSoftEvictTime="); 108 builder.append(idleSoftEvictTime); 109 builder.append(", minIdle="); 110 builder.append(minIdle); 111 builder.append("]"); 112 return builder.toString(); 113 } 114}