001 package org.apache.ojb.broker.core;
002
003 /* Copyright 2003-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * 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 */
017
018 import org.apache.ojb.broker.util.configuration.Configurable;
019 import org.apache.ojb.broker.util.configuration.Configuration;
020 import org.apache.ojb.broker.util.configuration.ConfigurationException;
021 import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
022 import org.apache.ojb.broker.util.logging.LoggerFactory;
023 import org.apache.ojb.broker.util.pooling.PoolConfiguration;
024
025 import java.util.Properties;
026
027 public class PBPoolInfo extends PoolConfiguration implements Configurable
028 {
029 private static final long serialVersionUID = 3331426619896735439L;
030
031 public PBPoolInfo()
032 {
033 super();
034 init();
035 OjbConfigurator.getInstance().configure(this);
036 }
037
038 public PBPoolInfo(Properties properties)
039 {
040 super();
041 init();
042 OjbConfigurator.getInstance().configure(this);
043 this.putAll(properties);
044 }
045
046 /**
047 * Read in the configuration properties.
048 */
049 public void configure(Configuration pConfig) throws ConfigurationException
050 {
051 if (pConfig instanceof PBPoolConfiguration)
052 {
053 PBPoolConfiguration conf = (PBPoolConfiguration) pConfig;
054 this.setMaxActive(conf.getMaxActive());
055 this.setMaxIdle(conf.getMaxIdle());
056 this.setMaxWait(conf.getMaxWaitMillis());
057 this.setMinEvictableIdleTimeMillis(conf.getMinEvictableIdleTimeMillis());
058 this.setTimeBetweenEvictionRunsMillis(conf.getTimeBetweenEvictionRunsMilli());
059 this.setWhenExhaustedAction(conf.getWhenExhaustedAction());
060 }
061 else
062 {
063 LoggerFactory.getDefaultLogger().error(this.getClass().getName() +
064 " cannot read configuration properties, use default.");
065 }
066 }
067
068 /**
069 * Init default properties.
070 * We set {@link #setTestOnBorrow}, {@link #setTestOnReturn}, {@link #setTestWhileIdle}
071 * to <ii>false<ii> (See documentation of jakarta-commons-pool).
072 * Override this to change behavior.
073 */
074 public void init()
075 {
076 this.setTestOnBorrow(false);
077 this.setTestOnReturn(false);
078 this.setTestWhileIdle(false);
079 }
080 }