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 module hunt.pool.impl.GenericObjectPoolConfig; 18 19 import hunt.pool.impl.BaseObjectPoolConfig; 20 21 import hunt.Exceptions; 22 import hunt.util.StringBuilder; 23 24 /** 25 * A simple "struct" encapsulating the configuration for a 26 * {@link GenericObjectPool}. 27 * 28 * <p> 29 * This class is not thread-safe; it is only intended to be used to provide 30 * attributes used when creating a pool. 31 * </p> 32 * 33 * @param <T> Type of element pooled. 34 */ 35 class GenericObjectPoolConfig : BaseObjectPoolConfig { 36 37 /** 38 * The default value for the {@code maxTotal} configuration attribute. 39 * @see GenericObjectPool#getMaxTotal() 40 */ 41 enum int DEFAULT_MAX_TOTAL = 8; 42 43 /** 44 * The default value for the {@code maxIdle} configuration attribute. 45 * @see GenericObjectPool#getMaxIdle() 46 */ 47 enum int DEFAULT_MAX_IDLE = 8; 48 49 /** 50 * The default value for the {@code minIdle} configuration attribute. 51 * @see GenericObjectPool#getMinIdle() 52 */ 53 enum int DEFAULT_MIN_IDLE = 0; 54 55 56 private int maxTotal = DEFAULT_MAX_TOTAL; 57 58 private int maxIdle = DEFAULT_MAX_IDLE; 59 60 private int minIdle = DEFAULT_MIN_IDLE; 61 62 /** 63 * Get the value for the {@code maxTotal} configuration attribute 64 * for pools created with this configuration instance. 65 * 66 * @return The current setting of {@code maxTotal} for this 67 * configuration instance 68 * 69 * @see GenericObjectPool#getMaxTotal() 70 */ 71 int getMaxTotal() { 72 return maxTotal; 73 } 74 75 /** 76 * Set the value for the {@code maxTotal} configuration attribute for 77 * pools created with this configuration instance. 78 * 79 * @param maxTotal The new setting of {@code maxTotal} 80 * for this configuration instance 81 * 82 * @see GenericObjectPool#setMaxTotal(int) 83 */ 84 void setMaxTotal(int maxTotal) { 85 this.maxTotal = maxTotal; 86 } 87 88 89 /** 90 * Get the value for the {@code maxIdle} configuration attribute 91 * for pools created with this configuration instance. 92 * 93 * @return The current setting of {@code maxIdle} for this 94 * configuration instance 95 * 96 * @see GenericObjectPool#getMaxIdle() 97 */ 98 int getMaxIdle() { 99 return maxIdle; 100 } 101 102 /** 103 * Set the value for the {@code maxIdle} configuration attribute for 104 * pools created with this configuration instance. 105 * 106 * @param maxIdle The new setting of {@code maxIdle} 107 * for this configuration instance 108 * 109 * @see GenericObjectPool#setMaxIdle(int) 110 */ 111 void setMaxIdle(int maxIdle) { 112 this.maxIdle = maxIdle; 113 } 114 115 116 /** 117 * Get the value for the {@code minIdle} configuration attribute 118 * for pools created with this configuration instance. 119 * 120 * @return The current setting of {@code minIdle} for this 121 * configuration instance 122 * 123 * @see GenericObjectPool#getMinIdle() 124 */ 125 int getMinIdle() { 126 return minIdle; 127 } 128 129 /** 130 * Set the value for the {@code minIdle} configuration attribute for 131 * pools created with this configuration instance. 132 * 133 * @param minIdle The new setting of {@code minIdle} 134 * for this configuration instance 135 * 136 * @see GenericObjectPool#setMinIdle(int) 137 */ 138 void setMinIdle(int minIdle) { 139 this.minIdle = minIdle; 140 } 141 142 override 143 GenericObjectPoolConfig clone() { 144 try { 145 return cast(GenericObjectPoolConfig) super.clone(); 146 } catch (CloneNotSupportedException e) { 147 throw new AssertionError(); // Never happen 148 } 149 } 150 151 override 152 protected void toStringAppendFields(StringBuilder builder) { 153 super.toStringAppendFields(builder); 154 builder.append(", maxTotal="); 155 builder.append(maxTotal); 156 builder.append(", maxIdle="); 157 builder.append(maxIdle); 158 builder.append(", minIdle="); 159 builder.append(minIdle); 160 } 161 }