Skip to content

Commit

Permalink
Merged #316 selective merge
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwooldridge committed May 17, 2015
1 parent 61d07c2 commit 29351e8
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 38 deletions.
4 changes: 2 additions & 2 deletions CHANGES
Expand Up @@ -169,7 +169,7 @@ Changes in 2.2.4
* Improved connection timeout handling by using Connection.setNetworkTimeout() * Improved connection timeout handling by using Connection.setNetworkTimeout()
if available (JDBC 4.1). 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. Omitting this property only works for compliant drivers.


* Add auto-detection of support for Statement.setQueryTimeout() used in the * Add auto-detection of support for Statement.setQueryTimeout() used in the
Expand Down Expand Up @@ -287,7 +287,7 @@ Changes in 1.3.6
*) Include connection failure cause in calls to getConnection() that *) Include connection failure cause in calls to getConnection() that
timeout (due to connection failure). Removed chatty logging. timeout (due to connection failure). Removed chatty logging.


*) Java8 Compatability fixes. *) Java8 Compatibility fixes.


*) Include pool name in logging messages. Thanks for the contribution *) Include pool name in logging messages. Thanks for the contribution
@jaredstehler. @jaredstehler.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ _Java 7 and Java 8 maven artifact:_
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
``` ```
_Java 6 maven artifact (*maintence mode*):_ _Java 6 maven artifact (*maintenance mode*):_
```xml ```xml
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/zaxxer/hikari/HikariConfig.java
Expand Up @@ -28,6 +28,7 @@
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;


import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
Expand All @@ -51,7 +52,7 @@ public class HikariConfig implements HikariConfigMBean
private static final long IDLE_TIMEOUT = TimeUnit.MINUTES.toMillis(10); private static final long IDLE_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
private static final long MAX_LIFETIME = TimeUnit.MINUTES.toMillis(30); 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; private static boolean unitTest;


// Properties changeable at runtime through the MBean // Properties changeable at runtime through the MBean
Expand Down Expand Up @@ -85,11 +86,11 @@ public class HikariConfig implements HikariConfigMBean
private boolean isAllowPoolSuspension; private boolean isAllowPoolSuspension;
private boolean isWeakThreadLocals; private boolean isWeakThreadLocals;
private DataSource dataSource; private DataSource dataSource;
private Properties dataSourceProperties; private final Properties dataSourceProperties;
private ThreadFactory threadFactory; private ThreadFactory threadFactory;
private Object metricRegistry; private Object metricRegistry;
private Object healthCheckRegistry; private Object healthCheckRegistry;
private Properties healthCheckProperties; private final Properties healthCheckProperties;


static static
{ {
Expand Down Expand Up @@ -729,7 +730,7 @@ public void validate()
validateNumerics(); validateNumerics();


if (poolName == null) { if (poolName == null) {
poolName = "HikariPool-" + poolNumber++; poolName = "HikariPool-" + POOL_NUMBER.getAndIncrement();
} }


if (poolName.contains(":") && isRegisterMbeans) { if (poolName.contains(":") && isRegisterMbeans) {
Expand Down Expand Up @@ -804,7 +805,7 @@ else if (idleTimeout > maxLifetime && maxLifetime > 0) {
private void logConfiguration() private void logConfiguration()
{ {
LOGGER.debug("HikariCP pool {} configuration:", poolName); 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) { for (String prop : propertyNames) {
try { try {
Object value = PropertyBeanSetter.getProperty(prop, this); Object value = PropertyBeanSetter.getProperty(prop, this);
Expand All @@ -825,7 +826,7 @@ private void logConfiguration()
protected void loadProperties(String propertyFileName) protected void loadProperties(String propertyFileName)
{ {
final Path propFile = Paths.get(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) { if (is != null) {
Properties props = new Properties(); Properties props = new Properties();
props.load(is); props.load(is);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/HikariConfigMBean.java
Expand Up @@ -17,7 +17,7 @@
package com.zaxxer.hikari; 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 * @author Brett Wooldridge
*/ */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/zaxxer/hikari/HikariDataSource.java
Expand Up @@ -204,7 +204,7 @@ public void setMetricRegistry(Object metricRegistry)
throw new IllegalStateException("MetricRegistry can only be set one time"); throw new IllegalStateException("MetricRegistry can only be set one time");
} }
else { else {
pool.setMetricRegistry((MetricRegistry) super.getMetricRegistry()); pool.setMetricRegistry(super.getMetricRegistry());
} }
} }
} }
Expand All @@ -221,7 +221,7 @@ public void setHealthCheckRegistry(Object healthCheckRegistry)
throw new IllegalStateException("HealthCheckRegistry can only be set one time"); throw new IllegalStateException("HealthCheckRegistry can only be set one time");
} }
else { else {
pool.setHealthCheckRegistry((HealthCheckRegistry) super.getHealthCheckRegistry()); pool.setHealthCheckRegistry(super.getHealthCheckRegistry());
} }
} }
} }
Expand Down Expand Up @@ -296,7 +296,7 @@ public boolean isClosed()
/** /**
* Shutdown the DataSource and its associated pool. * 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 @Deprecated
public void shutdown() public void shutdown()
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java
Expand Up @@ -18,6 +18,7 @@


import com.zaxxer.hikari.pool.HikariPool; import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry; import com.zaxxer.hikari.pool.PoolBagEntry;
import com.zaxxer.hikari.util.ClockSource;


/** /**
* This class only supports realtime, not historical metrics. * This class only supports realtime, not historical metrics.
Expand Down Expand Up @@ -51,7 +52,7 @@ public void close()


/** /**
* A base instance of a MetricsContext. Classes extending this class should exhibit the * 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. * {@link MetricsContext#stop()} method is called.
* *
* @author Brett Wooldridge * @author Brett Wooldridge
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/zaxxer/hikari/pool/HikariPool.java
Expand Up @@ -26,6 +26,7 @@
import static com.zaxxer.hikari.util.UtilityElf.quietlySleep; import static com.zaxxer.hikari.util.UtilityElf.quietlySleep;


import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLTimeoutException; import java.sql.SQLTimeoutException;
import java.sql.Statement; import java.sql.Statement;
Expand Down Expand Up @@ -178,11 +179,11 @@ public final Connection getConnection() throws SQLException
public final Connection getConnection(final long hardTimeout) throws SQLException public final Connection getConnection(final long hardTimeout) throws SQLException
{ {
suspendResumeLock.acquire(); suspendResumeLock.acquire();
long timeout = hardTimeout;
final long startTime = clockSource.currentTime(); final long startTime = clockSource.currentTime();
final MetricsContext metricsContext = (isRecordMetrics ? metricsTracker.recordConnectionRequest() : MetricsTracker.NO_CONTEXT);


try { try {
long timeout = hardTimeout;
final MetricsContext metricsContext = (isRecordMetrics ? metricsTracker.recordConnectionRequest() : MetricsTracker.NO_CONTEXT);
do { do {
final PoolBagEntry bagEntry = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS); final PoolBagEntry bagEntry = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS);
if (bagEntry == null) { if (bagEntry == null) {
Expand Down Expand Up @@ -563,7 +564,8 @@ private boolean isConnectionAlive(final Connection connection)


try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
poolUtils.setQueryTimeout(statement, timeoutSec); poolUtils.setQueryTimeout(statement, timeoutSec);
statement.executeQuery(configuration.getConnectionTestQuery()); ResultSet rs = statement.executeQuery(configuration.getConnectionTestQuery());
rs.close();
} }


if (isIsolateInternalQueries && !isAutoCommit) { if (isIsolateInternalQueries && !isAutoCommit) {
Expand Down Expand Up @@ -621,7 +623,8 @@ private void initializeConnections()
try { try {
shutdown(); shutdown();
} }
catch (InterruptedException ignore) { catch (Throwable ex) {
e.addSuppressed(ex);
} }


throw new PoolInitializationException(e); throw new PoolInitializationException(e);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/pool/HikariPoolMBean.java
Expand Up @@ -17,7 +17,7 @@
package com.zaxxer.hikari.pool; 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 * @author Brett Wooldridge
*/ */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/pool/PoolBagEntry.java
Expand Up @@ -50,7 +50,7 @@ public PoolBagEntry(final Connection connection, final HikariPool pool) {
this.connection = connection; this.connection = connection;
this.parentPool = pool; this.parentPool = pool;
this.lastAccess = ClockSource.INSTANCE.currentTime(); 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 variance = pool.configuration.getMaxLifetime() > 60_000 ? ThreadLocalRandom.current().nextLong(10_000) : 0;
final long maxLifetime = pool.configuration.getMaxLifetime() - variance; final long maxLifetime = pool.configuration.getMaxLifetime() - variance;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/pool/PoolUtilities.java
Expand Up @@ -121,7 +121,7 @@ else if (jdbcUrl != null && dataSource == null) {
} }


/** /**
* Setup a connection intial state. * Setup a connection initial state.
* *
* @param connection a Connection * @param connection a Connection
* @param isAutoCommit auto-commit state * @param isAutoCommit auto-commit state
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/proxy/ConnectionProxy.java
Expand Up @@ -63,7 +63,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
static { static {
LOGGER = LoggerFactory.getLogger(ConnectionProxy.class); LOGGER = LoggerFactory.getLogger(ConnectionProxy.class);


SQL_ERRORS = new HashSet<String>(); SQL_ERRORS = new HashSet<>();
SQL_ERRORS.add("57P01"); // ADMIN SHUTDOWN SQL_ERRORS.add("57P01"); // ADMIN SHUTDOWN
SQL_ERRORS.add("57P02"); // CRASH SHUTDOWN SQL_ERRORS.add("57P02"); // CRASH SHUTDOWN
SQL_ERRORS.add("57P03"); // CANNOT CONNECT NOW SQL_ERRORS.add("57P03"); // CANNOT CONNECT NOW
Expand Down
Expand Up @@ -132,14 +132,14 @@ private <T> Class<T> generateProxyClass(Class<T> primaryInterface, Class<?> supe
targetCt.setModifiers(Modifier.FINAL); targetCt.setModifiers(Modifier.FINAL);


// Make a set of method signatures we inherit implementation for, so we don't generate delegates for these // 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()) { for (CtMethod method : superClassCt.getMethods()) {
if ((method.getModifiers() & Modifier.FINAL) == Modifier.FINAL) { if ((method.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
superSigs.add(method.getName() + method.getSignature()); superSigs.add(method.getName() + method.getSignature());
} }
} }


Set<String> methods = new HashSet<String>(); Set<String> methods = new HashSet<>();
Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(primaryInterface); Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(primaryInterface);
for (Class<?> intf : interfaces) { for (Class<?> intf : interfaces) {
CtClass intfCt = classPool.getCtClass(intf.getName()); CtClass intfCt = classPool.getCtClass(intf.getName());
Expand Down Expand Up @@ -218,7 +218,7 @@ private boolean isThrowsSqlException(CtMethod method)


private boolean isDefaultMethod(Class<?> intf, CtClass intfCt, CtMethod intfMethod) throws Exception 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()) { for (CtClass pt : intfMethod.getParameterTypes()) {
paramTypes.add(toJavaClass(pt)); paramTypes.add(toJavaClass(pt));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/util/ClassLoaderUtils.java
Expand Up @@ -29,7 +29,7 @@ public final class ClassLoaderUtils
{ {
public static Set<Class<?>> getAllInterfaces(Class<?> clazz) 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())) { for (Class<?> intf : Arrays.asList(clazz.getInterfaces())) {
if (intf.getInterfaces().length > 0) { if (intf.getInterfaces().length > 0) {
interfaces.addAll(getAllInterfaces(intf)); interfaces.addAll(getAllInterfaces(intf));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java
Expand Up @@ -238,7 +238,7 @@ public void close()
} }


/** /**
* 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" * items in the bag in the specified state. It does not "lock"
* or reserve items in any way. Call <code>reserve(T)</code> * or reserve items in any way. Call <code>reserve(T)</code>
* on items in list before performing any action on them. * on items in list before performing any action on them.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/util/DriverDataSource.java
Expand Up @@ -32,7 +32,7 @@


public final class DriverDataSource implements DataSource 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 String jdbcUrl;
private final Properties driverProperties; private final Properties driverProperties;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/util/FastList.java
Expand Up @@ -53,7 +53,7 @@ public FastList(Class<?> clazz)
} }


/** /**
* Construct a FastList with a specfied size. * Construct a FastList with a specified size.
* @param clazz the Class stored in the collection * @param clazz the Class stored in the collection
* @param capacity the initial size of the FastList * @param capacity the initial size of the FastList
*/ */
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/zaxxer/hikari/util/PropertyBeanSetter.java
Expand Up @@ -23,6 +23,7 @@
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;


Expand Down Expand Up @@ -73,7 +74,7 @@ public static void setTargetFromProperties(Object target, Properties properties)
*/ */
public static Set<String> getPropertyNames(Class<?> targetClass) public static Set<String> getPropertyNames(Class<?> targetClass)
{ {
HashSet<String> set = new HashSet<String>(); HashSet<String> set = new HashSet<>();
try { try {
BeanInfo info = Introspector.getBeanInfo(targetClass); BeanInfo info = Introspector.getBeanInfo(targetClass);
for (PropertyDescriptor descr : info.getPropertyDescriptors()) { for (PropertyDescriptor descr : info.getPropertyDescriptors()) {
Expand Down Expand Up @@ -111,8 +112,8 @@ public static Object getProperty(String propName, Object target)
public static Properties copyProperties(Properties props) public static Properties copyProperties(Properties props)
{ {
Properties copy = new Properties(); Properties copy = new Properties();
for (Object key : props.keySet()) { for (Map.Entry<Object, Object> entry : props.entrySet()) {
copy.setProperty(key.toString(), props.get(key).toString()); copy.setProperty(entry.getKey().toString(), entry.getValue().toString());
} }
return copy; return copy;
} }
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/zaxxer/hikari/util/UtilityElf.java
Expand Up @@ -36,10 +36,10 @@ public final class UtilityElf
* *
* @param millis the number of milliseconds to sleep * @param millis the number of milliseconds to sleep
*/ */
public static void quietlySleep(final long ticks) public static void quietlySleep(final long millis)
{ {
try { try {
Thread.sleep(ticks); Thread.sleep(millis);
} }
catch (InterruptedException e) { catch (InterruptedException e) {
// I said be quiet! // I said be quiet!
Expand All @@ -51,7 +51,7 @@ public static void quietlySleep(final long ticks)
* arguments. * arguments.
* *
* @param <T> the class type * @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 clazz a class to cast the result as
* @param args arguments to a constructor * @param args arguments to a constructor
* @return an instance of the specified class * @return an instance of the specified class
Expand All @@ -73,10 +73,10 @@ public static <T> T createInstance(final String className, final Class<T> clazz,


if (args.length > 0) { if (args.length > 0) {
Constructor<?> constructor = loaded.getConstructor(argClasses); 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) { catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
Expand All @@ -98,7 +98,7 @@ public static ThreadPoolExecutor createThreadPoolExecutor(final int queueSize, f
threadFactory = new DefaultThreadFactory(threadName, true); 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); ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, queue, threadFactory, policy);
executor.allowCoreThreadTimeOut(true); executor.allowCoreThreadTimeOut(true);
return executor; return executor;
Expand Down

0 comments on commit 29351e8

Please sign in to comment.