com.vladmihalcea.flexypool.adaptor.DBCPPoolAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flexy-dbcp Show documentation
Show all versions of flexy-dbcp Show documentation
The flexible pool DBCP adapter
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());
}
}