1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.pool2.impl; 18 19 /** 20 * A simple structure encapsulating the configuration for a 21 * {@link GenericObjectPool}. 22 * 23 * <p> 24 * This class is not thread-safe; it is only intended to be used to provide 25 * attributes used when creating a pool. 26 * </p> 27 * 28 * @param <T> Type of element pooled. 29 * @since 2.0 30 */ 31 public class GenericObjectPoolConfig<T> extends BaseObjectPoolConfig<T> { 32 33 /** 34 * The default value for the {@code maxTotal} configuration attribute. 35 * @see GenericObjectPool#getMaxTotal() 36 */ 37 public static final int DEFAULT_MAX_TOTAL = 8; 38 39 /** 40 * The default value for the {@code maxIdle} configuration attribute. 41 * @see GenericObjectPool#getMaxIdle() 42 */ 43 public static final int DEFAULT_MAX_IDLE = 8; 44 45 /** 46 * The default value for the {@code minIdle} configuration attribute. 47 * @see GenericObjectPool#getMinIdle() 48 */ 49 public static final int DEFAULT_MIN_IDLE = 0; 50 51 52 private int maxTotal = DEFAULT_MAX_TOTAL; 53 54 private int maxIdle = DEFAULT_MAX_IDLE; 55 56 private int minIdle = DEFAULT_MIN_IDLE; 57 58 @SuppressWarnings("unchecked") 59 @Override 60 public GenericObjectPoolConfig<T> clone() { 61 try { 62 return (GenericObjectPoolConfig<T>) super.clone(); 63 } catch (final CloneNotSupportedException e) { 64 throw new AssertionError(); // Can't happen 65 } 66 } 67 68 /** 69 * Get the value for the {@code maxIdle} configuration attribute 70 * for pools created with this configuration instance. 71 * 72 * @return The current setting of {@code maxIdle} for this 73 * configuration instance 74 * 75 * @see GenericObjectPool#getMaxIdle() 76 */ 77 public int getMaxIdle() { 78 return maxIdle; 79 } 80 81 82 /** 83 * Get the value for the {@code maxTotal} configuration attribute 84 * for pools created with this configuration instance. 85 * 86 * @return The current setting of {@code maxTotal} for this 87 * configuration instance 88 * 89 * @see GenericObjectPool#getMaxTotal() 90 */ 91 public int getMaxTotal() { 92 return maxTotal; 93 } 94 95 /** 96 * Get the value for the {@code minIdle} configuration attribute 97 * for pools created with this configuration instance. 98 * 99 * @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 }