All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladmihalcea.flexypool.adaptor.DBCPPoolAdapter Maven / Gradle / Ivy

There is a newer version: 2.2.3
Show newest version
package com.vladmihalcea.flexypool.adaptor;

import com.vladmihalcea.flexypool.common.ConfigurationProperties;
import com.vladmihalcea.flexypool.metric.Metrics;
import org.apache.commons.dbcp.BasicDataSource;

import java.util.regex.Pattern;

/**
 * DBCPPoolAdapter extends {@link AbstractPoolAdapter} and it adapts the required API to
 * communicate with the DBCP {@link BasicDataSource}
 *
 * @author Vlad Mihalcea
 * @since 1.0
 */
public class DBCPPoolAdapter extends AbstractPoolAdapter {

    public static final String ACQUIRE_TIMEOUT_MESSAGE = "Cannot get a connection, pool error Timeout waiting for idle object";

    /**
     * Singleton factory object reference
     */
    public static final PoolAdapterFactory FACTORY = new PoolAdapterFactory() {

        @Override
        public PoolAdapter newInstance(
                ConfigurationProperties> configurationProperties) {
            return new DBCPPoolAdapter(configurationProperties);
        }
    };

    /**
     * Init constructor
     */
    public DBCPPoolAdapter(ConfigurationProperties> configurationProperties) {
        super(configurationProperties);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaxPoolSize() {
        return getTargetDataSource().getMaxActive();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setMaxPoolSize(int maxPoolSize) {
        getTargetDataSource().setMaxActive(maxPoolSize);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean isAcquireTimeoutException(Exception e) {
        return e.getMessage() != null && Pattern.matches(ACQUIRE_TIMEOUT_MESSAGE, e.getMessage());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy