Merged #316 selective merge

pull/316/merge
Brett Wooldridge 10 years ago
parent 61d07c24e2
commit 29351e811e

@ -169,7 +169,7 @@ Changes in 2.2.4
* Improved connection timeout handling by using Connection.setNetworkTimeout()
if available (JDBC 4.1).
* drvierClassName is no longer a required property when jdbcUrl is specified.
* driverClassName is no longer a required property when jdbcUrl is specified.
Omitting this property only works for compliant drivers.
* Add auto-detection of support for Statement.setQueryTimeout() used in the
@ -287,7 +287,7 @@ Changes in 1.3.6
*) Include connection failure cause in calls to getConnection() that
timeout (due to connection failure). Removed chatty logging.
*) Java8 Compatability fixes.
*) Java8 Compatibility fixes.
*) Include pool name in logging messages. Thanks for the contribution
@jaredstehler.

@ -18,7 +18,7 @@ _Java 7 and Java 8 maven artifact:_
<scope>compile</scope>
</dependency>
```
_Java 6 maven artifact (*maintence mode*):_
_Java 6 maven artifact (*maintenance mode*):_
```xml
<dependency>
<groupId>com.zaxxer</groupId>

@ -28,6 +28,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@ -51,7 +52,7 @@ public class HikariConfig implements HikariConfigMBean
private static final long IDLE_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
private static final long MAX_LIFETIME = TimeUnit.MINUTES.toMillis(30);
private static int poolNumber;
private static final AtomicInteger POOL_NUMBER = new AtomicInteger();
private static boolean unitTest;
// Properties changeable at runtime through the MBean
@ -85,11 +86,11 @@ public class HikariConfig implements HikariConfigMBean
private boolean isAllowPoolSuspension;
private boolean isWeakThreadLocals;
private DataSource dataSource;
private Properties dataSourceProperties;
private final Properties dataSourceProperties;
private ThreadFactory threadFactory;
private Object metricRegistry;
private Object healthCheckRegistry;
private Properties healthCheckProperties;
private final Properties healthCheckProperties;
static
{
@ -729,7 +730,7 @@ public class HikariConfig implements HikariConfigMBean
validateNumerics();
if (poolName == null) {
poolName = "HikariPool-" + poolNumber++;
poolName = "HikariPool-" + POOL_NUMBER.getAndIncrement();
}
if (poolName.contains(":") && isRegisterMbeans) {
@ -804,7 +805,7 @@ public class HikariConfig implements HikariConfigMBean
private void logConfiguration()
{
LOGGER.debug("HikariCP pool {} configuration:", poolName);
final Set<String> propertyNames = new TreeSet<String>(PropertyBeanSetter.getPropertyNames(HikariConfig.class));
final Set<String> propertyNames = new TreeSet<>(PropertyBeanSetter.getPropertyNames(HikariConfig.class));
for (String prop : propertyNames) {
try {
Object value = PropertyBeanSetter.getProperty(prop, this);
@ -825,7 +826,7 @@ public class HikariConfig implements HikariConfigMBean
protected void loadProperties(String propertyFileName)
{
final Path propFile = Paths.get(propertyFileName);
try (final InputStream is = Files.isRegularFile(propFile) ? Files.newInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
try (final InputStream is = Files.isRegularFile(propFile) ? Files.newInputStream(propFile) : HikariConfig.class.getResourceAsStream(propertyFileName)) {
if (is != null) {
Properties props = new Properties();
props.load(is);

@ -17,7 +17,7 @@
package com.zaxxer.hikari;
/**
* The javax.management MBean for a Hikiri pool configuration.
* The javax.management MBean for a Hikari pool configuration.
*
* @author Brett Wooldridge
*/

@ -204,7 +204,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
throw new IllegalStateException("MetricRegistry can only be set one time");
}
else {
pool.setMetricRegistry((MetricRegistry) super.getMetricRegistry());
pool.setMetricRegistry(super.getMetricRegistry());
}
}
}
@ -221,7 +221,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
throw new IllegalStateException("HealthCheckRegistry can only be set one time");
}
else {
pool.setHealthCheckRegistry((HealthCheckRegistry) super.getHealthCheckRegistry());
pool.setHealthCheckRegistry(super.getHealthCheckRegistry());
}
}
}
@ -296,7 +296,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
/**
* Shutdown the DataSource and its associated pool.
*
* @deprecated The {@link #shutdown()} method has been deprecated, please use {@link #close()} instead
* @deprecated This method has been deprecated, please use {@link #close()} instead
*/
@Deprecated
public void shutdown()

@ -18,6 +18,7 @@ package com.zaxxer.hikari.metrics;
import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
import com.zaxxer.hikari.util.ClockSource;
/**
* This class only supports realtime, not historical metrics.
@ -51,7 +52,7 @@ public class MetricsTracker implements AutoCloseable
/**
* A base instance of a MetricsContext. Classes extending this class should exhibit the
* behavior of "starting" a timer upon contruction, and "stopping" the timer when the
* behavior of "starting" a timer upon construction, and "stopping" the timer when the
* {@link MetricsContext#stop()} method is called.
*
* @author Brett Wooldridge

@ -26,6 +26,7 @@ import static com.zaxxer.hikari.util.UtilityElf.getTransactionIsolation;
import static com.zaxxer.hikari.util.UtilityElf.quietlySleep;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLTimeoutException;
import java.sql.Statement;
@ -178,11 +179,11 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
public final Connection getConnection(final long hardTimeout) throws SQLException
{
suspendResumeLock.acquire();
long timeout = hardTimeout;
final long startTime = clockSource.currentTime();
final MetricsContext metricsContext = (isRecordMetrics ? metricsTracker.recordConnectionRequest() : MetricsTracker.NO_CONTEXT);
try {
long timeout = hardTimeout;
final MetricsContext metricsContext = (isRecordMetrics ? metricsTracker.recordConnectionRequest() : MetricsTracker.NO_CONTEXT);
do {
final PoolBagEntry bagEntry = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS);
if (bagEntry == null) {
@ -563,7 +564,8 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
try (Statement statement = connection.createStatement()) {
poolUtils.setQueryTimeout(statement, timeoutSec);
statement.executeQuery(configuration.getConnectionTestQuery());
ResultSet rs = statement.executeQuery(configuration.getConnectionTestQuery());
rs.close();
}
if (isIsolateInternalQueries && !isAutoCommit) {
@ -621,7 +623,8 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
try {
shutdown();
}
catch (InterruptedException ignore) {
catch (Throwable ex) {
e.addSuppressed(ex);
}
throw new PoolInitializationException(e);

@ -17,7 +17,7 @@
package com.zaxxer.hikari.pool;
/**
* The javax.management MBean for a Hikiri pool instance.
* The javax.management MBean for a Hikari pool instance.
*
* @author Brett Wooldridge
*/

@ -50,7 +50,7 @@ public final class PoolBagEntry implements IConcurrentBagEntry
this.connection = connection;
this.parentPool = pool;
this.lastAccess = ClockSource.INSTANCE.currentTime();
this.openStatements = new FastList<Statement>(Statement.class, 16);
this.openStatements = new FastList<>(Statement.class, 16);
final long variance = pool.configuration.getMaxLifetime() > 60_000 ? ThreadLocalRandom.current().nextLong(10_000) : 0;
final long maxLifetime = pool.configuration.getMaxLifetime() - variance;

@ -121,7 +121,7 @@ public final class PoolUtilities
}
/**
* Setup a connection intial state.
* Setup a connection initial state.
*
* @param connection a Connection
* @param isAutoCommit auto-commit state

@ -63,7 +63,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
static {
LOGGER = LoggerFactory.getLogger(ConnectionProxy.class);
SQL_ERRORS = new HashSet<String>();
SQL_ERRORS = new HashSet<>();
SQL_ERRORS.add("57P01"); // ADMIN SHUTDOWN
SQL_ERRORS.add("57P02"); // CRASH SHUTDOWN
SQL_ERRORS.add("57P03"); // CANNOT CONNECT NOW

@ -132,14 +132,14 @@ public final class JavassistProxyFactory
targetCt.setModifiers(Modifier.FINAL);
// Make a set of method signatures we inherit implementation for, so we don't generate delegates for these
Set<String> superSigs = new HashSet<String>();
Set<String> superSigs = new HashSet<>();
for (CtMethod method : superClassCt.getMethods()) {
if ((method.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
superSigs.add(method.getName() + method.getSignature());
}
}
Set<String> methods = new HashSet<String>();
Set<String> methods = new HashSet<>();
Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(primaryInterface);
for (Class<?> intf : interfaces) {
CtClass intfCt = classPool.getCtClass(intf.getName());
@ -218,7 +218,7 @@ public final class JavassistProxyFactory
private boolean isDefaultMethod(Class<?> intf, CtClass intfCt, CtMethod intfMethod) throws Exception
{
List<Class<?>> paramTypes = new ArrayList<Class<?>>();
List<Class<?>> paramTypes = new ArrayList<>();
for (CtClass pt : intfMethod.getParameterTypes()) {
paramTypes.add(toJavaClass(pt));

@ -29,7 +29,7 @@ public final class ClassLoaderUtils
{
public static Set<Class<?>> getAllInterfaces(Class<?> clazz)
{
Set<Class<?>> interfaces = new HashSet<Class<?>>();
Set<Class<?>> interfaces = new HashSet<>();
for (Class<?> intf : Arrays.asList(clazz.getInterfaces())) {
if (intf.getInterfaces().length > 0) {
interfaces.addAll(getAllInterfaces(intf));

@ -238,7 +238,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
}
/**
* This method provides a "snaphot" in time of the BagEntry
* This method provides a "snapshot" in time of the BagEntry
* items in the bag in the specified state. It does not "lock"
* or reserve items in any way. Call <code>reserve(T)</code>
* on items in list before performing any action on them.

@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
public final class DriverDataSource implements DataSource
{
private final Logger LOGGER = LoggerFactory.getLogger(DriverDataSource.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DriverDataSource.class);
private final String jdbcUrl;
private final Properties driverProperties;

@ -53,7 +53,7 @@ public final class FastList<T> extends ArrayList<T>
}
/**
* Construct a FastList with a specfied size.
* Construct a FastList with a specified size.
* @param clazz the Class stored in the collection
* @param capacity the initial size of the FastList
*/

@ -23,6 +23,7 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -73,7 +74,7 @@ public final class PropertyBeanSetter
*/
public static Set<String> getPropertyNames(Class<?> targetClass)
{
HashSet<String> set = new HashSet<String>();
HashSet<String> set = new HashSet<>();
try {
BeanInfo info = Introspector.getBeanInfo(targetClass);
for (PropertyDescriptor descr : info.getPropertyDescriptors()) {
@ -111,8 +112,8 @@ public final class PropertyBeanSetter
public static Properties copyProperties(Properties props)
{
Properties copy = new Properties();
for (Object key : props.keySet()) {
copy.setProperty(key.toString(), props.get(key).toString());
for (Map.Entry<Object, Object> entry : props.entrySet()) {
copy.setProperty(entry.getKey().toString(), entry.getValue().toString());
}
return copy;
}

@ -36,10 +36,10 @@ public final class UtilityElf
*
* @param millis the number of milliseconds to sleep
*/
public static void quietlySleep(final long ticks)
public static void quietlySleep(final long millis)
{
try {
Thread.sleep(ticks);
Thread.sleep(millis);
}
catch (InterruptedException e) {
// I said be quiet!
@ -51,7 +51,7 @@ public final class UtilityElf
* arguments.
*
* @param <T> the class type
* @param className the name of the classto instantiate
* @param className the name of the class to instantiate
* @param clazz a class to cast the result as
* @param args arguments to a constructor
* @return an instance of the specified class
@ -73,10 +73,10 @@ public final class UtilityElf
if (args.length > 0) {
Constructor<?> constructor = loaded.getConstructor(argClasses);
return (T) constructor.newInstance(args);
return clazz.cast(constructor.newInstance(args));
}
return (T) loaded.newInstance();
return clazz.cast(loaded.newInstance());
}
catch (Exception e) {
throw new RuntimeException(e);
@ -98,7 +98,7 @@ public final class UtilityElf
threadFactory = new DefaultThreadFactory(threadName, true);
}
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(queueSize);
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(queueSize);
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, queue, threadFactory, policy);
executor.allowCoreThreadTimeOut(true);
return executor;

Loading…
Cancel
Save