com.vladmihalcea.flexypool.adaptor.BitronixPoolAdapter Maven / Gradle / Ivy
package com.vladmihalcea.flexypool.adaptor;
import bitronix.tm.internal.BitronixRuntimeException;
import bitronix.tm.resource.jdbc.PoolingDataSource;
import com.vladmihalcea.flexypool.common.ConfigurationProperties;
import com.vladmihalcea.flexypool.metric.Metrics;
import java.util.regex.Pattern;
/**
* BitronixPoolAdapter
extends {@link AbstractPoolAdapter} and it adapts the required API to
* communicate with the bitronix {@link PoolingDataSource}
*
* @author Vlad Mihalcea
* @since 1.0
*/
public class BitronixPoolAdapter extends AbstractPoolAdapter {
public static final String ACQUIRE_TIMEOUT_MESSAGE = "XA pool of resource .*? still empty after .*?s wait time";
/**
* Singleton factory object reference
*/
public static final PoolAdapterFactory FACTORY = new PoolAdapterFactory() {
@Override
public PoolAdapter newInstance(
ConfigurationProperties> configurationProperties) {
return new BitronixPoolAdapter(configurationProperties);
}
};
/**
* Init constructor
* @param configurationProperties configuration properties
*/
public BitronixPoolAdapter(ConfigurationProperties> configurationProperties) {
super(configurationProperties);
}
/**
* {@inheritDoc}
*/
@Override
public int getMaxPoolSize() {
return getTargetDataSource().getMaxPoolSize();
}
/**
* {@inheritDoc}
*/
@Override
public void setMaxPoolSize(int maxPoolSize) {
getTargetDataSource().setMaxPoolSize(maxPoolSize);
}
/**
* {@inheritDoc}
*/
@Override
protected boolean isAcquireTimeoutException(Exception e) {
if (e.getCause() instanceof BitronixRuntimeException) {
BitronixRuntimeException cause = (BitronixRuntimeException) e.getCause();
return cause.getMessage() != null &&
Pattern.matches(ACQUIRE_TIMEOUT_MESSAGE, cause.getMessage());
}
return false;
}
}